#!/usr/bin/env bash set -euo pipefail usage() { echo "Usage: $0 compile|examples --platform esp8266|esp32" >&2 exit 2 } [[ $# -eq 3 && ( "${1:-}" == "compile" || "${1:-}" == "examples" ) && "${2:-}" == "--platform" ]] || usage case "${3:-}" in esp8266|esp32) environment="${3}" ;; *) usage ;; esac root="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" pio_for_platform() { if [[ "$environment" != "esp32" ]]; then pio "$@" return fi # Keep Core 3.3.11's package-form esptool and generated pioarduino # environment in a persistent repository cache. It is never cleared by # this script, and isolates this tested graph from stale global metadata. local core_dir packages_dir cache_dir core_dir="${ARDUINOHA_PLATFORMIO_CORE_DIR:-${XDG_CACHE_HOME:-$HOME/.cache}/arduinoha-platformio/core-3.3.11}" packages_dir="${ARDUINOHA_PLATFORMIO_PACKAGES_DIR:-$core_dir/packages}" cache_dir="${ARDUINOHA_PLATFORMIO_CACHE_DIR:-$core_dir/cache}" install -d -m 700 "$core_dir" "$packages_dir" "$cache_dir" PLATFORMIO_CORE_DIR="$core_dir" PLATFORMIO_PACKAGES_DIR="$packages_dir" \ PLATFORMIO_CACHE_DIR="$cache_dir" pio "$@" } case "$1" in compile) # PlatformIO's test command starts many archive jobs by default. This # multi-suite project has a reproducible missing-object race on Core # 3.3.11 at high parallelism, so use a deterministic default while # preserving an explicit caller override. export PLATFORMIO_RUN_JOBS="${PLATFORMIO_RUN_JOBS:-1}" pio_for_platform test -d "$root" -e "$environment" --without-uploading --without-testing echo "ArduinoHA compile check passed for $environment" ;; examples) mapfile -t examples < <(find "$root/examples" -mindepth 1 -maxdepth 1 -type d -name '[0-9][0-9]-*' -print | sort) if (( ${#examples[@]} == 0 )); then echo "No example projects found" >&2 exit 1 fi for example in "${examples[@]}"; do pio_for_platform run -d "$example" -e "$environment"