Repository navigation
Expand file tree
/
Copy pathcommon.sh
More file actions
executable file
·520 lines (422 loc) · 13.2 KB
/
Copy pathcommon.sh
File metadata and controls
executable file
·520 lines (422 loc) · 13.2 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
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
#!/usr/bin/env bash
set -u -e -E -o pipefail
cache_dir=$(mktemp -d)
trap 'trap_exit' EXIT
function trap_exit()
{
# workaround for macOS shipping with broken bash
local exit_code=$?
if [ -z "${ESP8266_ARDUINO_PRESERVE_CACHE-}" ]; then
rm -rf "$cache_dir"
fi
exit $exit_code
}
if [ "${CI-}" = "true" ] ; then
ci_group="::group::"
ci_end_group="::endgroup::"
ci_error="::error::"
else
ci_group="==> "
ci_end_group=""
ci_error=">>> "
fi
function step_summary()
{
local header=$1
local contents=$2
# ref. https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#adding-a-job-summary
if [ -n "${GITHUB_STEP_SUMMARY-}" ]; then
{ echo "# $header"; echo '```console'; cat "$contents"; echo '```'; } \
>> $GITHUB_STEP_SUMMARY
else
echo "# $header"
cat "$contents"
fi
}
function print_size_info_header()
{
printf "%-28s %-8s %-8s %-8s %-8s %-10s %-8s %-8s\n" sketch data rodata bss text irom0.text dram flash
}
function print_size_info()
{
local awk_script='
/^\.data/ || /^\.rodata/ || /^\.bss/ || /^\.text/ || /^\.irom0\.text/{
size[$1] = $2
}
END {
total_ram = size[".data"] + size[".rodata"] + size[".bss"]
total_flash = size[".data"] + size[".rodata"] + size[".text"] + size[".irom0.text"]
printf "%-28s %-8d %-8d %-8d %-8d %-10d %-8d %-8d\n",
sketch_name,
size[".data"], size[".rodata"], size[".bss"], size[".text"], size[".irom0.text"],
total_ram, total_flash
}
'
local size=$1
local elf_file=$2
local elf_name
elf_name=$(basename $elf_file)
$size --format=sysv "$elf_file" | \
awk -v sketch_name="${elf_name%.*}" "$awk_script" -
}
function print_sketch_info()
{
local build_mod=$1
local build_rem=$2
local testcnt=0
local cnt=0
for sketch in $ESP8266_ARDUINO_SKETCHES; do
testcnt=$(( ($testcnt + 1) % $build_mod ))
if [ $testcnt -ne $build_rem ]; then
continue # Not ours to do
fi
local skip
skip=$(skip_sketch "$sketch")
if [ -n "$skip" ]; then
continue # Should be skipped / cannot be built
fi
cnt=$(( $cnt + 1 ))
printf '%2d\t%s\n' "$cnt" "$sketch"
done
}
function format_fqbn()
{
local board_name=$1
local flash_size=$2
local lwip=$3
echo "esp8266com:esp8266:${board_name}:"\
"eesz=${flash_size},"\
"ip=${lwip}"
}
function build_sketches()
{
local core_path=$1
local cli_path=$2
local library_path=$3
local lwip=$4
local build_mod=$5
local build_rem=$6
local build_cnt=$7
local build_dir="$cache_dir"/build
mkdir -p "$build_dir"
local build_out="$cache_dir"/out
mkdir -p "$build_out"
local fqbn=$(format_fqbn "generic" "4M1M" "$lwip")
echo "FQBN: $fqbn"
local build_cmd
build_cmd+=${cli_path}
build_cmd+=" compile"\
" --warnings=all"\
" --build-path $build_dir"\
" --fqbn $fqbn"\
" --libraries $library_path"\
" --output-dir $build_out"
print_size_info_header >"$cache_dir"/size.log
local clean_core=1
local testcnt=0
local cnt=0
for sketch in $ESP8266_ARDUINO_SKETCHES; do
testcnt=$(( ($testcnt + 1) % $build_mod ))
if [ $testcnt -ne "$build_rem" ]; then
continue # Not ours to do
fi
local skip
skip=$(skip_sketch "$sketch")
if [ -n "$skip" ]; then
echo "$skip"
continue # Should be skipped / cannot be built
fi
cnt=$(( $cnt + 1 ))
if [ $build_cnt != 0 ] ; then
if [ $build_cnt != $cnt ] ; then
continue # Haven't reached the $cnt yet
fi
build_cnt=0
fi
# Do we need a clean core build? $build_dir/core/* cannot be shared
# between sketches when global options are present.
clean_core=$(arduino_mkbuildoptglobals_cleanup "$clean_core" "$build_dir" "$sketch")
# Clear out the last built sketch, map, elf, bin files, but leave the compiled
# objects in the core and libraries available for use so we don't need to rebuild
# them each sketch.
rm -rf "$build_dir"/sketch \
"$build_dir"/*.bin \
"$build_dir"/*.map \
"$build_dir"/*.elf
echo ${ci_group}Building $cnt $sketch
echo "$build_cmd $sketch"
local result
time $build_cmd $sketch >"$cache_dir"/build.log \
&& result=0 || result=1
if [ $result -ne 0 ]; then
echo ${ci_error}Build failed for $cnt $sketch
cat "$cache_dir/build.log"
echo $ci_end_group
return $result
else
grep -s -c warning: "$cache_dir"/build.log \
&& step_summary "$sketch warnings" "$cache_dir/build.log"
fi
print_size_info "$core_path"/tools/xtensa-lx106-elf/bin/xtensa-lx106-elf-size \
$build_dir/*.elf >>$cache_dir/size.log
echo $ci_end_group
done
}
function check_hash()
{
local file=$1
local hash=$2
local shasum
case ${RUNNER_OS-} in
"macOS")
shasum="shasum -a 512"
;;
*)
shasum="sha512sum"
;;
esac
echo "$hash $file" | $shasum -c -
}
function fetch_and_unpack()
{
local archive=$1
local hash=$2
local url=$3
test -r "$archive" \
&& check_hash "$archive" "$hash" \
|| { pushd "$cache_dir"
curl --output "$archive" --location "$url";
check_hash "$archive" "$hash";
popd;
mv "$cache_dir/$archive" ./"$archive"; }
case $archive in
*".zip")
unzip -q "$archive"
;;
*)
tar xf "$archive"
;;
esac
}
function install_library()
{
local lib_path=$1
local name=$2
local extract=$3
local archive=$4
local hash=$5
local url=$6
fetch_and_unpack "$archive" "$hash" "$url"
mkdir -p "$lib_path"
rm -rf "$lib_path/$name"
mv "$extract" "$lib_path/$name"
}
function install_libraries()
{
local core_path=$1
local lib_path=$2
mkdir -p "$core_path"/tools/dist
pushd "$core_path"/tools/dist
source "$root/tests/dep-libraries.sh"
popd
}
function install_arduino_cli()
{
local path=$1
local core_path=$2
local ver='1.2.2'
local urlbase="https://github.com/arduino/arduino-cli/releases/download/v${ver}/arduino-cli_${ver}_"
echo "Arduino CLI ${ver}"
mkdir -p ${core_path}/dist
pushd ${core_path}/dist
source "$root/tests/dep-arduino-cli.sh"
mkdir -p $(dirname $path)
cp -v arduino-cli $path
chmod +x $path
popd
}
function install_core()
{
local core_path=$1
local hardware_core_path=$2
local debug=$3
pushd "${core_path}"
local debug_flags=""
if [ "$debug" = "debug" ]; then
debug_flags="-DDEBUG_ESP_PORT=Serial -DDEBUG_ESP_SSL -DDEBUG_ESP_TLS_MEM"\
" -DDEBUG_ESP_HTTP_CLIENT -DDEBUG_ESP_HTTP_SERVER -DDEBUG_ESP_CORE -DDEBUG_ESP_WIFI"\
" -DDEBUG_ESP_HTTP_UPDATE -DDEBUG_ESP_UPDATER -DDEBUG_ESP_OTA -DDEBUG_ESP_OOM"
fi
# Set our custom warnings for all builds
printf "%s\n" \
"compiler.c.extra_flags=-Wall -Wextra $debug_flags" \
"compiler.cpp.extra_flags=-Wall -Wextra $debug_flags" \
"mkbuildoptglobals.extra_flags=--ci --cache_core" \
"recipe.hooks.prebuild.1.pattern=\"{runtime.tools.python3.path}/python3\" -I \"{runtime.tools.makecorever}\" --git-root \"{runtime.platform.path}\" --version \"{version}\" \"{runtime.platform.path}/cores/esp8266/core_version.h\"" \
> ${core_path}/platform.local.txt
echo -e "\n----platform.local.txt----"
cat platform.local.txt
echo -e "\n----\n"
# Fetch toolchain & filesystem utils
pushd tools
python3 get.py -q
popd
popd
# todo: windows runners are using copied tree
local core_dir
core_dir=$(dirname "$hardware_core_path")
mkdir -p "$core_dir"
if [ "${RUNNER_OS-}" = "Windows" ]; then
cp -a "$core_path" "${core_dir}/esp8266"
else
ln -s "$core_path" "$hardware_core_path"
fi
}
function install_arduino()
{
echo ${ci_group}Install arduino
local debug=$1
local hardware_core_path="$ESP8266_ARDUINO_HARDWARE/esp8266com/esp8266"
test -d "$hardware_core_path" \
|| install_core "$ESP8266_ARDUINO_BUILD_DIR" "$hardware_core_path" "$debug"
command -v "${ESP8266_ARDUINO_CLI}" \
|| install_arduino_cli "${ESP8266_ARDUINO_CLI}" "$hardware_core_path"
install_libraries "$ESP8266_ARDUINO_BUILD_DIR" "$ESP8266_ARDUINO_LIBRARIES"
echo $ci_end_group
}
function arduino_lwip_menu_option()
{
case $1 in
"default")
echo "lm2f"
;;
"IPv6")
echo "lm6f"
;;
esac
}
# mkbuildoptglobals.py is optimized around the Arduino IDE 1.x
# behaviour. One way the CI differs from the Arduino IDE is in the
# handling of core and caching core. With the Arduino IDE, each sketch
# has a private copy of core and contributes to a core cache. With the
# CI, there is one shared copy of core for all sketches. When global
# options are used, the shared copy of core and cache are removed before
# and after the build.
function arduino_mkbuildoptglobals_cleanup()
{
local clean_core=$1
local build_dir=$2
local sketch=$3
if [ -s ${sketch}.globals.h ]; then
clean_core=1
fi
# Remove sketch specific files from ./core/ between builds.
if [ $clean_core -ne 0 ]; then
rm -rf "$build_dir"/core/*
else
rm -rf "$build_dir/core/build.opt" "$build_dir"/core/*.ino.globals.h
fi
if [ -e ${build_dir}/core/*.a ]; then
# We need to preserve the build.options.json file and replace the last .ino
# with this sketch's ino file, or builder will throw everything away.
jq '."sketchLocation" = "'$sketch'"' $build_dir/build.options.json \
> "$build_dir"/build.options.json.tmp
mv "$build_dir"/build.options.json.tmp "$build_dir"/build.options.json
if [ $clean_core -ne 0 ]; then
# Hack workaround for CI not handling core rebuild for global options
rm ${build_dir}/core/*.a
fi
fi
if [ -s ${sketch}.globals.h ]; then
# Set to cleanup core at the start of the next build.
clean_core=1
else
clean_core=0
fi
echo $clean_core
}
function build_sketches_with_arduino()
{
local lwip
lwip=$(arduino_lwip_menu_option $1)
local build_mod=$2
local build_rem=$3
local build_cnt=$4
build_sketches "$ESP8266_ARDUINO_BUILD_DIR" \
"$ESP8266_ARDUINO_CLI" \
"$ESP8266_ARDUINO_LIBRARIES" \
"$lwip" "$build_mod" "$build_rem" "$build_cnt"
step_summary "Size report" "$cache_dir/size.log"
}
function install_platformio()
{
echo ${ci_group}Install PlatformIO
local board=$1
pushd $ESP8266_ARDUINO_BUILD_DIR/tools
python3 get.py -q
popd
install_libraries "$ESP8266_ARDUINO_BUILD_DIR" "$ESP8266_ARDUINO_LIBRARIES"
# we should reference our up-to-date build tools
# ref. https://docs.platformio.org/en/latest/core/userguide/pkg/cmd_install.html
pio pkg install --global --skip-dependencies --platform "https://github.com/platformio/platform-espressif8266.git"
local framework_symlink="framework-arduinoespressif8266 @ symlink://${ESP8266_ARDUINO_BUILD_DIR}"
local toolchain_symlink="toolchain-xtensa @ symlink://${ESP8266_ARDUINO_BUILD_DIR}/tools/xtensa-lx106-elf/"
# pre-generate config; pio-ci with multiple '-O' options replace each other instead of appending to the same named list
cat <<EOF > $cache_dir/platformio.ini
[env:$board]
platform = espressif8266
board = $board
framework = arduino
platform_packages =
${framework_symlink}
${toolchain_symlink}
EOF
cat $cache_dir/platformio.ini
echo $ci_end_group
}
function build_sketches_with_platformio()
{
local build_mod=$1
local build_rem=$2
local build_cnt=$3
local testcnt=0
for sketch in $ESP8266_ARDUINO_SKETCHES; do
testcnt=$(( ($testcnt + 1) % $build_mod ))
if [ $testcnt -ne $build_rem ]; then
continue # Not ours to do
fi
local skip
skip=$(skip_sketch "$sketch")
if [ -n "$skip" ]; then
echo "$skip"
continue # Should be skipped / cannot be built
fi
cnt=$(( $cnt + 1 ))
if [ $build_cnt != 0 ] ; then
if [ $build_cnt != $cnt ] ; then
continue # Haven't reached the $cnt yet
fi
build_cnt=0
fi
echo ${ci_group}Building $sketch
local sketchdir
sketchdir=$(dirname $sketch)
local result
env PLATFORMIO_LIB_DIR="${ESP8266_ARDUINO_LIBRARIES}" \
time pio ci \
--project-conf $cache_dir/platformio.ini \
$sketchdir >$cache_dir/build.log 2>&1 \
&& result=0 || result=1
if [ $result -ne 0 ]; then
echo ${ci_error}Build failed for $sketch
cat "$cache_dir/build.log"
echo $ci_end_group
return $result
fi
echo $ci_end_group
done
}
if [ -z "${ESP8266_ARDUINO_BUILD_DIR-}" ]; then
ESP8266_ARDUINO_BUILD_DIR=$(git rev-parse --show-toplevel)
echo "Using ESP8266_ARDUINO_BUILD_DIR=$ESP8266_ARDUINO_BUILD_DIR"
fi