FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
unified-runtime/scripts/generate_docs.py at main · oneapi-src/unified-runtime · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
oneapi-src
/
unified-runtime
Public
Notifications
You must be signed in to change notification settings
Fork
120
Star
57
Code
Issues
109
Pull requests
0
Discussions
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Discussions
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
unified-runtime
/
scripts
/
generate_docs.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
346 lines (287 loc) · 11.3 KB
Breadcrumbs
unified-runtime
/
scripts
/
generate_docs.py
Copy path
File metadata and controls
346 lines (287 loc) · 11.3 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
#
# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
# See https://llvm.org/LICENSE.txt for license information.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
import
os
import
subprocess
import
util
import
re
from
parse_specs
import
Version
RE_ENABLE
=
r"^\#\#\s*\-\-validate\s*\=\s*on$"
RE_DISABLE
=
r"^\#\#\s*\-\-validate\s*\=\s*off$"
RE_PYCODE_BLOCK_BEGIN
=
r"^\<\%$"
RE_PYCODE_BLOCK_END
=
r"^\%\>$"
RE_INVALID_TAG_FORMAT
=
r".*(\$\w).*"
RE_EXTRACT_TAG_NAME
=
r"\$\{(\w)\}"
RE_PROPER_TAG_FORMAT
=
r".*"
+
RE_EXTRACT_TAG_NAME
+
r".*"
RE_CODE_BLOCK_BEGIN
=
r"\s*..\sparsed-literal::"
RE_EXTRACT_NAME
=
r"\$\{\w\}\w+"
RE_EXTRACT_PARAMS
=
r"\w+\((.*)\)\;"
RE_VERSION_BEGIN
=
r"\%if\s+(ver\s+[\<\=\>]+\s+[-+]?\d*\.\d+|\d+).*"
RE_VERSION_END
=
r"\%endif\s+#\s+.*"
def
_find_symbol_type
(
name
,
meta
):
"""determines if the symbol is known"""
for
group
in
meta
:
if
name
in
meta
[
group
]:
return
group
if
name
.
isupper
():
for
enum
in
meta
[
"enum"
]:
if
name
in
meta
[
"enum"
][
enum
][
"etors"
]:
return
"etor"
return
None
def
_fixup_tag
(
name
):
"""fix up tag for template (e.g. $x to ${x})"""
return
re
.
sub
(
r"\$(?P<tag>\w)"
,
r"${\g<tag>}"
,
name
)
def
_find_enum_from_etor
(
etor
,
meta
):
for
name
in
meta
[
"enum"
]:
if
etor
in
meta
[
"enum"
][
name
][
"etors"
]:
return
_fixup_tag
(
name
)
return
None
def
_make_ref
(
symbol
,
symbol_type
,
meta
):
"""make restructedtext reference from symbol."""
if
not
re
.
match
(
r"function|struct|union|enum|etor|macro"
,
symbol_type
):
return
""
ref
=
_fixup_tag
(
symbol
)
if
re
.
match
(
"etor"
,
symbol_type
):
target
=
_find_enum_from_etor
(
symbol
,
meta
)
if
target
:
ref
=
":ref:`"
+
ref
+
" <"
+
target
.
replace
(
"_"
,
"-"
)
+
">`"
else
:
print
(
"%s(%s) : error : enum symbol not found for etor %s"
%
(
fin
,
iline
+
1
,
symbol
)
)
raise
Exception
()
elif
not
re
.
match
(
"function"
,
symbol_type
):
ref
=
":ref:`"
+
ref
.
replace
(
"_"
,
"-"
)
+
"`"
else
:
ref
=
":ref:`"
+
ref
+
"`"
return
ref
def
_generate_valid_rst
(
fin
,
fout
,
namespace
,
tags
,
ver
,
rev
,
meta
,
fast_mode
):
"""generate a valid reStructuredText file"""
ver
=
Version
(
ver
)
enable
=
True
code_block
=
False
print
(
"Generating %s..."
%
fout
)
error
=
False
outlines
=
[]
iter
=
enumerate
(
util
.
textRead
(
fin
))
for
iline
,
line
in
iter
:
if
re
.
match
(
RE_ENABLE
,
line
)
or
re
.
match
(
RE_PYCODE_BLOCK_END
,
line
):
enable
=
True
elif
re
.
match
(
RE_DISABLE
,
line
)
or
re
.
match
(
RE_PYCODE_BLOCK_BEGIN
,
line
):
enable
=
False
elif
re
.
match
(
RE_CODE_BLOCK_BEGIN
,
line
):
code_block
=
True
elif
re
.
match
(
r"^\w"
,
line
)
and
code_block
:
# code is always indented
code_block
=
False
elif
re
.
match
(
RE_VERSION_BEGIN
,
line
):
enable
=
eval
(
re
.
sub
(
RE_VERSION_BEGIN
,
r"\1"
,
line
))
elif
re
.
match
(
RE_VERSION_END
,
line
):
enable
=
True
if
not
enable
:
outlines
.
append
(
line
)
continue
if
re
.
match
(
RE_INVALID_TAG_FORMAT
,
line
):
print
(
"%s(%s) : error : invalid %s tag used"
%
(
fin
,
iline
+
1
,
re
.
sub
(
RE_INVALID_TAG_FORMAT
,
r"\1"
,
line
))
)
error
=
True
newline
=
(
line
# new line will contain proper tags for reStructuredText if needed.
)
if
re
.
match
(
RE_PROPER_TAG_FORMAT
,
line
):
words
=
re
.
findall
(
RE_EXTRACT_NAME
,
line
)
newline
=
""
for
word
in
words
:
symbol
=
re
.
sub
(
RE_EXTRACT_TAG_NAME
,
r"$\1"
,
word
)
if
symbol
:
symbol_type
=
_find_symbol_type
(
symbol
,
meta
)
if
not
symbol_type
:
print
(
"%s(%s) : error : symbol '%s' not found"
%
(
fin
,
iline
+
1
,
symbol
)
)
error
=
True
continue
if
code_block
and
"function"
==
symbol_type
:
# If function is split across multiple lines
# then join lines until a ';' is encountered.
try
:
line
=
line
.
rstrip
()
while
not
line
.
endswith
(
";"
):
_
,
n_line
=
next
(
iter
)
line
=
line
+
n_line
.
strip
()
line
+=
"
\n
"
except
StopIteration
:
print
(
f"Function
{
line
[:
100
]
}
was not terminated by a ';' character."
)
error
=
True
words
=
re
.
sub
(
RE_EXTRACT_PARAMS
,
r"\1"
,
line
)
words
=
line
.
split
(
","
)
if
len
(
words
)
!=
len
(
meta
[
"function"
][
symbol
][
"params"
]):
print
(
"%s(%s) : error : %s parameter count mismatch - %s actual vs. %s expected"
%
(
fin
,
iline
+
1
,
symbol
,
len
(
words
),
len
(
meta
[
"function"
][
symbol
][
"params"
]),
)
)
print
(
"line = %s"
%
line
)
error
=
True
ref
=
_make_ref
(
symbol
,
symbol_type
,
meta
)
if
ref
:
tuple
=
line
.
partition
(
word
)
newline
+=
tuple
[
0
]
+
tuple
[
1
].
replace
(
word
,
ref
)
if
tuple
[
2
]
and
not
re
.
match
(
r"\s"
,
tuple
[
2
]):
# reStructuredText requires an escape character after references that are not followed by whitespace.
newline
+=
"
\\
"
line
=
tuple
[
2
]
else
:
# ignore reference links for specific types that have no API documentation for them.
if
not
re
.
match
(
r"env|handle|typedef"
,
symbol_type
):
print
(
"%s(%s) : warning : reference link %s (type=%s) not used."
%
(
fin
,
iline
+
1
,
symbol
,
symbol_type
)
)
else
:
print
(
"%s(%s) : warning : reference link %s not used."
%
(
fin
,
iline
+
1
,
word
)
)
newline
+=
line
outlines
.
append
(
newline
)
if
error
:
raise
Exception
(
"Error during reStructuredText generation."
)
util
.
writelines
(
os
.
path
.
abspath
(
fout
),
outlines
)
return
util
.
makoWrite
(
os
.
path
.
abspath
(
fout
),
fout
,
ver
=
ver
,
namespace
=
namespace
,
tags
=
tags
,
meta
=
meta
,
fast_mode
=
fast_mode
,
)
def
generate_rst
(
docpath
,
section
,
namespace
,
tags
,
ver
,
rev
,
specs
,
meta
,
fast_mode
):
"""
Entry-point:
generate restructuredtext documents from templates
"""
srcpath
=
os
.
path
.
join
(
"./"
,
section
)
dstpath
=
os
.
path
.
join
(
docpath
,
"source"
,
section
)
loc
=
0
util
.
makePath
(
dstpath
)
util
.
removeFiles
(
dstpath
,
"*.rst"
)
for
fin
in
util
.
findFiles
(
srcpath
,
"*.rst"
):
fout
=
os
.
path
.
join
(
dstpath
,
os
.
path
.
basename
(
fin
))
loc
+=
_generate_valid_rst
(
os
.
path
.
abspath
(
fin
),
fout
,
namespace
,
tags
,
ver
,
rev
,
meta
,
fast_mode
)
print
(
"Generated %s lines of reStructuredText (rst).
\n
"
%
loc
)
if
loc
>
0
:
fin
=
os
.
path
.
join
(
"templates"
,
"api_listing.mako"
)
fout
=
os
.
path
.
join
(
dstpath
,
"api.rst"
)
groupname
=
os
.
path
.
basename
(
dstpath
).
capitalize
()
util
.
makoWrite
(
fin
,
fout
,
namespace
=
namespace
,
groupname
=
groupname
,
ver
=
ver
,
rev
=
rev
,
tags
=
tags
,
meta
=
meta
,
specs
=
specs
,
fast_mode
=
fast_mode
,
)
def
generate_common
(
dstpath
,
sections
,
ver
,
rev
):
"""
Entry-point:
generate doxygen xml and setup source path.
"""
htmlpath
=
os
.
path
.
join
(
dstpath
,
"html"
)
latexpath
=
os
.
path
.
join
(
dstpath
,
"latex"
)
xmlpath
=
os
.
path
.
join
(
dstpath
,
"xml"
)
sourcepath
=
os
.
path
.
join
(
dstpath
,
"source"
)
util
.
removePath
(
htmlpath
)
util
.
removePath
(
latexpath
)
util
.
removePath
(
xmlpath
)
util
.
makePath
(
xmlpath
)
# Generate sphinx configuration file with version.
loc
=
0
for
fn
in
[
"conf.py"
,
"index.rst"
,
"api.rst"
,
"exp-features.rst"
]:
loc
+=
util
.
makoWrite
(
"./templates/%s.mako"
%
fn
,
os
.
path
.
join
(
sourcepath
,
fn
),
ver
=
ver
,
rev
=
rev
,
sourcepath
=
sourcepath
,
sections
=
sections
,
)
# Doxygen generates XML files needed by sphinx breathe plugin for API documentation.
print
(
"Generating doxygen..."
)
proc
=
subprocess
.
Popen
([
"doxygen"
,
"Doxyfile"
],
stderr
=
subprocess
.
PIPE
)
proc
.
wait
()
output
=
proc
.
stderr
.
read
().
decode
()
print
(
output
)
if
(
re
.
search
(
r"warning: explicit link request to \'.*\' could not be resolved"
,
output
)
and
"CI"
in
os
.
environ
):
raise
Exception
(
"Doxygen has unresolved references"
)
def
generate_html
(
dstpath
):
"""
Entry-point:
generate HTML files using reStructuredText (rst) and Doxygen template
"""
sourcepath
=
os
.
path
.
join
(
dstpath
,
"source"
)
print
(
"Generating HTML..."
)
result
=
subprocess
.
run
(
[
"sphinx-build"
,
"-M"
,
"html"
,
sourcepath
,
"../docs"
],
stderr
=
subprocess
.
PIPE
)
if
result
.
returncode
!=
0
:
print
(
"sphinx-build returned non-zero error code."
)
print
(
"--- output ---"
)
print
(
result
.
stderr
.
decode
())
raise
Exception
(
"Failed to generate html documentation."
)
def
generate_pdf
(
dstpath
):
"""
Entry-point:
generate PDF file using generated LaTeX files
"""
sourcepath
=
os
.
path
.
join
(
dstpath
,
"source"
)
print
(
"Generating PDF..."
)
result
=
subprocess
.
run
(
[
"sphinx-build"
,
"-b"
,
"pdf"
,
sourcepath
,
"../docs/latex"
],
stderr
=
subprocess
.
PIPE
,
)
if
result
.
returncode
!=
0
:
print
(
"sphinx-build returned non-zero error code."
)
print
(
"--- output ---"
)
print
(
result
.
stderr
.
decode
())
raise
Exception
(
"Failed to generate pdf documentation."
)
def
prepare
(
docpath
,
gen_rst
,
gen_html
,
ver
):
"""
Entry-point:
prepare doc folder for documentation.
"""
if
gen_html
:
htmlpath
=
os
.
path
.
join
(
docpath
,
"html"
)
if
util
.
exists
(
htmlpath
):
util
.
removePath
(
htmlpath
)
# if generating rst then assume everything in docs is invalid and clean it.
if
gen_rst
:
if
util
.
exists
(
docpath
):
util
.
removePath
(
docpath
)
docsourcepath
=
os
.
path
.
join
(
docpath
,
"source"
)
util
.
copyTree
(
"./assets/html/_static"
,
os
.
path
.
join
(
docsourcepath
,
"_static"
))
util
.
copyTree
(
"./assets/html/_templates"
,
os
.
path
.
join
(
docsourcepath
,
"_templates"
))
util
.
copyTree
(
"./assets/images"
,
os
.
path
.
join
(
docsourcepath
,
"images"
))
Back
|
FazBrowse Home
|
New Git URL