diff options
author | alexv-smirnov <alex@ydb.tech> | 2022-08-02 18:29:40 +0300 |
---|---|---|
committer | alexv-smirnov <alex@ydb.tech> | 2022-08-02 18:29:40 +0300 |
commit | 4b1c01e02b4ad60b38ca508a6fed5cc2e8d5e55a (patch) | |
tree | f236dc83d57e23056b407e19e9fd570331461fd1 /build/scripts/rodata2cpp.py | |
parent | 2c3e463184db19e1b80af7e0d03ee2dd315261a1 (diff) | |
download | ydb-4b1c01e02b4ad60b38ca508a6fed5cc2e8d5e55a.tar.gz |
add implicit build/scripts/rodata2cpp.py to ydb sync config
Diffstat (limited to 'build/scripts/rodata2cpp.py')
-rw-r--r-- | build/scripts/rodata2cpp.py | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/build/scripts/rodata2cpp.py b/build/scripts/rodata2cpp.py new file mode 100644 index 0000000000..be67d3af53 --- /dev/null +++ b/build/scripts/rodata2cpp.py @@ -0,0 +1,34 @@ +import argparse + + +def main(): + parser = argparse.ArgumentParser(description='Convert rodata into C++ source with embedded file content') + parser.add_argument('symbol', help='symbol name exported from generated file') + parser.add_argument('rodata', type=argparse.FileType('rb'), help='input .rodata file path') + parser.add_argument('cpp', type=argparse.FileType('w', encoding='UTF-8'), help='destination .cpp file path') + + args = parser.parse_args() + args.cpp.write('static_assert(sizeof(unsigned int) == 4, "ups, something gone wrong");\n\n') + args.cpp.write('extern "C" {\n') + args.cpp.write(' extern const unsigned char ' + args.symbol + '[] = {\n') + + cnt = 0 + + for ch in args.rodata.read(): + args.cpp.write('0x%02x, ' % ch) + + cnt += 1 + + if cnt % 50 == 1: + args.cpp.write('\n') + + args.cpp.write(' };\n') + args.cpp.write(' extern const unsigned int ' + args.symbol + 'Size = sizeof(' + args.symbol + ');\n') + args.cpp.write('}\n') + + args.rodata.close() + args.cpp.close() + + +if __name__ == '__main__': + main() |