-
Notifications
You must be signed in to change notification settings - Fork 9
/
post-build-script.py
executable file
·108 lines (84 loc) · 2.81 KB
/
post-build-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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
# For more information look here
# https://docs.platformio.org/en/latest/projectconf/advanced_scripting.html
#
Import("env", "projenv")
import os
from subprocess import Popen, PIPE
# access to global build environment
# print(env.Dump())
# access to project build environment (is used source files in "src" folder)
# print(projenv.Dump())
# Show sizes
env.AddPostAction(
"$BUILD_DIR/${PROGNAME}.elf",
env.VerboseAction(" ".join([
"avr-size", "$BUILD_DIR/${PROGNAME}.elf"
]), "\nBuilt $BUILD_DIR/${PROGNAME}.hex")
)
# Make listing
env.AddPostAction(
"$BUILD_DIR/${PROGNAME}.elf",
env.VerboseAction(" ".join([
"avr-objdump -d -S ", "$BUILD_DIR/${PROGNAME}.elf",
" > ", "${PROGNAME}.lst"
]), "Generate listing file ${PROGNAME}.lst")
)
# format sources
p = Popen('clang-format -version',shell = True, stderr = PIPE, stdout = PIPE)
output,error = p.communicate()
if len(error) == 0:
env.AddPostAction(
"$BUILD_DIR/${PROGNAME}.elf",
env.VerboseAction(" ".join([
"clang-format -i ",
# " --verbose ",
"${PROJECT_SRC_DIR}/*.cpp",
"${PROJECT_SRC_DIR}/*.h",
"${PROJECT_SRC_DIR}/*.ino",
]), "Format sources in ${PROJECT_SRC_DIR}\n")
)
#
# Dump build environment (for debug purpose)
# print(env.Dump())
#
#
# Change build flags in runtime
#
# env.ProcessUnFlags("-DVECT_TAB_ADDR")
# env.Append(CPPDEFINES=("VECT_TAB_ADDR", 0x123456789))
#
# Upload actions
#
# def before_upload(source, target, env):
# print("before_upload")
# # do some actions
# # call Node.JS or other script
# env.Execute("node --version")
# def after_upload(source, target, env):
# print("after_upload")
# # do some actions
# print("Current build targets", map(str, BUILD_TARGETS))
# env.AddPreAction("upload", before_upload)
# env.AddPostAction("upload", after_upload)
#
# Custom actions when building program/firmware
#
# env.AddPreAction("buildprog", callback...)
# env.AddPostAction("buildprog", callback...)
#
# Custom actions for specific files/objects
#
# env.AddPreAction("$BUILD_DIR/${PROGNAME}.elf", [callback1, callback2,...])
# env.AddPostAction("$BUILD_DIR/${PROGNAME}.hex", callback...)
# custom action before building SPIFFS image. For example, compress HTML, etc.
# env.AddPreAction("$BUILD_DIR/spiffs.bin", callback...)
# custom action for project's main.cpp
# env.AddPostAction("$BUILD_DIR/src/main.cpp.o", callback...)
# Custom HEX from ELF
# env.AddPostAction(
# "$BUILD_DIR/${PROGNAME}.elf",
# env.VerboseAction(" ".join([
# "$OBJCOPY", "-O", "ihex", "-R", ".eeprom",
# "$BUILD_DIR/${PROGNAME}.elf", "$BUILD_DIR/${PROGNAME}.hex"
# ]), "Building $BUILD_DIR/${PROGNAME}.hex")
# )