forked from KSU-MS/pio-git-hash-gen
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpio-git-hash-gen.py
51 lines (42 loc) · 1.73 KB
/
pio-git-hash-gen.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
44
45
46
47
48
49
50
51
import subprocess
Import("projenv")
def get_firmware_specifier_build_flag():
path = str(projenv["PROJECT_DIR"])
build_version = subprocess.run(
['git', '-C', path, 'rev-parse', '--short', 'HEAD'], stdout=subprocess.PIPE).stdout.decode('utf-8')
build_version.strip()
print("VERSION: " + (build_version))
return int(build_version, 16)
def get_project_main_or_master():
path = str(projenv["PROJECT_DIR"])
main_or_master = subprocess.run(
['git', '-C', path, 'rev-parse', '--abbrev-ref','HEAD'], stdout=subprocess.PIPE).stdout.decode('utf-8')
main_or_master.strip()
project_is_main_or_master = ('main' in main_or_master.lower()) or ('master' in main_or_master.lower())
project_is_testing = ('testing' in main_or_master.lower())
if project_is_main_or_master:
branch_enum = 1
elif project_is_testing:
branch_enum = 2
else:
branch_enum = 0
print("MAIN OR MASTER: " + (main_or_master) + "ENUM: " + str(branch_enum))
return int(branch_enum)
def get_project_is_dirty():
path = str(projenv["PROJECT_DIR"])
project_status = subprocess.run(
['git', '-C', path, 'status', '--porcelain'], stdout=subprocess.PIPE).stdout.decode('utf-8')
project_status.strip()
project_is_dirty = (project_status != '')
print("Project is dirty: " + str(project_is_dirty))
print("Project status: " + project_status)
return int(project_is_dirty)
fw_flag = get_firmware_specifier_build_flag()
project_is_dirty = get_project_is_dirty()
project_is_main_or_master = get_project_main_or_master()
projenv.Append(CPPDEFINES=[
("AUTO_VERSION", fw_flag),
("FW_PROJECT_IS_DIRTY", project_is_dirty),
("FW_PROJECT_IS_MAIN_OR_MASTER",project_is_main_or_master)
]
)