-
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathversion.py
More file actions
31 lines (24 loc) · 1.2 KB
/
Copy pathversion.py
File metadata and controls
31 lines (24 loc) · 1.2 KB
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
import subprocess
def get_git_info():
try:
shortSHA = ( subprocess.check_output(["git", "rev-parse", "--short" , "HEAD"]).strip().decode("utf-8") )
branch = ( subprocess.check_output(["git", "rev-parse", "--abbrev-ref", "HEAD"]).strip().decode("utf-8") )
try:
tag = subprocess.check_output(["git", "describe", "--tags", "--exact-match"]).strip().decode("utf-8")
except subprocess.CalledProcessError:
tag = "untagged"
dirtyFlag = subprocess.call(["git", "diff-index", "--quiet", "HEAD", "--"]) != 0
return branch, shortSHA, tag, dirtyFlag
except Exception as e:
print(f"Error getting GIT info: {e}")
return "unknown", "unknown", "unknown", False
def generate_build_flags(env):
branch, shortSHA, tag, dirtyFlag = get_git_info()
dirty = "dirty" if dirtyFlag else "clean"
version_string = f"{tag} {shortSHA}-{dirty}"
env.Append(CPPDEFINES=[("VERSION_STRING", env.StringifyMacro(version_string))])
env.Append(CPPDEFINES=[("VERSION_BRANCH", env.StringifyMacro(branch))])
print(f"Version: {version_string}")
print(f"Branch: {branch}")
Import("env")
generate_build_flags(env)