Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/tools/build_config/wix.py
169674 views
1
#!/usr/bin/env python
2
# Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3
# Copyright (C) 2011-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 wix.py
15
# @author Michael Behrisch
16
# @author Jakob Erdmann
17
# @date 2011
18
19
from __future__ import absolute_import
20
import os
21
import sys
22
import tempfile
23
import glob
24
import shutil
25
import zipfile
26
from os.path import abspath, basename, dirname, join
27
28
import version
29
import status
30
31
sys.path.append(dirname(dirname(abspath(__file__))))
32
import sumolib # noqa
33
34
SUMO_ROOT = abspath(join(dirname(__file__), '..', '..'))
35
SUMO_VERSION = version.get_pep440_version().replace("post", "")
36
INPUT_DEFAULT = r"S:\daily\sumo-win64-git.zip"
37
OUTPUT_DEFAULT = "sumo.msi"
38
WIX_DEFAULT = join(os.environ.get("WIX", r"C:\Program Files (x86)\WiX Toolset v3.11"), "bin")
39
WXS_DEFAULT = join(SUMO_ROOT, "build_config", "wix", "*.wxs")
40
LICENSE = join(SUMO_ROOT, "build_config", "wix", "License.rtf")
41
42
SKIP_FILES = ["osmWebWizard.py", "sumo-gui.exe",
43
"netedit.exe", "start-command-line.bat"]
44
45
46
def buildFragment(wix_bin, source_dir, target_label, tmp_dir):
47
base = basename(source_dir)
48
tmp_base = join(tmp_dir, base)
49
status.log_subprocess([join(wix_bin, "heat.exe"), "dir", source_dir,
50
"-cg", base, "-gg", "-dr", target_label, "-sreg",
51
"-out", tmp_base + "RawFragment.wxs"])
52
with open(tmp_base + "RawFragment.wxs") as frag_in, open(tmp_base + "Fragment.wxs", "w") as frag_out:
53
skip = 0
54
for fl in frag_in:
55
for s in SKIP_FILES:
56
if s in fl:
57
skip = 3
58
if skip == 0:
59
frag_out.write(fl.replace("SourceDir", source_dir))
60
else:
61
skip -= 1
62
return frag_out.name
63
64
65
def buildMSI(source_zip=INPUT_DEFAULT, out_file=OUTPUT_DEFAULT,
66
wix_bin=WIX_DEFAULT, wxs_pattern=WXS_DEFAULT,
67
license_path=LICENSE):
68
tmp_dir = tempfile.mkdtemp()
69
zipfile.ZipFile(source_zip).extractall(tmp_dir)
70
extracted_sumo = glob.glob(join(tmp_dir, "sumo-*"))[0]
71
fragments = [buildFragment(wix_bin, join(extracted_sumo, d), "INSTALLDIR", tmp_dir)
72
for d in ["bin", "data", "share", "include", "tools"]]
73
for d in ["userdoc", "pydoc", "javadoc", "tutorial", "examples"]:
74
doc_dir = join(extracted_sumo, "docs", d)
75
if os.path.exists(doc_dir):
76
fragments.append(buildFragment(wix_bin, doc_dir, "DOCDIR", tmp_dir))
77
for wxs in glob.glob(wxs_pattern):
78
with open(wxs) as wxs_in, open(join(tmp_dir, basename(wxs)), "w") as wxs_out:
79
data_dir = dirname(license_path)
80
wxs_out.write(wxs_in.read().format(version=SUMO_VERSION, license=license_path,
81
bindir=join(extracted_sumo, "bin"),
82
banner=join(data_dir, "bannrbmp.bmp"),
83
dialogbg=join(data_dir, "dlgbmp.bmp"),
84
webwizico=join(data_dir, "webWizard.ico")))
85
fragments.append(wxs_out.name)
86
status.log_subprocess([join(wix_bin, "candle.exe"), "-o", tmp_dir + "\\"] + fragments)
87
wix_obj = [f.replace(".wxs", ".wixobj") for f in fragments]
88
status.log_subprocess([join(wix_bin, "light.exe"), "-sw1076",
89
"-ext", "WixUIExtension", "-o", out_file] + wix_obj)
90
shutil.rmtree(tmp_dir, True) # comment this out when debugging
91
92
93
if __name__ == "__main__":
94
ap = sumolib.options.ArgumentParser()
95
ap.add_argument("-n", "--nightly-zip", default=INPUT_DEFAULT, help="full path to nightly zip")
96
ap.add_argument("-o", "--output", default=OUTPUT_DEFAULT, help="full path to output file")
97
ap.add_argument("-w", "--wix", default=WIX_DEFAULT, help="path to the wix binaries")
98
ap.add_argument("-x", "--wxs", default=WXS_DEFAULT, help="pattern for wxs templates")
99
ap.add_argument("-l", "--license", default=LICENSE, help="path to the license")
100
options = ap.parse_args()
101
buildMSI(options.nightly_zip, options.output, options.wix, options.wxs, options.license)
102
103