IoT - Modular - Post-Compile.py
Jump to navigation
Jump to search
1 #
2 # For some strange reason, if the FinalBIN file does not exist yet,
3 # You have to do a "Clean" before "Build" or it doesn't get copied...
4 #
5 # If the file exists, it gets updated...
6 #
7 # This is rather odd...
8 #
9
10 print(">---------- POST Compile Script BEGIN ----------<")
11
12 Import("env", "projenv")
13 from shutil import copyfile
14
15 # Dump construction environments (for debug purpose)
16 # print(env.Dump())
17 # print(projenv.Dump())
18
19 # access to global construction environment
20 # print(env)
21
22 # print("=======")
23 # print("BUILD FLAGS: ")
24 # print(env.ParseFlags(env['BUILD_FLAGS']))
25 # print("=======")
26
27 # access to project construction environment
28 # print(projenv)
29
30
31 Foo1 = env['PROGNAME'] + ".bin"
32 Foo2 = env['PIOENV'] + ".bin"
33 # FinalBIN = "Binaries/" + env['PIOENV'] + ".bin"
34 FinalBIN = "Distribution/" + env['PIOENV'] + ".bin"
35
36 # print(Foo1, " --> ", Foo2, " ==> ", FinalBIN)
37 print(Foo1, " --> ", FinalBIN)
38
39 def Copy_Binary(*args, **kwargs):
40 print("Copying binary to distribution directory...", FinalBIN)
41 target = str(kwargs['target'][0])
42 copyfile(target, FinalBIN)
43 print("Done.")
44
45 env.AddPostAction("$BUILD_DIR/${PROGNAME}.bin", Copy_Binary) #post action for .hex
46
47 print(">---------- POST Compile Script END ----------<")