aboutsummaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/rcc30
1 files changed, 18 insertions, 12 deletions
diff --git a/scripts/rcc b/scripts/rcc
index 2ca587c..b81cf6e 100755
--- a/scripts/rcc
+++ b/scripts/rcc
@@ -24,12 +24,12 @@ def compress(file, zstd='zstd', level=19, dictionary=None):
cmd.append(file.name)
return subprocess.run(cmd, capture_output=True).stdout
-def hexdump(array_name, input_file, out_h):
+def hexdump(array_name, array_data, out_h):
array_len = 0
print("constexpr unsigned char {}[] = {{".format(array_name), file=out_h)
- for byte in input_file[0:len(input_file)]:
+ for byte in array_data[0:len(array_data)]:
array_len+=1
if array_len%16 == 0:
print(" 0x{:02X},".format(byte), file=out_h)
@@ -57,8 +57,9 @@ if __name__ == "__main__":
parser.add_argument('input', type=argparse.FileType('rt'), help='input file (.xrc)')
parser.add_argument('-o', '--output', type=argparse.FileType('wt'), metavar='OUT', default=sys.stdout, help='output header file')
+ parser.add_argument('-n', '--namespace', type=str, help='namespace')
- parser.add_argument('--compress', choices=[ 'None', 'Zstd' ], help='compress input files using algorightm')
+ parser.add_argument('--compress', choices=[ 'None', 'Zstd' ], default='None', help='compress input files using algorightm')
parser.add_argument('--dict', type=argparse.FileType('rb'), help='[zstd] use specified dictionary, recommended for many similar small files')
parser.add_argument('--train', action='store_true', help='[zstd] train dictionary')
@@ -66,13 +67,14 @@ if __name__ == "__main__":
entries_list = ""
- if args.compress=='Zstd' and args.train:
+ if args.train:
train(args.input, args.dict.name)
# write header
print("// Autogenerated binary file hexdump", file=args.output)
print("// This file may get overwritten by the build system\n", file=args.output)
print("#include <embed.h>\n", file=args.output)
+ print("namespace {} {{".format(args.namespace), file=args.output)
# write file data
for child in xml.parse(args.input).getroot():
@@ -80,22 +82,26 @@ if __name__ == "__main__":
prefix = child.attrib['prefix']
for i in child:
vname = name(i.text)
- with open(i.text) as f:
- hexdump(vname, compress(f, dictionary=args.dict), args.output)
+ with open(i.text, 'rb') as f:
+ if args.compress == 'None':
+ hexdump(vname, f.read(), args.output)
+ elif args.compress == 'Zstd':
+ hexdump(vname, compress(f, dictionary=args.dict), args.output)
entries_list += " {{ \"{}/{}\", std::span({}, {}_len) }},\n".format(prefix, i.attrib['alias'], vname, vname)
# write dictionary
if args.dict is not None:
- hexdump('dictionary', args.dict.read(), args.output)
+ hexdump('dict', args.dict.read(), args.output)
# write entries
print("constexpr auto entries = frozen::make_unordered_map<frozen::string, std::span<const unsigned char>>({", file=args.output)
print(entries_list, file=args.output)
print("});\n", file=args.output)
- # write metadata struct
- print("constexpr embed::ResourceData metadata = {", file=args.output)
- print(" .compression = embed::{},".format(args.compress), file=args.output)
+ # write metadata
+ print("constexpr auto compression = embed::{};".format(args.compress), file=args.output)
if args.dict is not None:
- print(" .dictionary = std::span(dictionary, dictionary_len),", file=args.output)
- print("};", file=args.output)
+ print("constexpr auto dictionary = std::span(dict, dict_len);", file=args.output)
+
+ print("}} // namespace {}".format(args.namespace), file=args.output)
+