diff --git a/_build_helpers.py b/_build_helpers.py new file mode 100644 index 00000000..5f100214 --- /dev/null +++ b/_build_helpers.py @@ -0,0 +1,19 @@ +"""Shared helpers for the PlatformIO pre-build scripts (patch_*, sync_file_libdeps). + +Centralizes the per-environment libdeps path so it is computed exactly ONE way. +Each PlatformIO environment gets its OWN .pio/libdeps/ tree, so this path +MUST be resolved per-environment. Hardcoding the env component (e.g. "tdeck") +silently misdirects a patch when building any OTHER env -- that is exactly how the +`nimble_host_reset_reason` undefined-reference link error appeared in tdeck-ota. +Always go through env_libdeps_dir(); never re-hand-roll the path with a literal env. +""" +import os + + +def env_libdeps_dir(env, *parts): + """Path inside THIS environment's libdeps tree: .pio/libdeps//.""" + return os.path.join( + env.get("PROJECT_DIR", "."), + ".pio", "libdeps", env.get("PIOENV", "tdeck"), + *parts, + ) diff --git a/patch_filestore.py b/patch_filestore.py index 4a02598c..68b67a97 100644 --- a/patch_filestore.py +++ b/patch_filestore.py @@ -23,12 +23,11 @@ Three purposes: patch pending the upstream fix landing. """ Import("env") -import os +import os, sys +sys.path.insert(0, env.get("PROJECT_DIR", ".")) +from _build_helpers import env_libdeps_dir # per-env libdeps path; never hardcode the env -FILESTORE_H = os.path.join( - env.get("PROJECT_DIR", "."), - ".pio", "libdeps", env.get("PIOENV", "tdeck"), "microStore", "include", "microStore", "FileStore.h", -) +FILESTORE_H = env_libdeps_dir(env, "microStore", "include", "microStore", "FileStore.h") OLD = """\tbool exists(const uint8_t* key, uint8_t key_len) \t{ diff --git a/patch_littlefs_paths.py b/patch_littlefs_paths.py index 725efdb9..fbf1bdc8 100644 --- a/patch_littlefs_paths.py +++ b/patch_littlefs_paths.py @@ -24,12 +24,10 @@ normalize paths to a leading "/" itself (file an issue / PR on the fork). Import("env") # noqa: F821 import os import sys +sys.path.insert(0, env.get("PROJECT_DIR", ".")) # noqa: F821 +from _build_helpers import env_libdeps_dir # per-env libdeps path; never hardcode the env -ADAPTER_H = os.path.join( - env.get("PROJECT_DIR", "."), # noqa: F821 - ".pio", "libdeps", env.get("PIOENV", "tdeck"), # noqa: F821 - "microStore", "include", "microStore", "Adapters", "LittleFSFileSystem.h", -) +ADAPTER_H = env_libdeps_dir(env, "microStore", "include", "microStore", "Adapters", "LittleFSFileSystem.h") MARKER = "_pyxis_norm_path" diff --git a/patch_msgpack.py b/patch_msgpack.py index 2be8dfdd..83ef0fdf 100644 --- a/patch_msgpack.py +++ b/patch_msgpack.py @@ -15,12 +15,11 @@ Mirrors the patch the microLXMF conformance-bridge applies via its CMakeLists (microLXMF/conformance-bridge/CMakeLists.txt:106-125). """ Import("env") -import os +import os, sys +sys.path.insert(0, env.get("PROJECT_DIR", ".")) +from _build_helpers import env_libdeps_dir # per-env libdeps path; never hardcode the env -MSGPACK_BASE = os.path.join( - env.get("PROJECT_DIR", "."), - ".pio", "libdeps", env.get("PIOENV", "tdeck"), "MsgPack", "MsgPack" -) +MSGPACK_BASE = env_libdeps_dir(env, "MsgPack", "MsgPack") def apply_patch(filepath, old, new, label): if not os.path.exists(filepath): diff --git a/patch_nimble.py b/patch_nimble.py index 98581bb5..7ed4554c 100644 --- a/patch_nimble.py +++ b/patch_nimble.py @@ -19,16 +19,11 @@ Patch 4 — NimBLEDevice.cpp: Expose host reset reason via global volatile varia global volatile int that application code can poll to capture the reason in UDP logs. """ Import("env") -import os +import os, sys +sys.path.insert(0, env.get("PROJECT_DIR", ".")) +from _build_helpers import env_libdeps_dir # per-env libdeps path; never hardcode the env -NIMBLE_BASE = os.path.join( - env.get("PROJECT_DIR", "."), - # Per-environment libdeps tree (each env gets its own). Was hardcoded to - # "tdeck", so building any OTHER env (e.g. tdeck-ota) patched the wrong tree - # and left nimble_host_reset_reason undefined -> link error. Match the sibling - # pre-scripts (patch_msgpack/filestore/littlefs, sync_file_libdeps). - ".pio", "libdeps", env.get("PIOENV", "tdeck"), "NimBLE-Arduino", "src" -) +NIMBLE_BASE = env_libdeps_dir(env, "NimBLE-Arduino", "src") def apply_patch(filepath, old, new, label): if not os.path.exists(filepath): diff --git a/src/main.cpp b/src/main.cpp index 2f2939c0..e22cc478 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -682,7 +682,9 @@ void on_wifi_connected() { }); ArduinoOTA.onError([](ota_error_t error) { ERROR("OTA: Error"); }); ArduinoOTA.begin(); - INFO("OTA: Ready"); + // ArduinoOTA.begin() returns void, so this is "started", not a verified-ready + // state -- log the target instead of claiming readiness we can't confirm. + INFO("OTA: wireless flash service started (pyxis-tdeck:3232)"); // Initialize UDP log broadcasting (multicast group 239.0.99.99:9999) udp_log_init(); diff --git a/sync_file_libdeps.py b/sync_file_libdeps.py index 6d6985e4..fed609fe 100644 --- a/sync_file_libdeps.py +++ b/sync_file_libdeps.py @@ -15,8 +15,11 @@ fresh source on every build. """ Import("env") import os +import sys import shutil from pathlib import Path +sys.path.insert(0, env.get("PROJECT_DIR", ".")) +from _build_helpers import env_libdeps_dir # per-env libdeps path; never hardcode the env # (source_dir, libdep_subdir_name) — populated from env vars so the # script doesn't bake any contributor's local checkout path into the @@ -32,7 +35,7 @@ if _micro_reticulum_dir: PROJECT_DIR = Path(env.get("PROJECT_DIR", ".")) ENV_NAME = env.get("PIOENV", "tdeck") -LIBDEPS_BASE = PROJECT_DIR / ".pio" / "libdeps" / ENV_NAME +LIBDEPS_BASE = Path(env_libdeps_dir(env)) def mirror(src: Path, dst: Path):