|
| 1 | +#!/usr/bin/env python3 |
| 2 | + |
| 3 | +# Copyright 2025 The Khronos Group Inc. |
| 4 | +# SPDX-License-Identifier: Apache-2.0 |
| 5 | + |
| 6 | +import argparse |
| 7 | +import os |
| 8 | +import urllib |
| 9 | +import xml.etree.ElementTree as etree |
| 10 | +import urllib.request |
| 11 | + |
| 12 | +def parse_xml(path): |
| 13 | + file = urllib.request.urlopen(path) if path.startswith("http") else open(path, 'r') |
| 14 | + with file: |
| 15 | + tree = etree.parse(file) |
| 16 | + return tree |
| 17 | + |
| 18 | +def GetHeader(): |
| 19 | + return """// Copyright 2025 The Khronos Group. |
| 20 | +// SPDX-License-Identifier: CC-BY-4.0 |
| 21 | +
|
| 22 | +""" |
| 23 | + |
| 24 | +if __name__ == "__main__": |
| 25 | + parser = argparse.ArgumentParser() |
| 26 | + |
| 27 | + parser.add_argument('-registry', action='store', |
| 28 | + default='cl.xml', |
| 29 | + help='Use specified registry file instead of cl.xml') |
| 30 | + parser.add_argument('-o', action='store', dest='directory', |
| 31 | + default='.', |
| 32 | + help='Create target and related files in specified directory') |
| 33 | + |
| 34 | + args = parser.parse_args() |
| 35 | + |
| 36 | + specpath = args.registry |
| 37 | + |
| 38 | + print('Generating extension interfaces from: ' + specpath) |
| 39 | + |
| 40 | + spec = parse_xml(specpath) |
| 41 | + |
| 42 | + for extension in spec.findall('extensions/extension'): |
| 43 | + extname = extension.get('name') |
| 44 | + #print(extname) |
| 45 | + iface_file = open(os.path.join(args.directory, extname + '.txt'), 'w') |
| 46 | + |
| 47 | + iface_file.write(GetHeader()) |
| 48 | + |
| 49 | + # New commands |
| 50 | + commands = extension.findall('require/command') |
| 51 | + if commands: |
| 52 | + iface_file.write('=== New Commands\n\n') |
| 53 | + for cmd in commands: |
| 54 | + iface_file.write(' * {{{}}}\n'.format(cmd.get('name'))) |
| 55 | + iface_file.write('\n') |
| 56 | + |
| 57 | + # New types |
| 58 | + types = extension.findall('require/type') |
| 59 | + if types: |
| 60 | + iface_file.write('=== New Types\n\n') |
| 61 | + for ty in types: |
| 62 | + iface_file.write(' * {{{}_TYPE}}\n'.format(ty.get('name'))) |
| 63 | + |
| 64 | + # New enums |
| 65 | + first_enum = True |
| 66 | + requires = extension.findall('require') |
| 67 | + for req in requires: |
| 68 | + enums = req.findall('enum') |
| 69 | + first_for_require = True |
| 70 | + for e in enums: |
| 71 | + if first_enum: |
| 72 | + iface_file.write('=== New enums\n\n') |
| 73 | + first_enum = False |
| 74 | + if first_for_require: |
| 75 | + comment = req.get('comment') |
| 76 | + if comment == 'Error codes': |
| 77 | + iface_file.write(' * New Error Codes\n') |
| 78 | + else: |
| 79 | + iface_file.write(' * {{{}_TYPE}}\n'.format(comment)) |
| 80 | + first_for_require = False |
| 81 | + iface_file.write(' ** {{{}}}\n'.format(e.get('name'))) |
| 82 | + iface_file.write('\n') |
| 83 | + |
| 84 | + iface_file.close() |
0 commit comments