Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/tools/build_config/version.py
193871 views
1
#!/usr/bin/env python
2
# Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3
# Copyright (C) 2008-2026 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 version.py
15
# @author Michael Behrisch
16
# @author Daniel Krajzewicz
17
# @author Jakob Erdmann
18
# @date 2007
19
20
"""
21
This script rebuilds "<BUILD_DIR>/src/version.h", the file which
22
lets the applications know the version of their build.
23
It does this by parsing the output of git describe where the function is
24
implemented in sumolib.
25
If the version file is newer than the .git index file or the revision cannot be
26
determined any existing version.h is kept.
27
"""
28
from __future__ import absolute_import
29
from __future__ import print_function
30
31
import sys
32
from os.path import dirname, exists, getmtime, join, abspath
33
34
sys.path.append(dirname(dirname(abspath(__file__))))
35
import sumolib # noqa
36
37
38
SUMO_ROOT = abspath(join(dirname(__file__), '..', '..'))
39
40
41
def get_version(padZero=True):
42
return sumolib.version.gitDescribe(gitDir=join(SUMO_ROOT, ".git"), padZero=padZero)
43
44
45
def get_pep440_version():
46
v = get_version(padZero=False).replace("_", ".").replace("+", ".post")
47
if v.endswith("-" + (10 * "0")):
48
# this is a fake version number since we could only determine the last release number, see #14228
49
return v[:-11] + ".post0"
50
v = v[1:v.rfind("-")]
51
vs = v.split(".")
52
if len(vs) == 4 and vs[3] == "post0":
53
return v[:-6]
54
return v
55
56
57
def create_version_file(versionFile, revision):
58
with open(versionFile, 'w') as f:
59
print('#define VERSION_STRING "%s"' % revision, file=f)
60
61
62
def filter_pep440(input_name, output_name, plat=False):
63
with open(input_name) as inf:
64
inp = inf.read()
65
with open(output_name, "w") as outf:
66
if plat:
67
inp = inp.replace("wheel.platlib", "# wheel.platlib")
68
outf.write(inp.replace('0.0.0', get_pep440_version()))
69
70
71
def main():
72
if len(sys.argv) > 2:
73
if sys.argv[1] == "--pep440":
74
filter_pep440(sys.argv[2], sys.argv[3 if len(sys.argv) > 3 else 2])
75
if sys.argv[1] == "--pep440plat":
76
filter_pep440(sys.argv[2], sys.argv[3 if len(sys.argv) > 3 else 2], True)
77
return
78
# determine output file
79
if len(sys.argv) > 1:
80
versionDir = sys.argv[1]
81
if sys.argv[1] == "-":
82
sys.stdout.write(get_version())
83
return
84
else:
85
versionDir = join(SUMO_ROOT, "src")
86
versionFile = join(versionDir, 'version.h')
87
88
vcsFile = join(SUMO_ROOT, ".git", "index")
89
try:
90
if exists(vcsFile):
91
if not exists(versionFile) or getmtime(versionFile) < getmtime(vcsFile):
92
# vcsFile is newer. lets update the revision number
93
print('generating %s from revision in %s' % (versionFile, vcsFile))
94
create_version_file(versionFile, get_version())
95
else:
96
print("version control file '%s' not found" % vcsFile)
97
if not exists(versionFile):
98
print('trying to generate version file %s from existing header' % versionFile)
99
create_version_file(versionFile, sumolib.version.fromVersionHeader())
100
except Exception as e:
101
print("Error creating", versionFile, e)
102
try:
103
# try at least to create something
104
create_version_file(versionFile, "UNKNOWN")
105
except Exception as ee:
106
print("Error creating", versionFile, ee)
107
pass
108
109
110
if __name__ == "__main__":
111
main()
112
113