diff options
Diffstat (limited to 'docker/scripts/build-spike.sh')
| -rwxr-xr-x | docker/scripts/build-spike.sh | 84 |
1 files changed, 84 insertions, 0 deletions
diff --git a/docker/scripts/build-spike.sh b/docker/scripts/build-spike.sh new file mode 100755 index 0000000..32a5b89 --- /dev/null +++ b/docker/scripts/build-spike.sh @@ -0,0 +1,84 @@ +#!/usr/bin/env bash +# Author: cirakg & claude ai +# Summary: Build the M1 settings spike (debug .prg files and the signed beta .iq) and optionally run it in the simulator. +# +# Usage: build-spike.sh build debug builds for every spike product + build/spike/settings-spike.iq +# build-spike.sh sim [DEVICE] debug build, run it headless, screenshot (default DEVICE fr70) +# Output: build/spike/ only (debug/<DEVICE>.prg, settings-spike.iq, logs, screenshots). +# +# Same policy as the app: strict type checking (-l 3), any compiler warning +# fails. The .iq is the file to upload as a private beta (docs/SETTINGS_SPIKE.md). +set -euo pipefail +# shellcheck source=ciq-env.sh +source "$(dirname "${BASH_SOURCE[0]}")/ciq-env.sh" + +readonly SPIKE=/work/spike/settings +readonly JUNGLES="${SPIKE}/monkey.jungle;${SPIKE}/icons.jungle" +readonly OUT="${BUILD_DIR}/spike" +readonly DEVICES=(fr70 fr255s venusq2 fr965) +# Longest wait for the debug self-test's "SPIKE ready" line. +readonly READY_TIMEOUT_S=60 + +# Run monkeyc, keep its log, fail on errors and on warnings. +compile() { + local log_file="$1" + shift + if ! monkeyc "$@" -f "${JUNGLES}" -y "${DEV_KEY}" -l 3 -w >"${log_file}" 2>&1; then + cat "${log_file}" >&2 + die "spike compile failed (${log_file#/work/})" + fi + if grep -q "^WARNING" "${log_file}"; then + grep "^WARNING" "${log_file}" >&2 + die "compiler warnings in the spike build; warnings count as errors" + fi +} + +build_debug() { + local device="$1" + ciq_require_device "${device}" + mkdir -p "${OUT}/debug" + compile "${OUT}/debug/${device}.log" -d "${device}" -o "${OUT}/debug/${device}.prg" + log "built build/spike/debug/${device}.prg" +} + +build_all() { + local device + for device in "${DEVICES[@]}"; do + build_debug "${device}" + done + compile "${OUT}/settings-spike.log" -e -r -o "${OUT}/settings-spike.iq" + log "built build/spike/settings-spike.iq (upload this as the beta)" +} + +run_in_simulator() { + local device="$1" app_log pid _ + app_log="${OUT}/sim-${device}.log" + build_debug "${device}" + ciq_start_display + ciq_start_simulator + monkeydo "${OUT}/debug/${device}.prg" "${device}" >"${app_log}" 2>&1 & + pid=$! + for _ in $(seq 1 $((READY_TIMEOUT_S * 10))); do + grep -q "SPIKE ready" "${app_log}" && break + kill -0 "${pid}" 2>/dev/null || break + sleep 0.1 + done + grep -q "SPIKE ready" "${app_log}" || { cat "${app_log}" >&2; die "the spike did not report ready on ${device}"; } + sleep 1 + mkdir -p "${OUT}/raw" + import -window "$(ciq_simulator_window)" "${OUT}/raw/${device}-window.png" + kill "${pid}" 2>/dev/null || true + python3 /work/tools/sim_screenshot.py --raw "${OUT}/raw/${device}-window.png" \ + --device-dir "${CIQ_HOME}/Devices/${device}" --out "${OUT}/screen-${device}.png" + grep "SPIKE ready" "${app_log}" >&2 + log "screen saved to build/spike/screen-${device}.png" +} + +ciq_require_sdk +ciq_require_key +mkdir -p "${OUT}" +case "${1:-build}" in + build) build_all ;; + sim) run_in_simulator "${2:-fr70}" ;; + *) die "usage: build-spike.sh build | sim [DEVICE]" ;; +esac |
