forked from UnifiedEngineering/T-962-improvements
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreate_version.py
More file actions
30 lines (28 loc) · 1.14 KB
/
create_version.py
File metadata and controls
30 lines (28 loc) · 1.14 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
import subprocess
import os
import traceback
import shutil
Import("env")
def create_version_c(*args, **kwargs):
print("Creating version.c file from git describe..")
# sanity check: was this downlaoded via git?
if not os.path.isdir(".git"):
print("Aborting creation of version.c since this project was not cloned via `git`...")
return
# sanity check: do we have git?
if shutil.which("git") is None:
print("Command `git` is not available, aborting creation of src/version.c..")
return
try:
git_tag_cmd = ["git", "describe", "--tag", "--always", "--dirty"]
git_tag = subprocess.check_output(git_tag_cmd).decode('utf-8').strip()
print("Got tag: %s" % git_tag)
file_content = 'const char* Version_GetGitVersion(void) { return "%s"; }' % git_tag
with open("src/version.c", 'w') as out_file:
out_file.write(file_content)
print("Writing version.c okay.")
except Exception as exc:
print("Exception during creation of version.c occured: %s" % str(exc))
print(traceback.format_exc())
os.remove("src/version.c")
create_version_c()