Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 64 additions & 4 deletions apollo/build_artifacts.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand Down Expand Up @@ -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"
Expand Down
Loading