forked from gereic/GXAirCom
-
Notifications
You must be signed in to change notification settings - Fork 0
/
extra_script.py
38 lines (35 loc) · 1.46 KB
/
extra_script.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
import os
Import("env", "projenv")
from shutil import copyfile
def get_build_flag_value(flag_name):
build_flags = env.ParseFlags(env['BUILD_FLAGS'])
flags_with_value_list = [build_flag for build_flag in build_flags.get('CPPDEFINES') if type(build_flag) == list]
defines = {k: v for (k, v) in flags_with_value_list}
return defines.get(flag_name)
def copy_file(*args, **kwargs):
print("Copying file output to project directory...")
version = get_build_flag_value("VERSION")
version = version[1:-1]
target = str(kwargs['target'][0])
savename = target.split(os.path.sep)[-1] # name of environment
platform = target.split(os.path.sep)[-2]
filename = target.split(os.path.sep)[-1]
print(target.split(os.path.sep)[-1])
print(target.split(os.path.sep)[-2])
print(target.split(os.path.sep)[-3])
print(version)
if filename == "firmware.bin":
savefile = 'bin/firmware_{}_{}.bin'.format(version,platform)
elif filename == "spiffs.bin":
savefile = 'bin/spiffs_{}.bin'.format(version)
else:
savefile = 'bin/{}'.format(filename)
print("******** copy file " + target + " to " + savefile + " *******")
copyfile(target, savefile)
f = open("bin/_version.txt", "w")
f.write(version)
f.close()
print("Done.")
env.AddPostAction("$BUILD_DIR/partitions.bin", copy_file)
env.AddPostAction("$BUILD_DIR/firmware.bin", copy_file)
env.AddPostAction("$BUILD_DIR/spiffs.bin", copy_file)