-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathextra_script.py
34 lines (26 loc) · 1.01 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
import os
from shutil import copyfile
Import("env")
pioEnv = env['PIOENV']
def copyFirmware(source, target, env):
print ( "------------------------------------------------------------------------------" )
buildFlags = env.ParseFlags(env['BUILD_FLAGS'])
cppDefines = buildFlags.get( "CPPDEFINES" )
appVersion = "0.0.0"
i = 0
while i < len(cppDefines):
if len(cppDefines[i]) == 2:
if "APP_VERSION" == cppDefines[i][0]:
appVersion = cppDefines[i][1]
l = len(appVersion)
appVersion = appVersion[1:l-1]
break
i += 1
firmwarePath = os.path.abspath(os.path.join( os.path.join( target[0].path, os.pardir), ( "firmware-%s.%s.bin" % ( appVersion, pioEnv ))))
print ( "PIOENV = " + pioEnv )
print ( "Firmware file:" )
print ( firmwarePath )
copyfile( target[0].path, firmwarePath )
print ( "size=%d bytes" % os.path.getsize( firmwarePath ))
env.AddPostAction( "$BUILD_DIR/firmware.bin", copyFirmware )
env.Append(CPPDEFINES=[("PIOENV", "\\\"" + env['PIOENV'] + "\\\"")])