Skip to content

Commit 4d34c9b

Browse files
baderdm-vodopyanov
andauthored
[BuildBot] Improve usability of buildbot scripts (#1472)
1. Make all parameters optional with (hopefully) useful defaults. 2. Run actions through CMake to make the independent from the build system (e.g. Ninja/Makefiles/MSVC/etc.) Signed-off-by: Alexey Bader <[email protected]> Co-Authored-By: Dmitry Vodopyanov <[email protected]>
1 parent 6d0f798 commit 4d34c9b

File tree

4 files changed

+81
-33
lines changed

4 files changed

+81
-33
lines changed

buildbot/check.py

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,41 @@
11
import argparse
22
import os
3+
import multiprocessing
34
import subprocess
45
import sys
56

67
DEFAULT_CPU_COUNT = 4
78

89
def do_check(args):
9-
ret = False
10-
11-
cpu_count = os.cpu_count()
12-
if cpu_count is None:
10+
try:
11+
cpu_count = multiprocessing.cpu_count()
12+
except NotImplementedError:
1313
cpu_count = DEFAULT_CPU_COUNT
1414

15+
# Get absolute path to source directory
16+
if args.src_dir:
17+
abs_src_dir = os.path.abspath(args.src_dir)
18+
else:
19+
abs_src_dir = os.path.abspath(os.path.join(__file__, "../.."))
20+
# Get absolute path to build directory
21+
if args.obj_dir:
22+
abs_obj_dir = os.path.abspath(args.obj_dir)
23+
else:
24+
abs_obj_dir = os.path.join(abs_src_dir, "build")
25+
26+
cmake_cmd = [
27+
"cmake",
28+
"--build", abs_obj_dir,
29+
"--",
30+
args.test_suite,
31+
"-j", str(cpu_count)]
32+
33+
print(cmake_cmd)
34+
1535
env_tmp=os.environ
1636
env_tmp["LIT_ARGS"]="\"{}\"".format("-v")
1737

18-
make_cmd = ["ninja", args.test_suite, "-j", str(cpu_count)]
19-
print(make_cmd)
20-
21-
subprocess.check_call(make_cmd, cwd=args.obj_dir, env=env_tmp)
38+
subprocess.check_call(cmake_cmd, cwd=abs_obj_dir, env=env_tmp)
2239

2340
ret = True
2441
return ret
@@ -34,8 +51,8 @@ def main():
3451
parser.add_argument("-w", "--builder-dir", metavar="BUILDER_DIR",
3552
help="builder directory, which is the directory contains source and build directories")
3653
parser.add_argument("-s", "--src-dir", metavar="SRC_DIR", help="source directory")
37-
parser.add_argument("-o", "--obj-dir", metavar="OBJ_DIR", required=True, help="build directory")
38-
parser.add_argument("-t", "--test-suite", metavar="TEST_SUITE", required=True, help="check-xxx target")
54+
parser.add_argument("-o", "--obj-dir", metavar="OBJ_DIR", help="build directory")
55+
parser.add_argument("-t", "--test-suite", metavar="TEST_SUITE", default="check-all", help="check-xxx target")
3956

4057
args = parser.parse_args()
4158

@@ -47,4 +64,3 @@ def main():
4764
ret = main()
4865
exit_code = 0 if ret else 1
4966
sys.exit(exit_code)
50-

buildbot/compile.py

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import multiprocessing
33
import subprocess
44
import sys
5+
import os
56

67
DEFAULT_CPU_COUNT = 4
78

@@ -12,10 +13,28 @@ def do_compile(args):
1213
except NotImplementedError:
1314
cpu_count = DEFAULT_CPU_COUNT
1415

15-
make_cmd = ["ninja", "-j", str(cpu_count), "deploy-sycl-toolchain", "deploy-opencl-aot"]
16-
print(make_cmd)
16+
# Get absolute path to source directory
17+
if args.src_dir:
18+
abs_src_dir = os.path.abspath(args.src_dir)
19+
else:
20+
abs_src_dir = os.path.abspath(os.path.join(__file__, "../.."))
21+
# Get absolute path to build directory
22+
if args.obj_dir:
23+
abs_obj_dir = os.path.abspath(args.obj_dir)
24+
else:
25+
abs_obj_dir = os.path.join(abs_src_dir, "build")
1726

18-
subprocess.check_call(make_cmd, cwd=args.obj_dir)
27+
cmake_cmd = [
28+
"cmake",
29+
"--build", abs_obj_dir,
30+
"--",
31+
"deploy-sycl-toolchain",
32+
"deploy-opencl-aot",
33+
"-j", str(cpu_count)]
34+
35+
print(cmake_cmd)
36+
37+
subprocess.check_call(cmake_cmd, cwd=abs_obj_dir)
1938

2039
return True
2140

@@ -31,7 +50,7 @@ def main():
3150
parser.add_argument("-w", "--builder-dir", metavar="BUILDER_DIR",
3251
help="builder directory, which is the directory contains source and build directories")
3352
parser.add_argument("-s", "--src-dir", metavar="SRC_DIR", help="source directory")
34-
parser.add_argument("-o", "--obj-dir", metavar="OBJ_DIR", required=True, help="build directory")
53+
parser.add_argument("-o", "--obj-dir", metavar="OBJ_DIR", help="build directory")
3554

3655
args = parser.parse_args()
3756

@@ -44,4 +63,3 @@ def main():
4463
ret = main()
4564
exit_code = 0 if ret else 1
4665
sys.exit(exit_code)
47-

buildbot/configure.py

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,21 @@
44
import sys
55
import platform
66

7-
# TODO:
8-
# 1. Make all required options optional
9-
# 2. Create obj_dir from the script if it doesn't exist
10-
117
def do_configure(args):
128
ret = False
139

14-
# Get absolute paths
15-
abs_src_dir = os.path.abspath(args.src_dir)
16-
abs_obj_dir = os.path.abspath(args.obj_dir)
10+
# Get absolute path to source directory
11+
if args.src_dir:
12+
abs_src_dir = os.path.abspath(args.src_dir)
13+
else:
14+
abs_src_dir = os.path.abspath(os.path.join(__file__, "../.."))
15+
# Get absolute path to build directory
16+
if args.obj_dir:
17+
abs_obj_dir = os.path.abspath(args.obj_dir)
18+
else:
19+
abs_obj_dir = os.path.join(abs_src_dir, "build")
20+
if not os.path.isdir(abs_obj_dir):
21+
os.makedirs(abs_obj_dir)
1722

1823
llvm_dir = os.path.join(abs_src_dir, "llvm")
1924
sycl_dir = os.path.join(abs_src_dir, "sycl")
@@ -60,7 +65,7 @@ def do_configure(args):
6065

6166
cmake_cmd = [
6267
"cmake",
63-
"-G", "Ninja",
68+
"-G", args.cmake_gen,
6469
"-DCMAKE_BUILD_TYPE={}".format(args.build_type),
6570
"-DLLVM_ENABLE_ASSERTIONS={}".format(llvm_enable_assertions),
6671
"-DLLVM_TARGETS_TO_BUILD={}".format(llvm_targets_to_build),
@@ -117,17 +122,18 @@ def main():
117122
parser.add_argument("-r", "--pr-number", metavar="PR_NUM", help="pull request number")
118123
parser.add_argument("-w", "--builder-dir", metavar="BUILDER_DIR",
119124
help="builder directory, which is the directory contains source and build directories")
120-
parser.add_argument("-s", "--src-dir", metavar="SRC_DIR", required=True, help="source directory")
121-
parser.add_argument("-o", "--obj-dir", metavar="OBJ_DIR", required=True, help="build directory")
125+
parser.add_argument("-s", "--src-dir", metavar="SRC_DIR", help="source directory (autodetected by default)")
126+
parser.add_argument("-o", "--obj-dir", metavar="OBJ_DIR", help="build directory. (<src>/build by default)")
122127
parser.add_argument("-t", "--build-type",
123-
metavar="BUILD_TYPE", required=True, help="build type, debug or release")
128+
metavar="BUILD_TYPE", default="Release", help="build type: Debug, Release")
124129
parser.add_argument("--cuda", action='store_true', help="switch from OpenCL to CUDA")
125130
parser.add_argument("--no-assertions", action='store_true', help="build without assertions")
126131
parser.add_argument("--docs", action='store_true', help="build Doxygen documentation")
127132
parser.add_argument("--system-ocl", action='store_true', help="use OpenCL deps from system (no download)")
128133
parser.add_argument("--no-werror", action='store_true', help="Don't treat warnings as errors")
129134
parser.add_argument("--shared-libs", action='store_true', help="Build shared libraries")
130135
parser.add_argument("--cmake-opt", action='append', help="Additional CMake option not configured via script parameters")
136+
parser.add_argument("--cmake-gen", default="Ninja", help="CMake generator")
131137

132138
args = parser.parse_args()
133139

sycl/doc/GetStartedGuide.md

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -79,15 +79,15 @@ variables is in these files.
7979
**Linux**
8080

8181
```bash
82-
python $DPCPP_HOME/llvm/buildbot/configure.py -s $DPCPP_HOME/llvm -o $DPCPP_HOME/build -t release
83-
python $DPCPP_HOME/llvm/buildbot/compile.py -s $DPCPP_HOME/llvm -o $DPCPP_HOME/build
82+
python $DPCPP_HOME/llvm/buildbot/configure.py
83+
python $DPCPP_HOME/llvm/buildbot/compile.py
8484
```
8585

8686
**Windows**
8787

8888
```bat
89-
python %DPCPP_HOME%\llvm\buildbot\configure.py -s %DPCPP_HOME%\llvm -o %DPCPP_HOME%\build -t release
90-
python %DPCPP_HOME%\llvm\buildbot\compile.py -s %DPCPP_HOME%\llvm -o %DPCPP_HOME%\build
89+
python %DPCPP_HOME%\llvm\buildbot\configure.py
90+
python %DPCPP_HOME%\llvm\buildbot\compile.py
9191
```
9292

9393
**Options**
@@ -99,6 +99,8 @@ You can use the following flags with `configure.py`:
9999
* `--cuda` -> use the cuda backend (see [Nvidia CUDA](#build-dpc-toolchain-with-support-for-nvidia-cuda))
100100
* `--shared-libs` -> Build shared libraries
101101
* `-t` -> Build type (debug or release)
102+
* `-o` -> Path to build directory
103+
* `--cmake-gen` -> Set build system type (e.g. `--cmake-gen "Unix Makefiles"`)
102104

103105
Ahead-of-time compilation for the Intel&reg; processors is enabled by default.
104106
For more, see [opencl-aot documentation](../../opencl-aot/README.md).
@@ -260,9 +262,15 @@ c:\oclcpu_rt_<cpu_version>\install.bat c:\tbb_<tbb_version>\tbb\bin\intel64\vc14
260262

261263
To verify that built DPC++ toolchain is working correctly, run:
262264

263-
**Linux/Windows (64-bit)**
265+
**Linux**
264266
```bash
265-
ninja check-all
267+
python $DPCPP_HOME/llvm/buildbot/check.py
268+
```
269+
270+
**Windows**
271+
272+
```bat
273+
python %DPCPP_HOME%\llvm\buildbot\check.py
266274
```
267275

268276
If no OpenCL GPU/CPU runtimes are available, the corresponding tests are

0 commit comments

Comments
 (0)