-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild_flags.py
43 lines (35 loc) · 1.03 KB
/
build_flags.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
import subprocess, os
Import("env")
def find_file_on_system_path(file):
paths = os.environ['PATH'].split(os.pathsep)
if not os.path.isfile(file):
for p in paths:
f = os.path.join(p, file)
if os.path.isfile(f):
return f
return None
else:
return file
# Re-run NanoPB generator if we've been told where it is
nanoPbPath = find_file_on_system_path("nanopb_generator.py")
if nanoPbPath is not None:
print("Running NanoPB Generator.")
os.chdir("src")
os.system("python " + nanoPbPath + " config/Config.proto")
os.chdir("../")
else:
print("NanoPB Generator not detected.")
# Calculate git revision
gitRevision = (
subprocess.check_output(["git", "rev-parse", "HEAD"])
.strip()
.decode("utf-8")
)
# Calculate build target include file
targetName = env.get("PIOENV")
env.Append(CPPDEFINES=[
("STRINGIFY2(X)", "#X"),
("STRINGIFY(X)", "STRINGIFY2(X)"),
("BUILD_GIT_REVISION", gitRevision),
("TARGET_NAME", targetName)
])