forked from project64/angrylion-rdp
-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathmake_version.py
executable file
·43 lines (34 loc) · 1.2 KB
/
make_version.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
#!/usr/bin/env python3
import sys, os, subprocess
def system(cmd, default):
args = cmd.split()
try:
return subprocess.check_output(args).decode("ascii").strip()
except:
return default
if __name__ == "__main__":
branch = system("git rev-parse --abbrev-ref HEAD", "master")
hash = system("git show -s --format=%h", "0" * 40)
date = system("git show -s --format=%ci", "")[:10]
tag = system("git describe --dirty --always --tags", "")
# remove hash from git describe output
tag = tag.split("-")
if len(tag) > 2 and tag[2][1:] in hash:
del tag[2]
tag = "-".join(tag)
mappings = {
"GIT_BRANCH": branch,
"GIT_TAG": tag,
"GIT_COMMIT_HASH": hash,
"GIT_COMMIT_DATE": date,
}
base_path = os.path.dirname(sys.argv[0])
core_path = os.path.join(base_path, "src", "core")
in_path = os.path.join(core_path, "version.h.in")
out_path = os.path.join(core_path, "version.h")
with open(in_path, "r") as f:
version_str = f.read()
for mapping, value in mappings.items():
version_str = version_str.replace("@" + mapping + "@", value)
with open(out_path, "w") as f:
f.write(version_str)