-
Notifications
You must be signed in to change notification settings - Fork 0
/
builder.py
273 lines (230 loc) · 9.24 KB
/
builder.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
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
# ***************************************************************************
# * Copyright (c) 2015-2023 by Pierre-Henri WUILLEMIN *
# * {prenom.nom}_at_lip6.fr *
# * *
# * "act" is free software; you can redistribute it and/or modify *
# * it under the terms of the GNU General Public License as published by *
# * the Free Software Foundation; either version 2 of the License, or *
# * (at your option) any later version. *
# * *
# * This program is distributed in the hope that it will be useful, *
# * but WITHOUT ANY WARRANTY; without even the implied warranty of *
# * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
# * GNU General Public License for more details. *
# * *
# * You should have received a copy of the GNU General Public License *
# * along with this program; if not, write to the *
# * Free Software Foundation, Inc., *
# * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
# **************************************************************************
import platform
import multiprocessing
import os
from .configuration import cfg
from .multijobs import execCde
from .utils import trace, setifyString, critic, notif
def getCmake(current: dict[str, str], target: str) -> str:
line = cfg.cmake + " ../../.." # we are in build/[release|target]
line += " -DCMAKE_EXPORT_COMPILE_COMMANDS=ON " # for clang-tidy
if current["mode"] == "release":
line += " -DCMAKE_BUILD_TYPE=RELEASE"
else:
line += " -DCMAKE_BUILD_TYPE=DEBUG"
if current["withSQL"]:
line += " -DUSE_NANODBC=ON"
else:
line += " -DUSE_NANODBC=OFF"
line += " -DCMAKE_INSTALL_PREFIX=" + '"' + current["destination"] + '"'
if current["verbose"]:
line += " -DCMAKE_VERBOSE_MAKEFILE=ON"
else:
line += " -DCMAKE_VERBOSE_MAKEFILE=OFF"
if current["static_lib"]:
line += " -DBUILD_SHARED_LIBS=OFF"
else:
line += " -DBUILD_SHARED_LIBS=ON"
if current["coverage"]:
line += " -DGUM_COVERAGE=ON"
else:
line += " -DGUM_COVERAGE=OFF"
line += " -DBUILD_ALL=OFF"
for module in setifyString(current["modules"]):
line += " -DBUILD_" + module + "=ON"
if current["fixed_seed"]:
line += " -DGUM_RANDOMSEED=" + cfg.fixedSeedValue
else:
line += " -DGUM_RANDOMSEED=0"
if target != "pyAgrum":
line += " -DBUILD_PYTHON=OFF"
else:
line += " -DBUILD_PYTHON=ON"
line += f' -DPython_EXECUTABLE="{current["python3target"]}"'
if platform.system() == "Windows":
if current["compiler"] in ['clang', 'gcc']:
critic(f"{current['compiler']} forbidden : clang or gcc only configured for linux system.")
else:
if current["compiler"] not in ['clang', 'gcc']:
critic(f"{current['compiler']} forbidden : clang or gcc only for linux system.")
if current["compiler"] == "mvsc22":
line += ' -G "Visual Studio 17 2022" -A x64'
elif current["compiler"] == "mvsc22_32":
line += ' -G "Visual Studio 17 2022" -A Win32'
elif current["compiler"] == "mvsc19":
line += ' -G "Visual Studio 16 2019" -A x64'
elif current["compiler"] == "mvsc19_32":
line += ' -G "Visual Studio 16 2019" -A Win32'
elif current["compiler"] == "mvsc17":
line += ' -G "Visual Studio 15 2017 Win64"'
elif current["compiler"] == "mvsc17_32":
line += ' -G "Visual Studio 15 2017"'
elif current["compiler"] == "mvsc15":
line += ' -G "Visual Studio 14 2015 Win64"'
elif current["compiler"] == "mvsc15_32":
line += ' -G "Visual Studio 14 2015"'
elif current["compiler"] == "mingw64":
line += ' -G "MinGW Makefiles"'
elif current["compiler"] == "clang":
if current['clangpath'] != "":
clangp = os.path.join(current['clangpath'], "clang")
else:
clangp = "clang"
line += f' -DCMAKE_C_COMPILER={clangp} -DCMAKE_CXX_COMPILER={clangp}++'
else: # gcc
if current['gccpath'] != "":
gccp = os.path.join(current['gccpath'], "g")
else:
gccp = "g"
line += f' -DCMAKE_C_COMPILER={gccp}cc -DCMAKE_CXX_COMPILER={gccp}++'
if current["threads"] == 'omp':
line += " -DCMAKE_GUM_THREADS=omp"
else:
line += " -DCMAKE_GUM_THREADS=stl"
if current["profiling"]:
line += " -DUSE_PROFILE=ON"
else:
line += " -DUSE_PROFILE=OFF"
return line
def buildCmake(current: dict[str, str], target: str):
line = getCmake(current, target)
execFromLine(current, line)
def getMake(current: dict[str, str], target: str):
if platform.system() == "Windows" and current["compiler"] != "mingw64":
return getForMsBuildSystem(current, target)
else:
return getForMakeSystem(current, target)
def getNbrOfJobs(jobrequest: str) -> str:
# number of jobs
nbrProc = multiprocessing.cpu_count()
if nbrProc == 1:
return "1"
else:
if jobrequest == "except1":
return str(nbrProc - 1)
elif jobrequest == "half":
return str(int(nbrProc / 2)) # >=1
elif jobrequest == "halfexcept1":
if nbrProc <= 3:
return "1"
else:
return str(int(nbrProc / 2) - 1)
elif jobrequest == "all":
return str(nbrProc)
else:
try:
nbrJob = int(jobrequest)
if nbrJob < 1:
nbrJob = 1
if nbrJob > nbrProc:
return str(nbrProc)
else:
return str(nbrJob)
except ValueError:
notif(f"Option '-j {jobrequest}' is invalid. Using '-j halfexcept1'.")
return getNbrOfJobs("halfexcept1")
def getForMsBuildSystem(current: dict[str, str], target: str):
line = ""
if cfg.msbuild is None:
critic("MsBuild not found")
else:
nbrJobs = getNbrOfJobs(current['jobs'])
notif("Compilation using [" + nbrJobs + "] jobs.")
if current["action"] == "test":
if target == "aGrUM":
line = cfg.msbuild + ' agrum.sln /t:gumTest /p:Configuration="Release"'
elif target == "pyAgrum":
line = cfg.msbuild + ' agrum.sln /t:_pyAgrum /p:Configuration="Release"'
else: # if target!= "pyAgrum":
critic(f"Action '{current['action']}' not treated for target '{target}' for now in compiler strange world.")
elif current["action"] == "install":
line = cfg.msbuild + ' INSTALL.vcxproj /p:Configuration="Release"'
elif current["action"] == "lib":
line = cfg.msbuild + ' INSTALL.vcxproj /p:Configuration="Release"'
else:
critic(f"Action '{current['action']}' not treated for target '{target}' for now in compiler weird world.")
line += ' /p:BuildInParallel=true /maxcpucount:' + nbrJobs
return line
def getForMakeSystem(current: dict[str, str], target: str) -> str:
line = cfg.make
nbrJobs = str(getNbrOfJobs(current['jobs']))
notif("Compilation using [" + nbrJobs + "] jobs.")
if current["action"] == "test":
if target == "aGrUM":
line += " gumTest"
elif target != "pyAgrum":
critic("Action '" + current["action"] +
"' not treated for target '" + target + "'.")
elif current["action"] == "install":
line += " install"
elif current["action"] == "uninstall":
line += " uninstall"
elif current["action"] == "lib":
pass # nothing to do
elif current["action"] == "doc":
line += " doc"
else:
critic("Action '" + current["action"] + "' not treated for now")
line += " -j " + nbrJobs
if target == "pyAgrum":
line += " -C wrappers/pyAgrum"
return line
def buildMake(current: dict[str, str], target: str):
line = getMake(current, target)
execFromLine(current, line)
def getPost(current: dict[str, str], target: str) -> tuple[str, bool]:
if current["action"] == "test":
if target == "aGrUM":
if cfg.os_platform == "win32":
if current["compiler"] == "mingw64":
line = "src\\gumTest.exe"
else:
line = "src\\Release\\gumTest.exe" # debug or release create Release folder
else:
line = "src/gumTest"
return line, True
elif target == "pyAgrum":
gumTest = ""
# quick_specifictest
if current['tests'].startswith('quick'):
gumTest = "gumTest.py " + current['tests']
elif current['tests'] == 'all': # all is with NOTEBOOKStest
gumTest = "gumTest.py all"
else:
critic(f"Only [-t all] or [-t quick] for testing pyAgrum (instead of [{current['tests']}])")
if cfg.os_platform == "win32":
line = r'copy /Y "wrappers\pyAgrum\Release\_pyAgrum.pyd" "wrappers\pyAgrum\." & ' + \
cfg.python + " ..\\..\\..\\wrappers\\pyAgrum\\testunits\\" + gumTest
else:
line = f"{cfg.python} ../../../wrappers/pyAgrum/testunits/{gumTest}"
line += " " + current['mode']
return line, True
return "", False
def buildPost(current: dict[str, str], target: str):
line, checkRC = getPost(current, target)
if line != "":
execFromLine(current, line, checkRC)
def execFromLine(current: dict[str, str], line: str, checkRC: bool = True):
trace(current, line)
if not current['dry_run']:
rc = execCde(line, current)
if checkRC and rc > 0:
critic(f"Received error {rc}", rc=rc)