forked from Open-Smartwatch/open-smartwatch-os
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprebuild_info.py
29 lines (26 loc) · 1.2 KB
/
prebuild_info.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
import subprocess
Import("env")
# Try to execute Git, if it failes we will just display the defaults below
gitAvailable = False
gitCommitHash = "???"
gitCommitTime = "???"
gitBranchName = "???"
try:
proc = subprocess.Popen(['git', '--version'], stdout=subprocess.PIPE)
proc.communicate()
gitAvailable = proc.returncode == 0
except:
pass
if gitAvailable:
gitCommitHash = subprocess.Popen(
['git', 'rev-parse', 'HEAD'], stdout=subprocess.PIPE).communicate()[0].decode('utf-8').strip()[:7] # Short hash
gitCommitTime = subprocess.Popen(
['git', 'log', '-1', '--pretty=format:%cd', '--date=format:%Y-%m-%dT%H:%M:%S%z'], stdout=subprocess.PIPE).communicate()[0].decode('utf-8').strip()
gitBranchName = subprocess.Popen(
['git', 'rev-parse', '--abbrev-ref', 'HEAD'], stdout=subprocess.PIPE).communicate()[0].decode('utf-8').strip()
env.Append(CPPDEFINES=[
# This will be expanded into a command line argument like '-DGIT_COMMIT_HASH="\"str\""', and thats the reason for the "strange" backslashing...
("GIT_COMMIT_HASH", "\\\"" + gitCommitHash + "\\\""),
("GIT_COMMIT_TIME", "\\\"" + gitCommitTime + "\\\""),
("GIT_BRANCH_NAME", "\\\"" + gitBranchName + "\\\"")
])