-
Notifications
You must be signed in to change notification settings - Fork 34
Expand file tree
/
Copy pathgen_docs.py
More file actions
188 lines (173 loc) · 5.46 KB
/
gen_docs.py
File metadata and controls
188 lines (173 loc) · 5.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
# Data Parallel Control (dpctl)
#
# Copyright 2020-2025 Intel Corporation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import os
import subprocess
import sys
def run(
use_oneapi=True,
c_compiler=None,
cxx_compiler=None,
level_zero=True,
compiler_root=None,
bin_llvm=None,
doxyrest_dir=None,
verbose=False,
cmake_opts="",
):
IS_LIN = False
if "linux" in sys.platform:
IS_LIN = True
elif sys.platform in ["win32", "cygwin"]:
pass
else:
assert False, sys.platform + " not supported"
if not IS_LIN:
raise RuntimeError(
"This scripts only supports coverage collection on Linux"
)
setup_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
cmake_args = [
sys.executable,
"setup.py",
"develop",
"--build-type=Release",
"--generator=Ninja",
"--",
"-DCMAKE_C_COMPILER:PATH=" + c_compiler,
"-DCMAKE_CXX_COMPILER:PATH=" + cxx_compiler,
"-DDPCTL_ENABLE_L0_PROGRAM_CREATION=" + ("ON" if level_zero else "OFF"),
"-DDPCTL_GENERATE_DOCS=ON",
]
if verbose:
cmake_args.append("-DCMAKE_VERBOSE_MAKEFILE=ON")
if doxyrest_dir:
cmake_args.append("-DDPCTL_ENABLE_DOXYREST=ON")
cmake_args.append("-DDoxyrest_DIR=" + doxyrest_dir)
if cmake_opts:
cmake_args += cmake_opts.split()
env = dict()
if bin_llvm:
env = {
"PATH": ":".join((os.environ.get("PATH", ""), bin_llvm)),
}
env.update({k: v for k, v in os.environ.items() if k != "PATH"})
# Install dpctl package
subprocess.check_call(cmake_args, shell=False, cwd=setup_dir, env=env)
# Get the path for the build directory
build_dir = (
subprocess.check_output(
["find", "_skbuild", "-name", "cmake-build"],
cwd=setup_dir,
)
.decode("utf-8")
.strip("\n")
)
# Generate docs
subprocess.check_call(
["cmake", "--build", ".", "--target", "Sphinx"], cwd=build_dir
)
generated_doc_dir = (
subprocess.check_output(
["find", "_skbuild", "-name", "index.html"], cwd=setup_dir
)
.decode("utf-8")
.strip("\n")
)
print("Generated documentation placed under ", generated_doc_dir)
if __name__ == "__main__":
import argparse
parser = argparse.ArgumentParser(
description="Driver to build dpctl and generate coverage"
)
driver = parser.add_argument_group(title="Coverage driver arguments")
driver.add_argument("--c-compiler", help="Name of C compiler", default=None)
driver.add_argument(
"--cxx-compiler", help="Name of C++ compiler", default=None
)
driver.add_argument(
"--not-oneapi",
help="Is one-API installation",
dest="oneapi",
action="store_false",
)
driver.add_argument(
"--compiler-root", type=str, help="Path to compiler home directory"
)
driver.add_argument(
"--no-level-zero",
help="Enable Level Zero support",
dest="level_zero",
action="store_false",
)
driver.add_argument(
"--bin-llvm", help="Path to folder where llvm-cov can be found"
)
driver.add_argument(
"--doxyrest-root",
help=(
"Path to Doxyrest installation to use to generate Sphinx docs"
+ "for libsyclinterface"
),
)
driver.add_argument(
"--verbose",
help="Build using vebose makefile mode",
dest="verbose",
action="store_true",
)
driver.add_argument(
"--cmake-opts",
help="Options to pass through to cmake",
dest="cmake_opts",
default="",
type=str,
)
args = parser.parse_args()
if args.oneapi:
args.c_compiler = "icx"
args.cxx_compiler = "icpx"
args.compiler_root = None
icx_path = subprocess.check_output(["which", "icx"])
bin_dir = os.path.dirname(icx_path)
args.bin_llvm = os.path.join(bin_dir.decode("utf-8"), "compiler")
else:
args_to_validate = [
"c_compiler",
"cxx_compiler",
"compiler_root",
"bin_llvm",
]
for p in args_to_validate:
arg = getattr(args, p, None)
if not isinstance(arg, str):
opt_name = p.replace("_", "-")
raise RuntimeError(
f"Option {opt_name} must be provided is "
"using non-default DPC++ layout"
)
if not os.path.exists(arg):
raise RuntimeError(f"Path {arg} must exist")
run(
use_oneapi=args.oneapi,
c_compiler=args.c_compiler,
cxx_compiler=args.cxx_compiler,
level_zero=args.level_zero,
compiler_root=args.compiler_root,
bin_llvm=args.bin_llvm,
doxyrest_dir=args.doxyrest_root,
verbose=args.verbose,
cmake_opts=args.cmake_opts,
)