xref: /aosp_15_r20/external/angle/third_party/vulkan-headers/src/registry/stripAPI.py (revision 8975f5c5ed3d1c378011245431ada316dfb6f244)
1#!/usr/bin/env python3
2#
3# Copyright 2023-2024 The Khronos Group Inc.
4# SPDX-License-Identifier: Apache-2.0
5
6import argparse
7import xml.etree.ElementTree as etree
8from reg import stripNonmatchingAPIs
9
10if __name__ == '__main__':
11    parser = argparse.ArgumentParser(prog='stripAPI',
12                formatter_class=argparse.RawDescriptionHelpFormatter,
13                description='''\
14Filters out elements with non-matching explicit 'api' attributes from API XML.
15To 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
17To remove Vulkan-only elements:
18    python3 scripts/stripAPI.py -input xml/vk.xml -output vulkansc-only.xml -keepAPI vulkansc
19If you are parsing the XML yourself but using the xml.etree package, the
20equivalent runtime code is:
21   import reg
22   reg.stripNonmatchingAPIs(tree.getroot(), keepAPI, actuallyDelete=True)
23where '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
43