Add support for snippets to build recipe

This commit is contained in:
urob 2024-11-25 09:31:26 -05:00
parent 24948e1801
commit de8250296a

View file

@ -36,19 +36,19 @@ _parse_combos:
# parse build.yaml and filter targets by expression # parse build.yaml and filter targets by expression
_parse_targets $expr: _parse_targets $expr:
#!/usr/bin/env bash #!/usr/bin/env bash
attrs="[.board, .shield]" attrs="[.board, .shield, .snippet]"
filter="(($attrs | map(. // [.]) | combinations), ((.include // {})[] | $attrs)) | join(\",\")" filter="(($attrs | map(. // [.]) | combinations), ((.include // {})[] | $attrs)) | join(\",\")"
echo "$(yq -r "$filter" build.yaml | grep -v "^," | grep -i "${expr/#all/.*}")" echo "$(yq -r "$filter" build.yaml | grep -v "^," | grep -i "${expr/#all/.*}")"
# build firmware for single board & shield combination # build firmware for single board & shield combination
_build_single $board $shield *west_args: _build_single $board $shield $snippet *west_args:
#!/usr/bin/env bash #!/usr/bin/env bash
set -euo pipefail set -euo pipefail
artifact="${shield:+${shield// /+}-}${board}" artifact="${shield:+${shield// /+}-}${board}"
build_dir="{{ build / '$artifact' }}" build_dir="{{ build / '$artifact' }}"
echo "Building firmware for $artifact..." echo "Building firmware for $artifact..."
west build -s zmk/app -d "$build_dir" -b $board {{ west_args }} -- \ west build -s zmk/app -d "$build_dir" -b $board {{ west_args }} ${snippet:+-S "$snippet"} -- \
-DZMK_CONFIG="{{ config }}" ${shield:+-DSHIELD="$shield"} -DZMK_CONFIG="{{ config }}" ${shield:+-DSHIELD="$shield"}
if [[ -f "$build_dir/zephyr/zmk.uf2" ]]; then if [[ -f "$build_dir/zephyr/zmk.uf2" ]]; then
@ -64,8 +64,8 @@ build expr *west_args: _parse_combos
targets=$(just _parse_targets {{ expr }}) targets=$(just _parse_targets {{ expr }})
[[ -z $targets ]] && echo "No matching targets found. Aborting..." >&2 && exit 1 [[ -z $targets ]] && echo "No matching targets found. Aborting..." >&2 && exit 1
echo "$targets" | while IFS=, read -r board shield; do echo "$targets" | while IFS=, read -r board shield snippet; do
just _build_single "$board" "$shield" {{ west_args }} just _build_single "$board" "$shield" "$snippet" {{ west_args }}
done done
# clear build cache and artifacts # clear build cache and artifacts