-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup.py
executable file
·134 lines (106 loc) · 3.12 KB
/
setup.py
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 sys
import os
import shutil
import shlex
import subprocess
from contextlib import contextmanager
CONAN_PROFILE = "workflow"
@contextmanager
def cd(path):
current = os.getcwd()
try:
os.chdir(path)
yield
finally:
os.chdir(current)
def call(*args, stdout=subprocess.PIPE):
print(shlex.join(args))
proc = subprocess.run(args, stdout=stdout, check=True)
return proc.stdout.decode().strip() if stdout is not None else None
def conan(build_type):
call("conan", "profile", "new", "--detect", "--force", CONAN_PROFILE)
if sys.platform == "linux":
call(
"conan",
"profile",
"update",
"settings.compiler.libcxx=libstdc++11",
CONAN_PROFILE,
)
call(
"conan", "profile", "update", f"settings.build_type={build_type}", CONAN_PROFILE
)
call(
"conan",
"install",
"../..",
"--build",
"missing",
"-pr:b",
CONAN_PROFILE,
"-pr:h",
CONAN_PROFILE,
stdout=None,
)
if len(sys.argv) < 3:
print("setup.py <compiler> <build_type>[,<build_type>...]", file=sys.stderr)
sys.exit(1)
compilers = {
"gcc": ["linux"],
"clang": ["linux"],
"msvc": ["nt"],
}
normalized = {"clang++": "clang", "g++": "gcc"}
names = {"clang": ["clang", "clang++"], "gcc": ["gcc", "g++"]}
def normalize_compiler(compiler: str):
dirname = os.path.dirname(compiler)
filename = os.path.basename(compiler)
if sys.platform == "nt":
filename = os.path.splitext()[0]
chunks = filename.split("-", 1)
if len(chunks) == 1:
version = None
else:
version = chunks[1]
filename = chunks[0].lower()
try:
filename = normalized[filename]
except KeyError:
pass
try:
compiler_names = names[filename]
except:
compiler_names = [filename]
return filename, [
os.path.join(dirname, name if version is None else f"{name}-{version}")
for name in compiler_names
]
compiler_name, compilers_used = normalize_compiler(sys.argv[1])
BUILD_TYPE = sys.argv[2].split(",")
try:
if sys.platform not in compilers[compiler_name]:
print(
f"Cannot use {compiler_name} on {'windows' if sys.platform == 'nt' else sys.platform}",
file=sys.stderr,
)
sys.exit(1)
except KeyError:
print(f"Unknown compiler: {compiler_name}", file=sys.stderr)
sys.exit(1)
for var, value in zip(["CC", "CXX"], compilers_used):
os.environ[var] = value
shutil.rmtree("build/conan", ignore_errors=True)
os.makedirs("build/conan", exist_ok=True)
with cd("build/conan"):
print("cd build/conan")
for build_type in BUILD_TYPE:
build_type = build_type.strip()
conan(build_type)
print("cd ../..")
generator = "msbuild" if sys.platform == "nt" else "make"
for build_type in BUILD_TYPE:
build_type = build_type.strip().lower()
preset = f"{build_type}-{generator}"
call("cmake", "--preset", preset, stdout=None)
call("cmake", "--build", "--preset", build_type, "--parallel", stdout=None)