forked from chapel-lang/chapel
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsub_test
executable file
·134 lines (112 loc) · 4.04 KB
/
sub_test
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
#!/usr/bin/env python3
import os
import sys
import subprocess as sp
import shutil
# for each subdirectory in test/cmake, run the following
# mkdir -p build
# cmake -B build -S -DCMAKE_INSTALL_PREFIX=install -DCMAKE_BUILD_TYPE=Debug
# cmake --build build
# cmake --install build
# repeat for -DCMAKE_BUILD_TYPE=Release
class BuildDirContext:
def __init__(self, subdir):
self.subdir = subdir
self.build_dir = os.path.join(subdir, "build")
self.install_dir = os.path.join(subdir, "install")
def cleanup(self):
if os.path.exists(self.build_dir):
shutil.rmtree(self.build_dir)
if os.path.exists(self.install_dir):
shutil.rmtree(self.install_dir)
def __enter__(self):
self.cleanup()
os.makedirs(self.build_dir, exist_ok=True)
return self.build_dir, self.install_dir
def __exit__(self, exc_type, exc_value, traceback):
pass
def run_build(subdir, build_type):
print(f"[Working on {subdir} with {build_type}]")
chpl_home = os.environ.get("CHPL_HOME", None)
if chpl_home is None:
print("[Error: CHPL_HOME not set]")
return 1
cmake_dir = os.path.join(chpl_home, "util", "cmake")
env = os.environ.copy()
# FIXME: we have to do this since util/cmake isn't installed anywhere yet
# once thats fixed, we can remove this
env["CMAKE_PREFIX_PATH"] = cmake_dir
with BuildDirContext(subdir) as (build_dir, install_dir):
try:
print(f"[Configuring {subdir} with {build_type}]")
output = sp.check_output(
[
"cmake",
"-B",
build_dir,
"-S",
subdir,
"-DCMAKE_INSTALL_PREFIX={}".format(install_dir),
f"-DCMAKE_BUILD_TYPE={build_type}",
],
env=env,
encoding="utf-8",
stderr=sp.STDOUT,
)
print(output)
except sp.CalledProcessError as e:
print(f"[Error configuring {subdir} with {build_type}]")
print(e.output)
return 1
finally:
print(f"[Finished configuring {subdir} with {build_type}]")
try:
print(f"[Building {subdir} with {build_type}]")
output = sp.check_output(
["cmake", "--build", build_dir],
env=env,
encoding="utf-8",
stderr=sp.STDOUT,
)
print(output)
except sp.CalledProcessError as e:
print(f"[Error building {subdir} with {build_type}]")
print(e.output)
return 1
finally:
print(f"[Finished building {subdir} with {build_type}]")
if os.path.exists(os.path.join(subdir, "NOINSTALL")):
print(f"[Skipping install for {subdir} with {build_type}]")
else:
try:
print(f"[Installing {subdir} with {build_type}]")
output = sp.check_output(
["cmake", "--install", build_dir],
env=env,
encoding="utf-8",
stderr=sp.STDOUT,
)
print(output)
except sp.CalledProcessError as e:
print(f"[Error installing {subdir} with {build_type}]")
print(e.output)
return 1
finally:
print(f"[Finished installing {subdir} with {build_type}]")
print("[Success matching build process for {} with {}]".format(subdir, build_type))
return 0
def run_builds(d):
for subdir in os.listdir(d):
if not os.path.isdir(subdir):
continue
run_build(subdir, "Debug")
run_build(subdir, "Release")
run_build(subdir, "RelWithDebInfo")
run_build(subdir, "MinSizeRel")
def main():
print("[Starting subtest]")
d = os.path.dirname(os.path.abspath(__file__))
run_builds(d)
print("[Finished subtest {}]".format(d))
if __name__ == "__main__":
main()