Files
MeshCore/local_build.sh
T
richandClaude Opus 5.5 0030aec8dd
Build and deploy Docs site to GitHub Pages / github-pages (push) Canceled after 0s
Run Unit Tests / nrf52-companion-smoke (push) Canceled after 0s
Run Unit Tests / nrf52-sensor-smoke (push) Canceled after 0s
Run Unit Tests / esp32-sensor-smoke (push) Canceled after 0s
Run Unit Tests / management-reports (push) Canceled after 0s
Run Unit Tests / stm32-companion-smoke (push) Canceled after 0s
Run Unit Tests / bootloader-version (push) Canceled after 0s
Run Unit Tests / test (push) Canceled after 0s
Run Unit Tests / hosted-doc-links (push) Canceled after 0s
Count only firmware-code commits in the -hz.N build identifier
Merge commits and commits that touch only the build-setup files
(local_build.sh, local_version.py, platformio.local.ini) no longer bump
the identifier, and setup-file edits no longer mark a build .dirty, so
a branch that only carries settings builds as the plain fork version.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01C6JeNqcQRUMo2vt6vFBmhk
2026-10-13 21:40:55 -04:00

98 lines
4.6 KiB
Bash
Executable File

#!/bin/sh
# Local firmware build wrapper: bakes this checkout's preferred defaults into
# every build, then hands off to build.sh with the same arguments.
#
# Usage:
# ./local_build.sh build-firmware <TARGET> [build.sh options]
#
# Defaults baked in (edit the list below to change them):
# Radio 919.5 MHz / BW500 / SF10 / CR5 (matches the local mesh;
# Hazelwood KM-Test repeater)
# BLE PIN code macro 123456 (on display boards such as Heltec V3 the
# firmware treats 123456 as "show a random PIN on screen each
# session"; set a fixed PIN at runtime from the app/CLI instead)
# Settings profile: target defaults (--profile default), not Cascade
# Version label: see local_version.py
#
# How it works: build.sh normally injects the USA Cascadia radio preset after
# any caller flags, which would win. `--radio-preset target` disables that
# injection, so the LORA_* flags exported here take effect. build.sh keeps an
# existing PLATFORMIO_BUILD_FLAGS and appends its own recipe flags after it.
#
# Firmware defaults only apply to a node without saved preferences (fresh
# flash or erase). A node that already has saved settings keeps them.
#
# macOS: build.sh needs bash >= 4, flock and GNU date/sed:
# brew install bash flock coreutils gnu-sed
#
# Lives on the personal Gitea branch, not in the upstream fork.
set -e
LOCAL_BUILD_FLAGS="-DLORA_FREQ=919.5 -DLORA_BW=500 -DLORA_SF=10 -DLORA_CR=5 -DBLE_PIN_CODE=123456"
export PLATFORMIO_BUILD_FLAGS="${PLATFORMIO_BUILD_FLAGS:+${PLATFORMIO_BUILD_FLAGS} }${LOCAL_BUILD_FLAGS}"
if [ -d /opt/homebrew/bin ]; then
PATH="/opt/homebrew/opt/coreutils/libexec/gnubin:/opt/homebrew/opt/gnu-sed/libexec/gnubin:/opt/homebrew/bin:${PATH}"
export PATH
fi
cd "$(dirname "$0")"
# Firmware version label (applied by local_version.py, see that file):
# hazelwood_repeater v<VERSION> (core v<CORE>) / companion: v<VERSION> hazelwood (core v<CORE>)
# VERSION follows the fork's own numbering: the highest vX.Y.Z.W tag reachable
# from HEAD (e.g. v1.17.1.10 from rak4631-full-companion-v1.17.1.10-preview3).
# Local code changes add an identifier; build settings (untracked files) don't:
# -hz.N N of your own commits that change firmware code relative to the
# maintainer's fork (upstream/keymindCascade; origin is the personal
# Gitea copy, so @{upstream} would hide them)
# .dirty uncommitted edits to tracked firmware code
# Merge commits and the build-setup files below don't count: they change
# settings, not code. Edit LOCAL_FW_SETUP_PATHS if you add more setup files.
# CORE is the upstream MeshCore version from examples/simple_repeater/MyMesh.h.
LOCAL_FW_NAME=hazelwood
fork_version=$(git tag --merged HEAD \
| sed -nE 's/.*v([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+).*/\1/p' \
| sort -t. -k1,1n -k2,2n -k3,3n -k4,4n | tail -n 1)
if [ -z "$fork_version" ]; then
echo "local_build.sh: no vX.Y.Z.W tag reachable from HEAD; run git fetch --tags" >&2
exit 1
fi
local_id=""
LOCAL_FW_UPSTREAM_REF=${LOCAL_FW_UPSTREAM_REF:-upstream/keymindCascade}
LOCAL_FW_SETUP_PATHS=":(exclude)local_build.sh :(exclude)local_version.py :(exclude)platformio.local.ini"
# shellcheck disable=SC2086 # intentional word-splitting of the pathspec list
local_commits=$(git rev-list --count --no-merges "${LOCAL_FW_UPSTREAM_REF}..HEAD" \
-- . $LOCAL_FW_SETUP_PATHS 2>/dev/null || echo 0)
if [ "$local_commits" -gt 0 ]; then
local_id="-hz.${local_commits}"
fi
# shellcheck disable=SC2086
if [ -n "$(git status --porcelain --untracked-files=no -- . $LOCAL_FW_SETUP_PATHS)" ]; then
local_id="${local_id:--hz}.dirty"
fi
LOCAL_FW_VERSION="v${fork_version}${local_id}"
LOCAL_FW_CORE_VERSION=$(sed -n 's/^ *#define FIRMWARE_VERSION *"v\([0-9.]*\)".*/\1/p' examples/simple_repeater/MyMesh.h | head -n 1)
export LOCAL_FW_NAME LOCAL_FW_VERSION LOCAL_FW_CORE_VERSION
# build.sh deletes and recreates its output directory on every run (unless
# RESUME_BUILD_OUTPUT=1), so give each run its own folder under out/ instead of
# letting it wipe out/ itself. Never keep anything else in an output folder.
if [ -z "${OUTPUT_DIR:-}" ]; then
OUTPUT_DIR="out/$(date +%Y%m%d-%H%M%S)"
export OUTPUT_DIR
fi
echo "Build output: ${OUTPUT_DIR}"
# FIRMWARE_VERSION also names the output files (build.sh appends -<commit8>).
export FIRMWARE_VERSION="${LOCAL_FW_VERSION}"
export PLATFORMIO_EXTRA_SCRIPTS="${PLATFORMIO_EXTRA_SCRIPTS:+${PLATFORMIO_EXTRA_SCRIPTS}
}pre:local_version.py"
echo "Local build defaults: ${LOCAL_BUILD_FLAGS} (--radio-preset target --profile default)"
echo "Local firmware version: ${FIRMWARE_VERSION} (core v${LOCAL_FW_CORE_VERSION})"
exec bash build.sh "$@" --radio-preset target --profile default