13 except OSError
as exc:
14 if exc.errno == errno.EEXIST
and os.path.isdir(path):
23 parser = argparse.ArgumentParser()
25 '--symbol-name', type=str, required=
True, help=
'The name of the symbol referencing the data.'
31 help=
'The header file containing the symbol reference.'
34 '--output-source', type=str, required=
True, help=
'The source file containing the file bytes.'
40 help=
'The source file whose contents to embed in the output source file.'
43 args = parser.parse_args()
45 assert os.path.exists(args.source)
47 output_header = os.path.abspath(args.output_header)
48 output_source = os.path.abspath(args.output_source)
49 output_header_basename = output_header[output_header.rfind(
'/') + 1:]
54 with open(args.source,
'rb')
as source, open(output_source,
'w')
as output:
56 output.write(f
'#include "{output_header_basename}"\n')
57 output.write(
'#include <cstddef>\n')
59 f
'alignas(std::max_align_t) const unsigned char impeller_{args.symbol_name}_data[] =\n'
67 output.write(f
'{ord(byte)},')
69 output.write(f
'const unsigned long impeller_{args.symbol_name}_length = {data_len};\n')
71 with open(output_header,
'w')
as output:
72 output.write(
'#pragma once\n')
73 output.write(
'#ifdef __cplusplus\n')
74 output.write(
'extern "C" {\n')
75 output.write(
'#endif\n\n')
77 output.write(f
'extern const unsigned char impeller_{args.symbol_name}_data[];\n')
78 output.write(f
'extern const unsigned long impeller_{args.symbol_name}_length;\n\n')
80 output.write(
'#ifdef __cplusplus\n')
82 output.write(
'#endif\n')
85if __name__ ==
'__main__':
def make_directories(path)