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