33# The functions in this file can be run independently to build boards.
44# For example:
55#
6- # $ source build-boards.sh
7- # $ MICROPY_AUTOBUILD_MAKE=make build_rp2_boards -latest /tmp
6+ # $ source tools/autobuild/build-boards.sh
7+ # $ cd ports/rp2
8+ # $ MICROPY_AUTOBUILD_MAKE="make -j8" build_rp2_boards -latest /tmp
9+ #
10+ # Or to build a single board:
11+ #
12+ # $ source tools/autobuild/build-boards.sh
13+ # $ cd ports/rp2
14+ # $ MICROPY_AUTOBUILD_MAKE="make -j8" build_board boards/PICO/board.json -latest /tmp uf2
15+
16+ function copy_artefacts {
17+ local dest_dir=$1
18+ local descr=$2
19+ local fw_tag=$3
20+ local build_dir=$4
21+ shift 4
22+
23+ for ext in $@ ; do
24+ dest=$dest_dir /$descr$fw_tag .$ext
25+ if [ -r $build_dir /firmware.$ext ]; then
26+ mv $build_dir /firmware.$ext $dest
27+ elif [ -r $build_dir /micropython.$ext ]; then
28+ # esp32 has micropython.elf, etc
29+ mv $build_dir /micropython.$ext $dest
30+ elif [ $ext = app-bin -a -r $build_dir /micropython.bin ]; then
31+ # esp32 has micropython.bin which is just the application
32+ mv $build_dir /micropython.bin $dest
33+ fi
34+ done
35+ }
836
937function build_board {
1038 # check/get parameters
@@ -13,33 +41,29 @@ function build_board {
1341 return 1
1442 fi
1543
16- board_json=$1
17- fw_tag=$2
18- dest_dir=$3
19- shift
20- shift
21- shift
44+ local board_json=$1
45+ local fw_tag=$2
46+ local dest_dir=$3
47+ shift 3
2248
23- board=$( echo $board_json | awk -F ' /' ' { print $2 }' )
24- descr=$( cat $board_json | python3 -c " import json,sys; print(json.load(sys.stdin).get('id', '$board '))" )
25- build_dir=/tmp/micropython-build-$board
49+ local board=$( echo $board_json | awk -F ' /' ' { print $2 }' )
50+ local descr=$( cat $board_json | python3 -c " import json,sys; print(json.load(sys.stdin).get('id', '$board '))" )
2651
52+ # Build the "default" variant. For most boards this is the only thing we build.
2753 echo " building $descr $board "
28- $MICROPY_AUTOBUILD_MAKE BOARD=$board BUILD=$build_dir && (
29- for ext in $@ ; do
30- dest=$dest_dir /$descr$fw_tag .$ext
31- if [ -r $build_dir /firmware.$ext ]; then
32- mv $build_dir /firmware.$ext $dest
33- elif [ -r $build_dir /micropython.$ext ]; then
34- # esp32 has micropython.elf, etc
35- mv $build_dir /micropython.$ext $dest
36- elif [ $ext = app-bin -a -r $build_dir /micropython.bin ]; then
37- # esp32 has micropython.bin which is just the application
38- mv $build_dir /micropython.bin $dest
39- fi
40- done
41- )
54+ local build_dir=/tmp/micropython-build-$board
55+ $MICROPY_AUTOBUILD_MAKE BOARD=$board BUILD=$build_dir && copy_artefacts $dest_dir $descr $fw_tag $build_dir $@
4256 rm -rf $build_dir
57+
58+ # Query variants from board.json and build them. Ignore the special "idf3"
59+ # variant for ESP32 boards (this allows the downloads page to still have
60+ # the idf3 files for older releases that used to be explicitly built).
61+ for variant in ` cat $board_json | python3 -c " import json,sys; print(' '.join(v for v in json.load(sys.stdin).get('variants', {}).keys() if v != 'idf3'))" ` ; do
62+ local variant_build_dir=$build_dir -$variant
63+ echo " building variant $descr $board $variant "
64+ $MICROPY_AUTOBUILD_MAKE BOARD=$board BOARD_VARIANT=$variant BUILD=$variant_build_dir && copy_artefacts $dest_dir $descr -$variant $fw_tag $variant_build_dir $@
65+ rm -rf $variant_build_dir
66+ done
4367}
4468
4569function build_boards {
@@ -49,7 +73,7 @@ function build_boards {
4973 return 1
5074 fi
5175
52- check_file=$1
76+ local check_file=$1
5377 shift
5478
5579 # check we are in the correct directory
0 commit comments