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