xref: /aosp_15_r20/external/mesa3d/src/util/gen_zipped_xml_file.py (revision 6104692788411f58d303aa86923a9ff6ecaded22)
1#encoding=utf-8
2#
3# Copyright © 2017 Intel Corporation
4# SPDX-License-Identifier: MIT
5
6import sys
7import zlib
8import xml.etree.ElementTree as et
9
10
11def main():
12    if len(sys.argv) < 2:
13        print("No input xml file specified")
14        sys.exit(1)
15
16    compress = zlib.compressobj()
17
18    print("static const struct {")
19    print("   uint32_t ver_10;")
20    print("   uint32_t offset;")
21    print("   uint32_t length;")
22    print("} genxml_files_table[] = {")
23
24    xml_offset = 0
25    compressed_data = b''
26    for i in range(1, len(sys.argv)):
27        filename = sys.argv[i]
28        xml = open(filename, "rb").read()
29        xml_length = len(xml)
30        root = et.fromstring(xml)
31
32        print("   { %i, %i, %i }," %
33              (int(float(root.attrib['gen']) * 10), xml_offset, xml_length))
34
35        compressed_data += compress.compress(xml)
36        xml_offset += xml_length
37
38    print("};")
39
40    compressed_data += compress.flush()
41
42    print("")
43    print("static const uint8_t compress_genxmls[] = {")
44    print("   ", end='')
45    for i, c in enumerate(bytearray(compressed_data), start=1):
46        print("0x%.2x, " % c, end='\n   ' if not i % 12 else '')
47    print('\n};')
48
49
50if __name__ == '__main__':
51    main()
52