From 11e3776e4094f9ff5128efabeb21c4f734ff7ef3 Mon Sep 17 00:00:00 2001 From: Justin Bunton <130115204+Bunton33@users.noreply.github.com> Date: Sun, 25 Oct 2026 13:53:46 -0400 Subject: [PATCH] build_artifacts.sh: resolve esptool, mklittlefs and boot_app0 through the env's platform Another project on the same machine replaced the plain packages/tool-esptoolpy folder with esptool 4.11.0 and moved the pinned 4.7.4 to a tool-esptoolpy@src-... folder, so the script silently used a different esptool (the merged image happened to be identical). The script now asks PlatformIO for the apollo_m1 platform, reads its pinned package versions from platform.json and uses the matching installed folders, falling back to the plain folders with a warning. BUILD_INFO.txt records which folders were used. Co-Authored-By: Claude Opus 5.5 --- apollo/build_artifacts.sh | 68 ++++++++++++++++++++++++++++++++++++--- 1 file changed, 64 insertions(+), 4 deletions(-) diff --git a/apollo/build_artifacts.sh b/apollo/build_artifacts.sh index 0d615b4005..3b99eaa46c 100755 --- a/apollo/build_artifacts.sh +++ b/apollo/build_artifacts.sh @@ -49,9 +49,68 @@ done PIO_HOME="${PLATFORMIO_CORE_DIR:-$HOME/.platformio}" PIO_PY="$PIO_HOME/penv/bin/python" [ -x "$PIO_PY" ] || PIO_PY="python3" -ESPTOOL_PY="$PIO_HOME/packages/tool-esptoolpy/esptool.py" -MKLITTLEFS="$PIO_HOME/packages/tool-mklittlefs/mklittlefs" -BOOT_APP0="$PIO_HOME/packages/framework-arduinoespressif32/tools/partitions/boot_app0.bin" + +# AI: below section was generated by an AI +# Other projects on the same machine install their own versions of these packages, sometimes under the plain +# folder name (tool-esptoolpy, framework-arduinoespressif32 ...), with ours moved to a "name@src-..." folder. +# So resolve each package through the platform the $ENV_NAME env actually uses: ask PlatformIO for the env's +# platform, read that platform's pinned package versions (platform.json), and pick the installed folder whose +# .piopm matches. Prints one folder per requested package; falls back to the plain folder with a warning. +read -r -d '' RESOLVE_PY <<'PY' || true +import json, os, re, sys +home, env, names = sys.argv[1], sys.argv[2], sys.argv[3:] +cfg = dict((s, dict(o)) for s, o in json.load(sys.stdin)) +plat = cfg["env:" + env]["platform"] + +def meta(d): + try: + with open(os.path.join(d, ".piopm")) as f: return json.load(f) + except Exception: return {} + +def nums(v): return tuple(int(x) for x in re.findall(r"\d+", v.split("+")[0])) + +def matches(m, want): + if not want: return False + spec = m.get("spec") or {} + if "://" in want: return spec.get("uri") == want + req, ver = want.split("@")[-1].strip(), m.get("version") or "" + if req[:1] in "^~": + base, have = nums(req[1:]), nums(ver) + keep = 1 if req[0] == "^" else 2 + return have[:keep] == base[:keep] and have >= base + return nums(ver) == nums(req) + +def dirs(sub, name): + root = os.path.join(home, sub) + return [os.path.join(root, d) for d in sorted(os.listdir(root)) if d == name or d.startswith(name + "@")] + +pdir = next((d for d in dirs("platforms", "espressif32") if matches(meta(d), plat)), None) +reqs = {} +if pdir: + with open(os.path.join(pdir, "platform.json")) as f: reqs = json.load(f).get("packages", {}) +else: + print("warning: platform %s is not installed under %s/platforms" % (plat, home), file=sys.stderr) +for n in names: + want = (reqs.get(n) or {}).get("version", "") + hit = next((d for d in dirs("packages", n) if matches(meta(d), want)), None) + if not hit: + hit = os.path.join(home, "packages", n) + print("warning: no installed %s matches the platform's %r; using %s" % (n, want, hit), file=sys.stderr) + print(hit) +PY +PKG_DIRS="$(cd "$ROOT" && PLATFORMIO_SETTING_CHECK_PLATFORMIO_INTERVAL=3650 pio project config --json-output 2>/dev/null \ + | "$PIO_PY" -c "$RESOLVE_PY" "$PIO_HOME" "$ENV_NAME" tool-esptoolpy tool-mklittlefs framework-arduinoespressif32)" || PKG_DIRS="" +if [ -z "$PKG_DIRS" ]; then + echo "warning: could not resolve the $ENV_NAME platform packages through PlatformIO; using the plain package folders" >&2 + PKG_DIRS="$(printf '%s\n' "$PIO_HOME/packages/tool-esptoolpy" "$PIO_HOME/packages/tool-mklittlefs" "$PIO_HOME/packages/framework-arduinoespressif32")" +fi +ESPTOOL_DIR="$(sed -n 1p <<< "$PKG_DIRS")" +MKLITTLEFS_DIR="$(sed -n 2p <<< "$PKG_DIRS")" +FRAMEWORK_DIR="$(sed -n 3p <<< "$PKG_DIRS")" +# AI: end +ESPTOOL_PY="$ESPTOOL_DIR/esptool.py" +MKLITTLEFS="$MKLITTLEFS_DIR/mklittlefs" +BOOT_APP0="$FRAMEWORK_DIR/tools/partitions/boot_app0.bin" [ -f "$ESPTOOL_PY" ] || { echo "esptool not found at $ESPTOOL_PY - build the $ENV_NAME env once first"; exit 1; } [ -f "$BOOT_APP0" ] || { echo "boot_app0.bin not found at $BOOT_APP0"; exit 1; } @@ -121,7 +180,8 @@ cp "$BUILD/firmware.elf" "$BUILD/firmware.map" "$BUILD/bootloader.bin" "$BUILD/p echo "built: $(date -u '+%Y-%m-%dT%H:%M:%SZ') (firmware.bin from $(date -u -r "$(mtime "$BUILD/firmware.bin")" '+%Y-%m-%dT%H:%M:%SZ' 2>/dev/null || date -u -d "@$(mtime "$BUILD/firmware.bin")" '+%Y-%m-%dT%H:%M:%SZ'))" echo "env: $ENV_NAME" echo "platformio: $(pio --version 2>/dev/null || echo unknown)" - echo "esptool: $(esptool version 2>/dev/null | tail -1)" + echo "esptool: $(esptool version 2>/dev/null | tail -1) (packages/$(basename "$ESPTOOL_DIR"))" + echo "boot_app0: packages/$(basename "$FRAMEWORK_DIR")" echo "littlefs: $FS_SOURCE" echo "web ui: $(grep -h 'define WEB_BUILD_TIME' "$ROOT"/wled00/html_ui.h 2>/dev/null | head -1)" } > "$OUT/BUILD_INFO.txt"