Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/tools/build_config/dailyBuildMSVC.py
169674 views
1
#!/usr/bin/env python
2
# Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3
# Copyright (C) 2008-2025 German Aerospace Center (DLR) and others.
4
# This program and the accompanying materials are made available under the
5
# terms of the Eclipse Public License 2.0 which is available at
6
# https://www.eclipse.org/legal/epl-2.0/
7
# This Source Code may also be made available under the following Secondary
8
# Licenses when the conditions for such availability set forth in the Eclipse
9
# Public License 2.0 are satisfied: GNU General Public License, version 2
10
# or later which is available at
11
# https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
12
# SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
13
14
# @file dailyBuildMSVC.py
15
# @author Michael Behrisch
16
# @author Jakob Erdmann
17
# @author Laura Bieker
18
# @date 2008
19
20
"""
21
Does the nightly git pull on the windows server and the visual
22
studio build. The script is also used for the meso build.
23
Some paths especially for the names of the texttest output dirs are
24
hard coded into this script.
25
"""
26
from __future__ import absolute_import
27
from __future__ import print_function
28
import datetime
29
import os
30
import glob
31
import zipfile
32
import shutil
33
import sys
34
35
import buildWindowsSUMOWheel
36
import status
37
import wix
38
39
env = os.environ
40
if "SUMO_HOME" not in env:
41
env["SUMO_HOME"] = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
42
SUMO_HOME = env["SUMO_HOME"]
43
env["PYTHON"] = "python"
44
env["SMTP_SERVER"] = "smtprelay.dlr.de"
45
46
sys.path += [os.path.join(SUMO_HOME, "tools"), os.path.join(SUMO_HOME, "tests")]
47
import sumolib # noqa
48
import runExtraTests # noqa
49
50
try:
51
import matplotlib
52
MATPLOTLIB_CACHE = matplotlib.get_cachedir()
53
except ImportError:
54
MATPLOTLIB_CACHE = None
55
56
BINARIES = ("activitygen", "emissionsDrivingCycle", "emissionsMap",
57
"dfrouter", "duarouter", "jtrrouter", "marouter",
58
"netconvert", "netedit", "netgenerate",
59
"od2trips", "polyconvert", "sumo", "sumo-gui",
60
"TraCITestClient")
61
62
63
def repositoryUpdate(options):
64
gitrev = ""
65
cwd = os.getcwd()
66
for d in options.repositories.split(","):
67
os.chdir(os.path.join(options.rootDir, d))
68
status.log_subprocess(["git", "clean", "-f", "-x", "-d", "-q"])
69
status.log_subprocess(["git", "pull"])
70
status.log_subprocess(["git", "submodule", "update"])
71
if gitrev == "":
72
gitrev = sumolib.version.gitDescribe()
73
os.chdir(cwd)
74
return gitrev
75
76
77
def runTests(options, env, gitrev, debugSuffix=""):
78
if not options.tests:
79
return
80
prefix = env["FILEPREFIX"] + debugSuffix
81
env["SUMO_BATCH_RESULT"] = os.path.join(options.rootDir, prefix + "batch_result")
82
env["SUMO_REPORT"] = os.path.join(options.rootDir, prefix + "report")
83
env["TEXTTEST_TMP"] = os.path.join(options.rootDir, prefix + "tmp")
84
env["TEXTTEST_HOME"] = os.path.join(SUMO_HOME, "tests")
85
shutil.rmtree(env["TEXTTEST_TMP"], True)
86
if MATPLOTLIB_CACHE:
87
shutil.rmtree(MATPLOTLIB_CACHE, True)
88
if not os.path.exists(env["SUMO_REPORT"]):
89
os.makedirs(env["SUMO_REPORT"])
90
for name in BINARIES:
91
binary = os.path.join(SUMO_HOME, "bin", name + debugSuffix + ".exe")
92
if name == "sumo-gui":
93
if os.path.exists(binary):
94
env["GUISIM_BINARY"] = binary
95
elif os.path.exists(binary):
96
env[name.upper() + "_BINARY"] = binary
97
# provide more information than just the date:
98
fullOpt = ["-b", prefix, "-name", "%sr%s" %
99
(datetime.date.today().strftime("%d%b%y"), gitrev)]
100
ttBin = "texttest"
101
if options.suffix == "extra":
102
runExtraTests.run(debugSuffix, fullOpt, True, debugSuffix == "")
103
else:
104
status.log_subprocess([ttBin] + fullOpt, env)
105
status.log_subprocess([ttBin, "-a", "sumo.gui"] + fullOpt, env)
106
status.log_subprocess([ttBin, "-b", env["FILEPREFIX"], "-coll"], env)
107
shutil.copytree(env["SUMO_REPORT"], os.path.join(options.remoteDir, prefix + "report"), dirs_exist_ok=True)
108
status.killall((debugSuffix,), BINARIES)
109
110
111
def generateCMake(generator, platform, checkOptionalLibs, python):
112
buildDir = os.path.join(SUMO_HOME, "build", "cmake-build-" + platform)
113
cmakeOpt = ["-DCOMPILE_DEFINITIONS=MSVC_TEST_SERVER",
114
"-DCHECK_OPTIONAL_LIBS=%s" % checkOptionalLibs]
115
if python:
116
cmakeOpt += ["-DPYTHON_EXECUTABLE=%s" % python]
117
if checkOptionalLibs:
118
cmakeOpt += ["-DSUMO_UTILS=True"]
119
os.makedirs(buildDir)
120
status.printLog("Creating solution for %s." % generator)
121
status.log_subprocess(["cmake", "../..", "-G", generator, "-A", platform] + cmakeOpt, cwd=buildDir)
122
return buildDir
123
124
125
def main(options, platform="x64"):
126
env["FILEPREFIX"] = options.msvc_version + options.suffix + platform
127
prefix = os.path.join(options.rootDir, env["FILEPREFIX"])
128
makeLog = prefix + "Release.log"
129
makeAllLog = prefix + "Debug.log"
130
testLog = prefix + "Test.log"
131
testDebugLog = prefix + "DebugTest.log"
132
statusLog = prefix + "status.log"
133
log_handler = status.set_rotating_log(makeLog)
134
135
status.killall(("", "D"), BINARIES)
136
status.printLog("Running %s build using python %s." % (options.msvc_version, sys.version))
137
gitrev = repositoryUpdate(options)
138
generator = "Visual Studio " + ("12 2013" if options.msvc_version == "msvc12" else "16 2019")
139
buildDir = generateCMake(generator, platform, options.suffix == "extra", options.python)
140
ret = status.log_subprocess(["cmake", "--build", ".", "--config", "Release"], cwd=buildDir)
141
status.log_subprocess(["cmake", "--build", ".", "--config", "Release", "--target", "lisum"], cwd=buildDir)
142
status.log_subprocess(["cmake", "--build", ".", "--config", "Release", "--target", "userdoc", "examples"],
143
cwd=buildDir)
144
status.log_subprocess(["cmake", "--install", "."], cwd=buildDir)
145
plat = platform.lower().replace("x", "win")
146
if options.msvc_version != "msvc16":
147
plat += options.msvc_version
148
for d in glob.glob(os.path.join(buildDir, "sumo-*")):
149
if os.path.isdir(d):
150
installDir = d
151
installBase = os.path.basename(installDir)
152
binaryZip = os.path.join(buildDir, "sumo-%s%s-%s" % (plat, options.suffix, installBase[5:]))
153
if ret == 0:
154
try:
155
for f in (glob.glob(os.path.join(SUMO_HOME, "*.md")) +
156
[os.path.join(SUMO_HOME, n) for n in ("AUTHORS", "ChangeLog", "CITATION.cff", "LICENSE")]):
157
shutil.copy(f, installDir)
158
if options.suffix == "extra":
159
shutil.copy(os.path.join(SUMO_HOME, "build_config", "wix", "gpl-2.0.txt"),
160
os.path.join(installDir, "LICENSE"))
161
for f in glob.glob(os.path.join(SUMO_HOME, "bin", "*.jar")):
162
shutil.copy(f, os.path.join(installDir, "bin"))
163
for f in glob.glob(os.path.join(SUMO_HOME, "bin", "*-sources.zip")):
164
shutil.unpack_archive(f, os.path.join(installDir, "include"))
165
if options.suffix == "extra" and os.path.exists(os.path.join(options.remoteDir, "cadyts.jar")):
166
shutil.copy(os.path.join(options.remoteDir, "cadyts.jar"), os.path.join(installDir, "bin"))
167
shutil.copytree(os.path.join(SUMO_HOME, "docs"), os.path.join(installDir, "docs"),
168
ignore=shutil.ignore_patterns('web'))
169
for lib in ("libsumo", "libtraci"):
170
shutil.rmtree(os.path.join(installDir, "tools", lib), ignore_errors=True)
171
shutil.copy(os.path.join(buildDir, "src", "version.h"), os.path.join(installDir, "include"))
172
status.printLog("Creating sumo.zip.")
173
shutil.make_archive(binaryZip, 'zip', buildDir, installBase)
174
shutil.copy(binaryZip + ".zip", options.remoteDir)
175
status.printLog("Creating sumo.msi.")
176
if options.suffix == "extra":
177
wix.buildMSI(binaryZip + ".zip", binaryZip + ".msi",
178
license_path=os.path.join(SUMO_HOME, "build_config", "wix", "gpl-2.0.rtf"))
179
else:
180
wix.buildMSI(binaryZip + ".zip", binaryZip + ".msi")
181
shutil.copy(binaryZip + ".msi", options.remoteDir)
182
except Exception as ziperr:
183
status.printLog("Warning: Could not zip to %s.zip (%s)!" % (binaryZip, ziperr))
184
185
gameZip = os.path.join(buildDir, "sumo-game-%s%s-%s.zip" % (plat, options.suffix, installBase[5:]))
186
status.printLog("Creating sumo-game.zip.")
187
try:
188
status.log_subprocess(["cmake", "--build", ".", "--target", "game"], cwd=buildDir)
189
shutil.move(os.path.join(buildDir, "sumo-game.zip"), gameZip)
190
shutil.copy(gameZip, options.remoteDir)
191
except Exception as e:
192
status.printLog("Warning: Could not create nightly sumo-game.zip! (%s)" % e)
193
194
if options.suffix == "extra":
195
try:
196
buildWindowsSUMOWheel.main()
197
f = glob.glob(os.path.join(SUMO_HOME, "dist", "eclipse_sumo-*"))[0]
198
shutil.copy(f, os.path.join(options.remoteDir, "wheels"))
199
except Exception as e:
200
status.printLog("Warning: Could not create nightly sumo wheel! (%s)" % e)
201
202
debug_handler = status.set_rotating_log(makeAllLog, log_handler)
203
ret = status.log_subprocess(["cmake", "--build", ".", "--config", "Debug"], cwd=buildDir)
204
if ret == 0:
205
debugZip = os.path.join(buildDir, "sumo-%s%sDebug-%s.zip" % (plat, options.suffix, installBase[5:]))
206
status.printLog("Creating sumoDebug.zip.")
207
try:
208
with zipfile.ZipFile(debugZip, 'w', zipfile.ZIP_DEFLATED) as zipf:
209
for ext in ("*D.exe", "*.dll", "*D.pdb"):
210
for f in glob.glob(os.path.join(SUMO_HOME, "bin", ext)):
211
zipf.write(f, os.path.join(installBase, "bin", os.path.basename(f)))
212
shutil.copy(debugZip, options.remoteDir)
213
except IOError as ziperr:
214
status.printLog("Warning: Could not zip to %s (%s)!" % (debugZip, ziperr))
215
216
log_handler = status.set_rotating_log(testLog, debug_handler)
217
status.printLog("Running tests.")
218
runTests(options, env, gitrev)
219
with open(statusLog, 'w') as log:
220
status.printStatus(makeLog, makeAllLog, env["SMTP_SERVER"], log, testLog=testLog)
221
for f in (makeLog, makeAllLog, statusLog, testLog):
222
shutil.copy(f, options.remoteDir)
223
if not options.x64only:
224
debug_handler = status.set_rotating_log(testDebugLog, log_handler)
225
status.printLog("Running debug tests.")
226
runTests(options, env, gitrev, "D")
227
with open(prefix + "Dstatus.log", 'w') as log:
228
status.printStatus(makeAllLog, testDebugLog, env["SMTP_SERVER"], log, testLog=testDebugLog)
229
for f in (testDebugLog, log.name):
230
shutil.copy(f, options.remoteDir)
231
232
233
if __name__ == "__main__":
234
optParser = sumolib.options.ArgumentParser()
235
optParser.add_option("-r", "--root-dir", dest="rootDir",
236
default=r"D:\Sumo", help="root for git and log output")
237
optParser.add_option("-s", "--suffix", default="", help="suffix to the fileprefix")
238
optParser.add_option("-m", "--remote-dir", dest="remoteDir", default="S:\\daily",
239
help="directory to move the results to")
240
optParser.add_option("-n", "--no-tests", dest="tests", action="store_false",
241
default=True, help="skip tests")
242
optParser.add_option("-x", "--x64only", action="store_true",
243
default=False, help="skip debug build")
244
optParser.add_option("-p", "--python", help="path to python interpreter to use")
245
optParser.add_option("--msvc-version", default="msvc16",
246
help="Visual Studio version to use (either msvc12 or msvc16)")
247
optParser.add_option("-u", "--repositories", default="git",
248
help="repositories to update")
249
main(optParser.parse_args())
250
251