Path: blob/21.2-virgl/src/vulkan/util/vk_icd_gen.py
7233 views
# Copyright 2017 Intel Corporation1#2# Permission is hereby granted, free of charge, to any person obtaining a3# copy of this software and associated documentation files (the4# "Software"), to deal in the Software without restriction, including5# without limitation the rights to use, copy, modify, merge, publish,6# distribute, sub license, and/or sell copies of the Software, and to7# permit persons to whom the Software is furnished to do so, subject to8# the following conditions:9#10# The above copyright notice and this permission notice (including the11# next paragraph) shall be included in all copies or substantial portions12# of the Software.13#14# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS15# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF16# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.17# IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR18# ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,19# TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE20# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.2122import argparse23import json24import os.path25import re26import xml.etree.ElementTree as et2728def get_xml_patch_version(xml_file):29xml = et.parse(xml_file)30for d in xml.findall('.types/type'):31if d.get('category', None) != 'define':32continue3334name = d.find('.name')35if name.text != 'VK_HEADER_VERSION':36continue;3738return name.tail.strip()3940if __name__ == '__main__':41parser = argparse.ArgumentParser()42parser.add_argument('--api-version', required=True,43help='Vulkan API version.')44parser.add_argument('--xml', required=False,45help='Vulkan registry XML for patch version')46parser.add_argument('--lib-path', required=True,47help='Path to installed library')48parser.add_argument('--out', required=False,49help='Output json file.')50args = parser.parse_args()5152version = args.api_version53if args.xml:54re.match(r'\d+\.\d+', version)55version = version + '.' + get_xml_patch_version(args.xml)56else:57re.match(r'\d+\.\d+\.\d+', version)5859json_data = {60'file_format_version': '1.0.0',61'ICD': {62'library_path': args.lib_path,63'api_version': version,64},65}6667json_params = {68'indent': 4,69'sort_keys': True,70'separators': (',', ': '),71}7273if args.out:74with open(args.out, 'w') as f:75json.dump(json_data, f, **json_params)76else:77print(json.dumps(json_data, **json_params))787980