1bf215546Sopenharmony_ci# Copyright 2017 Intel Corporation 2bf215546Sopenharmony_ci# 3bf215546Sopenharmony_ci# Permission is hereby granted, free of charge, to any person obtaining a 4bf215546Sopenharmony_ci# copy of this software and associated documentation files (the 5bf215546Sopenharmony_ci# "Software"), to deal in the Software without restriction, including 6bf215546Sopenharmony_ci# without limitation the rights to use, copy, modify, merge, publish, 7bf215546Sopenharmony_ci# distribute, sub license, and/or sell copies of the Software, and to 8bf215546Sopenharmony_ci# permit persons to whom the Software is furnished to do so, subject to 9bf215546Sopenharmony_ci# the following conditions: 10bf215546Sopenharmony_ci# 11bf215546Sopenharmony_ci# The above copyright notice and this permission notice (including the 12bf215546Sopenharmony_ci# next paragraph) shall be included in all copies or substantial portions 13bf215546Sopenharmony_ci# of the Software. 14bf215546Sopenharmony_ci# 15bf215546Sopenharmony_ci# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 16bf215546Sopenharmony_ci# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17bf215546Sopenharmony_ci# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. 18bf215546Sopenharmony_ci# IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR 19bf215546Sopenharmony_ci# ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 20bf215546Sopenharmony_ci# TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 21bf215546Sopenharmony_ci# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22bf215546Sopenharmony_ci 23bf215546Sopenharmony_ciimport argparse 24bf215546Sopenharmony_ciimport json 25bf215546Sopenharmony_ciimport os.path 26bf215546Sopenharmony_ciimport re 27bf215546Sopenharmony_ciimport xml.etree.ElementTree as et 28bf215546Sopenharmony_ci 29bf215546Sopenharmony_cidef get_xml_patch_version(xml_file): 30bf215546Sopenharmony_ci xml = et.parse(xml_file) 31bf215546Sopenharmony_ci for d in xml.findall('.types/type'): 32bf215546Sopenharmony_ci if d.get('category', None) != 'define': 33bf215546Sopenharmony_ci continue 34bf215546Sopenharmony_ci 35bf215546Sopenharmony_ci name = d.find('.name') 36bf215546Sopenharmony_ci if name.text != 'VK_HEADER_VERSION': 37bf215546Sopenharmony_ci continue; 38bf215546Sopenharmony_ci 39bf215546Sopenharmony_ci return name.tail.strip() 40bf215546Sopenharmony_ci 41bf215546Sopenharmony_ciif __name__ == '__main__': 42bf215546Sopenharmony_ci parser = argparse.ArgumentParser() 43bf215546Sopenharmony_ci parser.add_argument('--api-version', required=True, 44bf215546Sopenharmony_ci help='Vulkan API version.') 45bf215546Sopenharmony_ci parser.add_argument('--xml', required=False, 46bf215546Sopenharmony_ci help='Vulkan registry XML for patch version') 47bf215546Sopenharmony_ci parser.add_argument('--lib-path', required=True, 48bf215546Sopenharmony_ci help='Path to installed library') 49bf215546Sopenharmony_ci parser.add_argument('--out', required=False, 50bf215546Sopenharmony_ci help='Output json file.') 51bf215546Sopenharmony_ci parser.add_argument('--use-backslash', action='store_true', 52bf215546Sopenharmony_ci help='Use backslash (Windows).') 53bf215546Sopenharmony_ci args = parser.parse_args() 54bf215546Sopenharmony_ci 55bf215546Sopenharmony_ci version = args.api_version 56bf215546Sopenharmony_ci if args.xml: 57bf215546Sopenharmony_ci re.match(r'\d+\.\d+', version) 58bf215546Sopenharmony_ci version = version + '.' + get_xml_patch_version(args.xml) 59bf215546Sopenharmony_ci else: 60bf215546Sopenharmony_ci re.match(r'\d+\.\d+\.\d+', version) 61bf215546Sopenharmony_ci 62bf215546Sopenharmony_ci lib_path = args.lib_path 63bf215546Sopenharmony_ci if args.use_backslash: 64bf215546Sopenharmony_ci lib_path = lib_path.replace('/', '\\') 65bf215546Sopenharmony_ci 66bf215546Sopenharmony_ci json_data = { 67bf215546Sopenharmony_ci 'file_format_version': '1.0.0', 68bf215546Sopenharmony_ci 'ICD': { 69bf215546Sopenharmony_ci 'library_path': lib_path, 70bf215546Sopenharmony_ci 'api_version': version, 71bf215546Sopenharmony_ci }, 72bf215546Sopenharmony_ci } 73bf215546Sopenharmony_ci 74bf215546Sopenharmony_ci json_params = { 75bf215546Sopenharmony_ci 'indent': 4, 76bf215546Sopenharmony_ci 'sort_keys': True, 77bf215546Sopenharmony_ci 'separators': (',', ': '), 78bf215546Sopenharmony_ci } 79bf215546Sopenharmony_ci 80bf215546Sopenharmony_ci if args.out: 81bf215546Sopenharmony_ci with open(args.out, 'w') as f: 82bf215546Sopenharmony_ci json.dump(json_data, f, **json_params) 83bf215546Sopenharmony_ci else: 84bf215546Sopenharmony_ci print(json.dumps(json_data, **json_params)) 85