File: version-template.py

package info (click to toggle)
taisei 1.4.4%2Bdfsg-3
  • links: PTS
  • area: main
  • in suites: forky, sid
  • size: 345,704 kB
  • sloc: ansic: 136,835; cpp: 120,585; javascript: 4,343; asm: 4,083; python: 3,327; lisp: 1,043; xml: 371; sh: 367; makefile: 25
file content (50 lines) | stat: -rwxr-xr-x 1,363 bytes parent folder | download | duplicates (2)
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)