forked from oneapi-src/unified-runtime
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun.py
More file actions
executable file
·216 lines (176 loc) · 7.46 KB
/
run.py
File metadata and controls
executable file
·216 lines (176 loc) · 7.46 KB
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
"""
Copyright (C) 2022 Intel Corporation
Part of the Unified-Runtime Project, under the Apache License v2.0 with LLVM Exceptions.
See LICENSE.TXT
SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
"""
import argparse
import re
import util
import parse_specs
import generate_code
import generate_docs
import os, sys, platform
import time
import subprocess
"""
helper for adding mutually-exclusive boolean arguments "--name" and "--!name"
"""
def add_argument(parser, name, help, default=False):
group = parser.add_mutually_exclusive_group(required=False)
group.add_argument("--" + name, dest=name, help="Enable "+help, action="store_true")
group.add_argument("--!" + name, dest=name, help="Disable "+help, action="store_false")
parser.set_defaults(**{name:default})
"""
helper for cleaning previously generated files
"""
def clean():
util.removePath("../include")
util.makePath("../include")
util.removePath("../build")
util.makePath("../build")
"""
help for updating spec documentation
"""
def update_spec(target):
inc = "%s/source/elements/l0/include" % target
src = "%s/source/elements/l0/source" % target
util.copyTree("../include", inc)
util.copyTree("../docs/source", src)
util.removePath("%s/experimental" % inc)
util.removePath("%s/experimental" % src)
"""
helper for running cmake windows build
"""
def build():
if "Windows" == platform.system():
result = os.system('cmake -B ../build/ -S .. -G "Visual Studio 16 2019" -A x64')
else:
result = -1 #todo
if result == 0:
result = os.system('cmake --build ../build --clean-first')
return result == 0
"""
helper for getting revision number from git repository
revision is number of commits since tag 'v0'
"""
def revision():
return '0'
result = subprocess.run(['git', 'describe', '--tags', '--dirty'], cwd=os.path.dirname(os.path.abspath(__file__)), stdout=subprocess.PIPE)
if result.returncode:
print('ERROR: Could not get revision number from git', file=sys.stderr)
return '0'
items = result.stdout.decode().strip().split('-')
tag = items[0][1:] # remove 'v'
print("Version is %s" % tag)
count = 0
if len(items) > 1 and items[1].isdigit():
count = int(items[1])
# Bump count if any local files are dirty.
# Keeps the count the same after doing a commit (assuming all dirty files are committed)
if 'dirty' in items[-1]:
count += 1
return '%s.%s'%(tag, count)
"""
helper for getting the default version from the project() command in the
root CMakeLists.txt file
"""
def get_version_from_cmakelists():
cmakelists_path = os.path.abspath(
os.path.join(os.path.dirname(__file__), '..', 'CMakeLists.txt'))
with open(cmakelists_path, 'r') as cmakelists_file:
for line in cmakelists_file.readlines():
line = line.strip()
if line.startswith('project('):
return re.findall(r'\d+\.\d+', line)[0]
raise Exception(f'unable to read project version from {cmakelists_path}')
"""
Main entry:
Do everything...
"""
def main():
# phase 0: parse cmdline arguments
configParser = util.configRead("config.ini")
parser = argparse.ArgumentParser()
for section in configParser.sections():
add_argument(parser, section, "generation of C/C++ '%s' files."%section, True)
add_argument(parser, "clean", "cleaning previous generated files.")
add_argument(parser, "build", "running cmake to generate and build projects.", False)
add_argument(parser, "debug", "dump intermediate data to disk.")
add_argument(parser, "html", "generation of HTML files.", True)
add_argument(parser, "pdf", "generation of PDF file.")
add_argument(parser, "rst", "generation of reStructuredText files.", True)
parser.add_argument("--update_spec", type=str, help="root of integrated spec directory to update")
parser.add_argument("--ver", type=str, default=get_version_from_cmakelists(),
required=False, help="specification version to generate.")
parser.add_argument("--api-json", type=str, default="unified_runtime.json", required=False, help="json output file for the spec")
parser.add_argument("--clang-format", type=str, default="clang-format", required=False, help="path to clang-format executable")
args = vars(parser.parse_args())
args['rev'] = revision()
print('Version', args['ver'])
start = time.time()
# phase 1: extract configuration info from ini file
input = {
'configs': [],
'specs' : [],
'meta' : {},
'ref' : {}
}
try:
for section in configParser.sections():
input['configs'].append({
'name' : section,
'namespace': configParser.get(section,'namespace'),
'tags' : {'$'+key : configParser.get(section,key) for key in configParser.get(section,'tags').split(",")},
})
# phase 2: parse specs
for config in input['configs']:
specs, input['meta'], input['ref'] = parse_specs.parse(config['name'], args['ver'], config['tags'], input['meta'], input['ref'])
input['specs'].append(specs)
util.jsonWrite(args['api_json'], input)
# phase 3: generate files
if args['clean']:
clean()
incpath = os.path.join("../include/")
srcpath = os.path.join("../source/")
docpath = os.path.join("../docs/")
generate_docs.prepare(docpath, args['rst'], args['html'], args['ver'])
for idx, specs in enumerate(input['specs']):
config = input['configs'][idx]
if args[config['name']]:
generate_code.generate_api(incpath, srcpath, config['namespace'], config['tags'], args['ver'], args['rev'], specs, input['meta'])
# clang-format ur_api.h
proc = subprocess.run([args['clang_format'], "--style=file", "-i" , "ur_api.h"], stderr=subprocess.PIPE, cwd=incpath)
if proc.returncode != 0:
print("-- clang-format failed with non-zero return code. --")
print(proc.stderr.decode())
raise Exception("Failed to format ur_api.h")
if args['rst']:
generate_docs.generate_rst(docpath, config['name'], config['namespace'], config['tags'], args['ver'], args['rev'], specs, input['meta'])
if util.makeErrorCount():
print("\n%s Errors found during generation, stopping execution!"%util.makeErrorCount())
return
if args['debug']:
util.makoFileListWrite("generated.json")
# phase 4: build code
if args['build']:
if not build():
print("\nBuild failed, stopping execution!")
return
# phase 5: prep for publication of html or pdf
if args['html'] or args['pdf']:
generate_docs.generate_common(docpath, configParser.sections(), args['ver'], args['rev'])
# phase 5: publish documentation
if args['html']:
generate_docs.generate_html(docpath)
if args['pdf']:
generate_docs.generate_pdf(docpath)
if args['update_spec']:
update_spec(args['update_spec'])
print("\nCompleted in %.1f seconds!"%(time.time() - start))
except BaseException as e:
print("Failed to generate specification.")
print(e)
return sys.exit(1)
if __name__ == '__main__':
main()