|
1501
|
1 #!/usr/bin/env python3
|
|
|
2 #
|
|
|
3 # Copyright 2023-2025 The Khronos Group Inc.
|
|
|
4 # SPDX-License-Identifier: Apache-2.0
|
|
|
5
|
|
|
6 import argparse
|
|
|
7 import xml.etree.ElementTree as etree
|
|
|
8 from reg import stripNonmatchingAPIs
|
|
|
9
|
|
|
10 if __name__ == '__main__':
|
|
|
11 parser = argparse.ArgumentParser(prog='stripAPI',
|
|
|
12 formatter_class=argparse.RawDescriptionHelpFormatter,
|
|
|
13 description='''\
|
|
|
14 Filters out elements with non-matching explicit 'api' attributes from API XML.
|
|
|
15 To remove Vulkan SC-only elements from the combined API XML:
|
|
|
16 python3 scripts/stripAPI.py -input xml/vk.xml -output vulkan-only.xml -keepAPI vulkan
|
|
|
17 To remove Vulkan-only elements:
|
|
|
18 python3 scripts/stripAPI.py -input xml/vk.xml -output vulkansc-only.xml -keepAPI vulkansc
|
|
|
19 If you are parsing the XML yourself but using the xml.etree package, the
|
|
|
20 equivalent runtime code is:
|
|
|
21 import reg
|
|
|
22 reg.stripNonmatchingAPIs(tree.getroot(), keepAPI, actuallyDelete=True)
|
|
|
23 where 'tree' is an ElementTree created from the XML file using
|
|
|
24 etree.parse(filename)''')
|
|
|
25
|
|
|
26 parser.add_argument('-input', action='store',
|
|
|
27 required=True,
|
|
|
28 help='Specify input registry XML')
|
|
|
29 parser.add_argument('-output', action='store',
|
|
|
30 required=True,
|
|
|
31 help='Specify output registry XML')
|
|
|
32 parser.add_argument('-keepAPI', action='store',
|
|
|
33 default=None,
|
|
|
34 help='Specify API name whose \'api\' tags are kept')
|
|
|
35
|
|
|
36 args = parser.parse_args()
|
|
|
37
|
|
|
38 tree = etree.parse(args.input)
|
|
|
39 if args.keepAPI is not None:
|
|
|
40 stripNonmatchingAPIs(tree.getroot(), args.keepAPI, actuallyDelete = True)
|
|
|
41 tree.write(args.output)
|
|
|
42
|