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_artifacts {
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+ fi
31+ done
32+ }
833
934function build_board {
1035 # check/get parameters
@@ -13,30 +38,26 @@ function build_board {
1338 return 1
1439 fi
1540
16- board_json=$1
17- fw_tag=$2
18- dest_dir=$3
19- shift
20- shift
21- shift
41+ local board_json=$1
42+ local fw_tag=$2
43+ local dest_dir=$3
44+ shift 3
2245
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
46+ local board=$( echo $board_json | awk -F ' /' ' { print $2 }' )
47+ local descr=$( cat $board_json | python3 -c " import json,sys; print(json.load(sys.stdin).get('id', '$board '))" )
2648
2749 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- fi
37- done
38- )
50+ local build_dir=/tmp/micropython-build-$board
51+ $MICROPY_AUTOBUILD_MAKE BOARD=$board BUILD=$build_dir && copy_artifacts $dest_dir $descr $fw_tag $build_dir $@
3952 rm -rf $build_dir
53+
54+ # Run the query-variants target (if supported).
55+ for variant in ` ($MICROPY_AUTOBUILD_MAKE BUILD=$build_dir -variants BOARD=$board query-variants 2>&1 || true) | grep VARIANTS: | cut -d' ' -f2-` ; do
56+ local variant_build_dir=$build_dir -$variant
57+ echo " building variant $descr $board $variant "
58+ $MICROPY_AUTOBUILD_MAKE BOARD=$board BOARD_VARIANT=$variant BUILD=$variant_build_dir && copy_artifacts $dest_dir $descr -$variant $fw_tag $variant_build_dir $@
59+ rm -rf $variant_build_dir
60+ done
4061}
4162
4263function build_boards {
@@ -46,7 +67,7 @@ function build_boards {
4667 return 1
4768 fi
4869
49- check_file=$1
70+ local check_file=$1
5071 shift
5172
5273 # check we are in the correct directory
0 commit comments