forked from wled/WLED
-
-
Notifications
You must be signed in to change notification settings - Fork 133
Expand file tree
/
Copy pathoutput_bins.py
More file actions
191 lines (159 loc) · 6.82 KB
/
output_bins.py
File metadata and controls
191 lines (159 loc) · 6.82 KB
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
Import('env')
import os
import shutil
import gzip
OUTPUT_DIR = "build_output{}".format(os.path.sep)
def _get_cpp_define_value(env, define):
define_list = [item[-1] for item in env["CPPDEFINES"] if item[0] == define]
if define_list:
return define_list[0]
return None
def _create_dirs(dirs=["firmware", "map"]):
# check if output directories exist and create if necessary
if not os.path.isdir(OUTPUT_DIR):
os.mkdir(OUTPUT_DIR)
for d in dirs:
if not os.path.isdir("{}{}".format(OUTPUT_DIR, d)):
os.mkdir("{}{}".format(OUTPUT_DIR, d))
# trick for py2/3 compatibility
if 'basestring' not in globals():
basestring = str
# WLEDMM : custom print function
def print_my_item(items, flag = False):
if flag: print(" -D", end='')
else: print(" ", end='')
if isinstance(items, basestring):
# print a single string
print(items, end='')
else:
# print a list
first = True
for item in items:
if not first: print("=", end='')
print(item, end='')
first = False
# WLEDMM : dump out buildflags : usermods, disable, enable, use_..
def wledmm_print_build_info(env):
# get all defines, duplicates are removed
all_flags = list(dict.fromkeys(
tuple(i) if isinstance(i, (list, tuple)) else i
for i in env["CPPDEFINES"]
))
first = True
found = False
for item in all_flags:
if 'WLED_RELEASE_NAME' in item[0] or 'WLED_VERSION' in item[0] or 'ARDUINO_USB_CDC_ON_BOOT' in item[0] or 'ARDUINO_USB_MODE' in item[0] or 'CORE' in item[0] or 'BOARD_HAS' in item:
if first: print("\nUsermods and Features:")
print_my_item(item)
first = False
found = True
if found: print("")
found = False
for item in all_flags:
if 'USERMOD_' in item or 'UM_' in item:
if first: print("\nUsermods and Features:")
print_my_item(item)
first = False
found = True
if found: print("")
found = False
for item in all_flags:
if 'WLED_DISABLE' in item or 'WLED_DISABLE' in item[0] or 'WIFI_' in item:
if first: print("\nUsermods and Features:")
print_my_item(item)
first = False
found = True
if found: print("")
found = False
for item in all_flags:
if 'WLED_' in item or 'WLED_' in item[0] or 'MAX_LED' in item[0] or 'JSON_' in item[0] or '_SEGMENT' in item[0] or '_HEAP' in item[0]:
if not 'WLED_RELEASE_NAME' in item[0] and not 'WLED_VERSION' in item[0] and not 'WLED_WATCHDOG_TIMEOUT' in item[0] and not 'WLED_DISABLE' in item and not 'WLED_USE_MY_CONFIG' in item and not 'ARDUINO_PARTITION' in item:
if first: print("\nUsermods and Features:")
print_my_item(item)
first = False
found = True
if found: print("")
first = True
found = False
for item in all_flags:
if 'WLEDMM_' in item[0] or 'WLEDMM_' in item or 'TROYHACKS' in item:
if first: print("WLEDMM Features:")
print_my_item(item)
first = False
found = True
if found: print("")
first = True
for item in all_flags:
if 'PIN' in item[0] or 'PIN' in item or 'DMTYPE' in item[0] or 'STATUSLED' in item[0]:
if first: print("Default PINs:")
print_my_item(item)
first = False
found = True
print("\n")
def wledmm_print_all_defines(env):
all_flags = env["CPPDEFINES"]
found = False
for item in all_flags:
if not found: print("\nBuild Flags:")
print_my_item(item, True)
found = True
if found: print("\n")
def bin_rename_copy(source, target, env):
_create_dirs()
variant = env["PIOENV"]
builddir = os.path.join(env["PROJECT_BUILD_DIR"], variant)
source_map = os.path.join(builddir, env["PROGNAME"] + ".map")
# create string with location and file names based on variant
map_file = "{}map{}{}.map".format(OUTPUT_DIR, os.path.sep, variant)
bin_file = "{}firmware{}{}.bin".format(OUTPUT_DIR, os.path.sep, variant)
release_name = _get_cpp_define_value(env, "WLED_RELEASE_NAME")
if release_name:
_create_dirs(["release"])
version = _get_cpp_define_value(env, "WLED_VERSION")
release_file = "{}release{}WLEDMM_{}_{}.bin".format(OUTPUT_DIR, os.path.sep, version, release_name) #WLEDMM: add MM postfix to WLED
shutil.copy(str(target[0]), release_file)
# check if new target files exist and remove if necessary
for f in [map_file, bin_file]:
if os.path.isfile(f):
os.remove(f)
# copy firmware.bin to firmware/<variant>.bin
shutil.copy(str(target[0]), bin_file)
# copy firmware.map to map/<variant>.map
if os.path.isfile("firmware.map"):
print("Found linker mapfile firmware.map")
shutil.copy("firmware.map", map_file)
if os.path.isfile(source_map):
print(f"Found linker mapfile {source_map}")
shutil.copy(source_map, map_file)
# Copy boot_app0.bin to the build dir if available.
# Use the PlatformIO platform API to locate the exact arduino-esp32 framework package used
# for this build. ESP8266 builds return None from get_package_dir() and are silently skipped.
# Old arduino-esp32 1.0.x builds lack the file under tools/partitions/ and are also skipped.
_ARDUINO_ESP32_PACKAGE = "framework-arduinoespressif32"
try:
framework_dir = env.PioPlatform().get_package_dir(_ARDUINO_ESP32_PACKAGE)
if framework_dir:
boot_app0_src = os.path.join(str(framework_dir), "tools", "partitions", "boot_app0.bin")
if os.path.isfile(boot_app0_src):
shutil.copy(boot_app0_src, os.path.join(builddir, "boot_app0.bin"))
except Exception as e:
print(f"Warning: could not copy boot_app0.bin ({e})")
# Check if this is a release build (CI sets WLED_RELEASE=True)
is_release_build = os.environ.get('WLED_RELEASE', '').lower() in ('true', '1', 'yes')
# show build flags summary for github CI builds
if is_release_build:
# wledmm_print_all_defines(env)
wledmm_print_build_info(env)
def bin_gzip(source, target, env):
_create_dirs()
variant = env["PIOENV"]
# create string with location and file names based on variant
bin_file = "{}firmware{}{}.bin".format(OUTPUT_DIR, os.path.sep, variant)
gzip_file = "{}firmware{}{}.bin.gz".format(OUTPUT_DIR, os.path.sep, variant)
# check if new target files exist and remove if necessary
if os.path.isfile(gzip_file): os.remove(gzip_file)
# write gzip firmware file
with open(bin_file,"rb") as fp:
with gzip.open(gzip_file, "wb", compresslevel = 9) as f:
shutil.copyfileobj(fp, f)
env.AddPostAction("$BUILD_DIR/${PROGNAME}.bin", [bin_rename_copy, bin_gzip])