|
1 | 1 | #!/usr/bin/env bash |
| 2 | + |
2 | 3 | set -euo pipefail |
3 | 4 |
|
| 5 | +WORKSPACE=/workspace |
| 6 | +JOBS=$(nproc) |
| 7 | + |
4 | 8 | # Define vars (use safe defaults so -u won't fail) |
5 | 9 | : "${GITHUB_ACTIONS:=false}" |
6 | | - |
7 | 10 | # Inputs (provide safe defaults) |
8 | 11 | : "${REPO_REMOTE:=origin}" |
9 | 12 | : "${REPO_REF:=main}" |
10 | | -: "${MPY_TARGET:=build}" |
11 | | -: "${MPY_BOARD:=}" |
12 | | -: "${MPY_FLAGS:=}" |
| 13 | +: "${BOARD:=}" |
13 | 14 |
|
14 | 15 | # Reset to the target SHA |
15 | 16 | git fetch origin --tags --prune |
16 | 17 | git fetch upstream --tags --prune |
17 | 18 | git fetch "${REPO_REMOTE}" "${REPO_REF}" |
18 | 19 | git reset --hard FETCH_HEAD |
19 | 20 | git repack -d |
20 | | -# trunk-ignore(shellcheck/SC2312) |
21 | | -echo "Repository firmware version: $(git describe --tags --dirty --always --match 'v[1-9].*')" |
| 21 | + |
| 22 | +# Make the firmware tag |
| 23 | +# final filename will be <BOARD><-VARIANT>-<DATE>-v<SEMVER>.ext |
| 24 | +# where SEMVER is vX.Y.Z or vX.Y.Z-preview.N.gHASH or vX.Y.Z-preview.N.gHASH.dirty |
| 25 | +FW_DATE=$(date '+%Y%m%d') |
| 26 | +# same logic as makeversionhdr.py, convert git-describe output into semver-compatible |
| 27 | +FW_GIT_TAG="$(git describe --tags --dirty --always --match 'v[1-9].*')" |
| 28 | +FW_SEMVER_MAJOR_MINOR_PATCH="$(echo "${FW_GIT_TAG}" | cut -d'-' -f1)" |
| 29 | +FW_SEMVER_PRERELEASE="$(echo "${FW_GIT_TAG}" | cut -s -d'-' -f2-)" |
| 30 | +if [[ -z ${FW_SEMVER_PRERELEASE} ]]; then |
| 31 | + FW_SEMVER="${FW_SEMVER_MAJOR_MINOR_PATCH}" |
| 32 | +else |
| 33 | + FW_SEMVER="${FW_SEMVER_MAJOR_MINOR_PATCH}-$(echo "${FW_SEMVER_PRERELEASE}" | tr - .)" |
| 34 | +fi |
| 35 | +FW_TAG="-${FW_DATE}-${FW_SEMVER}" |
| 36 | +echo "Firmware version: ${FW_SEMVER}" |
| 37 | +echo "Firmware tag: ${FW_TAG}" |
22 | 38 |
|
23 | 39 | # Espressif IDF |
24 | 40 | if [[ ${MPY_PORT} == "esp32" ]]; then |
25 | | - export IDF_PATH=/opt/esp-idf |
26 | | - export IDF_TOOLS_PATH=/opt/esp-idf-tools |
27 | | - export ESP_ROM_ELF_DIR=/opt/esp-idf-tools |
28 | | - # trunk-ignore(shellcheck/SC1091) |
29 | | - source "${IDF_PATH}/export.sh" |
| 41 | + export IDF_PATH=/opt/esp-idf |
| 42 | + export IDF_TOOLS_PATH=/opt/esp-idf-tools |
| 43 | + export ESP_ROM_ELF_DIR=/opt/esp-idf-tools |
| 44 | + # trunk-ignore(shellcheck/SC1091) |
| 45 | + source "${IDF_PATH}/export.sh" |
30 | 46 | fi |
31 | 47 |
|
32 | | -JOBS=$(nproc) |
33 | | - |
34 | 48 | make -j"${JOBS}" -C mpy-cross |
35 | 49 | make -C ports/"${MPY_PORT}" submodules |
36 | 50 |
|
37 | 51 | # Build |
38 | | -if [[ ${MPY_TARGET} == "build" ]]; then |
39 | | - echo "Building MicroPython: ${MPY_PORT}:${MPY_BOARD}" |
40 | | - # trunk-ignore(shellcheck/SC2312) |
41 | | - # trunk-ignore(shellcheck/SC2086) |
42 | | - # trunk-ignore(shellcheck/SC2250) |
43 | | - make -j"${JOBS}" -C "ports/${MPY_PORT}" BOARD="${MPY_BOARD}" $MPY_FLAGS |
44 | | - # trunk-ignore(shellcheck/SC2231) |
45 | | - for OUTDIR in /workspace/ports/${MPY_PORT}/build-${MPY_BOARD}*; do |
46 | | - if [[ -d "${OUTDIR}" ]]; then |
47 | | - DESTDIR="/workspace/bin/${MPY_BOARD}" |
48 | | - mkdir -p "${DESTDIR}" |
49 | | - find "${OUTDIR}" -maxdepth 1 -type f \( -name '*.uf2' -o -name '*.bin' -o -name '*.hex' -o -name '*.elf' -o -name '*.dfu' -o -name '*.map' \) -exec cp {} "${DESTDIR}" \; |
| 52 | +echo "Build ${MPY_PORT} firmware: ${BOARD}" |
| 53 | +mkdir -p "${WORKSPACE}/bin" |
| 54 | + |
| 55 | +function copy_artefacts { |
| 56 | + local dest_dir=$1 |
| 57 | + local descr=$2 |
| 58 | + local fw_tag=$3 |
| 59 | + local build_dir=$4 |
| 60 | + shift 4 |
| 61 | + for ext in "$@"; do |
| 62 | + dest=${dest_dir}/${descr}${fw_tag}.${ext} |
| 63 | + if [[ -r ${build_dir}/firmware.${ext} ]]; then |
| 64 | + mv "${build_dir}"/firmware."${ext}" "${dest}" |
| 65 | + elif [[ -r ${build_dir}/micropython.${ext} ]]; then |
| 66 | + # esp32 has micropython.elf, etc |
| 67 | + mv "${build_dir}"/micropython."${ext}" "${dest}" |
| 68 | + # trunk-ignore(shellcheck/SC2292) |
| 69 | + # trunk-ignore(shellcheck/SC2166) |
| 70 | + elif [ "${ext}" = app-bin -a -r "${build_dir}"/micropython.bin ]; then |
| 71 | + # esp32 has micropython.bin which is just the application |
| 72 | + mv "${build_dir}"/micropython.bin "${dest}" |
| 73 | + fi |
| 74 | + done |
| 75 | +} |
| 76 | + |
| 77 | +function build_board { |
| 78 | + # trunk-ignore(shellcheck/SC2002) |
| 79 | + DESCR=$(cat ports/"${MPY_PORT}"/boards/"${BOARD}"/board.json | python3 -c "import json,sys; print(json.load(sys.stdin).get('id', '${BOARD}'))") |
| 80 | + # Build the "default" variant. For most boards this is the only thing we build. |
| 81 | + echo "building ${DESCR}" |
| 82 | + make -j"${JOBS}" -C ports/"${MPY_PORT}" BOARD="${BOARD}" |
| 83 | + if [[ ! -d ports/"${MPY_PORT}"/build-"${BOARD}" ]]; then |
| 84 | + mv ports/"${MPY_PORT}"/build-"${BOARD}"-* ports/"${MPY_PORT}"/build-"${BOARD}" |
| 85 | + fi |
| 86 | + copy_artefacts "${WORKSPACE}/bin" "${DESCR}" "${FW_TAG}" ports/"${MPY_PORT}"/build-"${BOARD}" "$@" |
| 87 | + # Query variants from board.json and build them. |
| 88 | + # trunk-ignore(shellcheck/SC2002) |
| 89 | + for VARIANT in $(cat ports/"${MPY_PORT}"/boards/"${BOARD}"/board.json | python3 -c "import json,sys; print(' '.join(json.load(sys.stdin).get('variants', {}).keys()))"); do |
| 90 | + echo "building variant ${DESCR} ${VARIANT}" |
| 91 | + make -j"${JOBS}" -C ports/"${MPY_PORT}" BOARD="${BOARD}" BOARD_VARIANT="${VARIANT}" |
| 92 | + if [[ ! -d ports/"${MPY_PORT}"/build-"${BOARD}"-"${VARIANT}" ]]; then |
| 93 | + mv ports/"${MPY_PORT}"/build-"${BOARD}"-"${VARIANT}"-* ports/"${MPY_PORT}"/build-"${BOARD}"-"${VARIANT}" |
50 | 94 | fi |
51 | | - done |
52 | | - echo "Build artifacts are located at: /workspace/bin" |
| 95 | + copy_artefacts "${WORKSPACE}/bin" "${DESCR}-${VARIANT}" "${FW_TAG}" ports/"${MPY_PORT}"/build-"${BOARD}"-"${VARIANT}" "$@" |
| 96 | + done |
| 97 | +} |
| 98 | + |
| 99 | +if [[ ${MPY_PORT} == "alif" ]]; then |
| 100 | + build_board zip |
53 | 101 | fi |
54 | 102 |
|
55 | | -# Release |
56 | | -if [[ ${MPY_TARGET} == "release" ]]; then |
57 | | - echo "Building MicroPython release: ${MPY_PORT}:${MPY_BOARD}" |
58 | | - for BOARD in ${MPY_BOARD}; do |
59 | | - echo "Building for board: ${BOARD}" |
60 | | - # trunk-ignore(shellcheck/SC2312) |
61 | | - # trunk-ignore(shellcheck/SC2086) |
62 | | - # trunk-ignore(shellcheck/SC2250) |
63 | | - make -j"${JOBS}" -C "ports/${MPY_PORT}" BOARD="${BOARD}" $MPY_FLAGS || true |
64 | | - done |
65 | | - mkdir -p /workspace/bin |
66 | | - for BOARD in ${MPY_BOARD}; do |
67 | | - # trunk-ignore(shellcheck/SC2231) |
68 | | - for OUTDIR in /workspace/ports/${MPY_PORT}/build-${BOARD}*; do |
69 | | - if [[ -d ${OUTDIR} ]]; then |
70 | | - DESTDIR="/workspace/bin/${BOARD}" |
71 | | - mkdir -p "${DESTDIR}" |
72 | | - find "${OUTDIR}" -maxdepth 1 -type f \( -name '*.uf2' -o -name '*.bin' -o -name '*.hex' -o -name '*.elf' -o -name '*.dfu' -o -name '*.map' \) -exec cp {} "${DESTDIR}" \; |
73 | | - fi |
74 | | - done |
75 | | - done |
76 | | - echo "Build artifacts are located at: /workspace/bin/" |
| 103 | +if [[ ${MPY_PORT} == "cc3200" ]]; then |
| 104 | + build_board zip |
77 | 105 | fi |
| 106 | + |
| 107 | +if [[ ${MPY_PORT} == "esp32" ]]; then |
| 108 | + build_board bin elf map uf2 app-bin |
| 109 | +fi |
| 110 | + |
| 111 | +if [[ ${MPY_PORT} == "esp8266" ]]; then |
| 112 | + build_board bin elf map |
| 113 | +fi |
| 114 | + |
| 115 | +if [[ ${MPY_PORT} == "mimxrt" ]]; then |
| 116 | + build_board bin hex uf2 |
| 117 | +fi |
| 118 | + |
| 119 | +if [[ ${MPY_PORT} == "nrf" ]]; then |
| 120 | + build_board bin hex uf2 |
| 121 | +fi |
| 122 | + |
| 123 | +if [[ ${MPY_PORT} == "renesas_ra" ]]; then |
| 124 | + build_board bin hex |
| 125 | +fi |
| 126 | + |
| 127 | +if [[ ${MPY_PORT} == "rp2" ]]; then |
| 128 | + build_board uf2 |
| 129 | +fi |
| 130 | + |
| 131 | +if [[ ${MPY_PORT} == "samd" ]]; then |
| 132 | + build_board uf2 |
| 133 | +fi |
| 134 | + |
| 135 | +if [[ ${MPY_PORT} == "stm32" ]]; then |
| 136 | + build_board dfu hex |
| 137 | +fi |
| 138 | + |
| 139 | +echo "Build artifacts are located at: ${WORKSPACE}/bin" |
0 commit comments