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