-
Notifications
You must be signed in to change notification settings - Fork 108
/
Copy pathversion-template.py
executable file
·50 lines (39 loc) · 1.33 KB
/
version-template.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
#!/usr/bin/env python3
import os
import sys
import version
assert(len(sys.argv) == 6)
root = sys.argv[1]
inpath = sys.argv[2]
outpath = sys.argv[3]
buildtype = sys.argv[4].strip()
v_fallback = sys.argv[5].strip()
version = version.get(fallback=v_fallback, rootdir=root)
if buildtype.lower().startswith("debug"):
buildtype_def = "#define DEBUG_BUILD"
else:
buildtype_def = "#define RELEASE_BUILD"
version = [("${TAISEI_VERSION_MAJOR}", version.major),
("${TAISEI_VERSION_MINOR}", version.minor),
("${TAISEI_VERSION_PATCH}", version.patch),
("${TAISEI_VERSION_TWEAK}", version.tweak),
("${TAISEI_VERSION}", version.string),
("${TAISEI_VERSION_FULL_STR}", version.full_string),
("${MESON_BUILD_TYPE}", buildtype),
("${ICONS_DIR}", os.path.join(root, "misc", "icons")),
("${BUILDTYPE_DEFINE}", buildtype_def)]
with open(inpath, "r") as infile:
template = infile.read()
for k, v in version:
template = template.replace(k, str(v))
try:
with open(outpath, "r+t") as outfile:
contents = outfile.read()
if contents == template:
exit(0)
outfile.seek(0)
outfile.write(template)
outfile.truncate()
except FileNotFoundError:
with open(outpath, "w") as outfile:
outfile.write(template)