forked from KhronosGroup/Vulkan-Docs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmakeSpec
executable file
·111 lines (93 loc) · 4.06 KB
/
makeSpec
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
#!/usr/bin/env python3
#
# Copyright 2020-2021 The Khronos Group Inc.
#
# SPDX-License-Identifier: Apache-2.0
# Build a spec with requested extension sets and options.
#
# Usage: makeSpec script-options make-options
# Script options are parsed by this script before invoking 'make':
# -genpath path - directory for generated files and outputs
# -spec core - make a spec with no extensions (default)
# -spec khr - make a spec with all KHR extensions
# -spec all - make a spec with all registered extensions
# -ext name - add specified extension and its dependencies
# -clean - clean generated files before building
# -v - verbose, print actions before executing them
# -n - dry-run, print actions instead of executing them
# make-options - all other options are passed to 'make', including
# requested build targets
import argparse, copy, io, os, re, string, subprocess, sys
def execute(args, results):
if results.verbose or results.dryrun:
print("'" + "' '".join(args) + "'")
if not results.dryrun:
subprocess.check_call(args)
if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.add_argument('-clean', action='store_true',
help='Clean generated files before building')
parser.add_argument('-extension', action='append',
default=[],
help='Specify a required extension or extensions to add to targets')
parser.add_argument('-genpath', action='store',
default='gen',
help='Path to directory containing generated files')
parser.add_argument('-spec', action='store',
choices=[ 'core', 'khr', 'all' ],
default='core',
help='Type of spec to generate')
parser.add_argument('-n', action='store_true', dest='dryrun',
help='Only prints actions, do not execute them')
parser.add_argument('-v', action='store_true', dest='verbose',
help='Print actions before executing them')
(results, options) = parser.parse_known_args()
# Ensure genpath is an absolute path, not relative
if results.genpath[0] != '/':
results.genpath = os.getcwd() + '/' + results.genpath
# Ensure extDependency.py exists and is up to date before importing it
execute(['make', 'GENERATED=' + results.genpath, 'extDependency'], results)
# Look for extDependency.py in the specified directory and import it
sys.path.insert(0, results.genpath)
from extDependency import extensions, allExts, khrExts
# List of extensions to build with from the requested -spec
# Also construct a spec title
if results.spec == 'core':
title = ''
exts = set()
if results.spec == 'khr':
title = 'with all KHR extensions'
exts = set(khrExts)
elif results.spec == 'all':
title = 'with all registered extensions'
exts = set(allExts)
# List of explicitly requested extension and all its dependencies
extraexts = set()
for name in results.extension:
if name in extensions:
extraexts.add(name)
extraexts.update(extensions[name])
else:
print('ERROR: unknown extension', name, file=sys.stderr)
sys.exit(1)
# See if any explicitly requested extensions aren't implicitly requested
# Add any such extensions to the spec title
extraexts -= exts
if len(extraexts) > 0:
exts.update(extraexts)
if title != '':
title += ' and ' + ', '.join(sorted(extraexts))
else:
title += 'with ' + ', '.join(sorted(extraexts))
if title != '':
title = '(' + title + ')'
# Finally, actually invoke make as needed for the targets
args = [ 'make', 'GENERATED=' + results.genpath ]
if results.clean:
execute(args + ['clean'], results)
# The actual target
if len(exts) > 0:
args.append('EXTENSIONS={}'.format(' '.join(sorted(exts))))
args.append('APITITLE={}'.format(title))
args += options
execute(args, results)