# Hazelwood PlatformIO pre-script (personal branch, not in the upstream fork). Injected by # ./local_build.sh through PLATFORMIO_EXTRA_SCRIPTS; rewrites FIRMWARE_VERSION # to the Hazelwood display label before PlatformIO parses the build flags. # # repeater/room/sensor: hazelwood_repeater v1.17.1.10 (core v1.17.1) # companion: v1.17.1.10 hazelwood (core v1.17.1) # with local code changes the version gains -hz.N and/or .dirty (local_build.sh) # # Companions keep the version first because the app's device-info frame # carries only the first 19 characters (companion MyMesh.cpp strzcpy(..., 20)). # LoRa OTA (EndF trailer, ota self, lora_ota.py) packs the first X.Y.Z[.W] in # the string, so it sees v1.17.1.10; the local identifier is display-only. # # Observer targets are left untouched: their HTTP pull-OTA parses the commit # hash after the last '-' of FIRMWARE_VERSION. import os import re Import("env") # noqa: F821 version = os.environ.get("LOCAL_FW_VERSION", "").strip() core = os.environ.get("LOCAL_FW_CORE_VERSION", "").strip() name = os.environ.get("LOCAL_FW_NAME", "hazelwood").strip() pioenv = env["PIOENV"].lower() # noqa: F821 ROLES = ( ("companion_radio", "companion"), ("observer", None), ("room_server", "room_server"), ("repeater", "repeater"), ("sensor", "sensor"), ("kiss", "kiss_modem"), ) def role_for(env_name): for token, role in ROLES: if token in env_name: return role return "firmware" role = role_for(pioenv) if version and core and role is not None: if role == "companion": label = f"{version} {name} (core v{core})" else: label = f"{name}_{role} {version} (core v{core})" # Plain quotes: PlatformIO escapes them and SCons wraps the spaced value. define = "-DFIRMWARE_VERSION='\"" + label + "\"'" pattern = re.compile(r"""-D\s?FIRMWARE_VERSION=(?:'[^']*'|"[^"]*"|\S+)""") flags = env.get("BUILD_FLAGS", []) # noqa: F821 if isinstance(flags, str): flags = [flags] replaced = False new_flags = [] for flag in flags: updated, count = pattern.subn(lambda _m: define, str(flag)) replaced = replaced or count > 0 new_flags.append(updated) if not replaced: new_flags.append(define) env.Replace(BUILD_FLAGS=new_flags) # noqa: F821 # deduplicate_full_build_flags.py (ESP32 FULL) re-reads this overlay; keep # it identical so the label is not treated as a foreign flag. overlay = os.environ.get("PLATFORMIO_BUILD_FLAGS", "") if overlay: os.environ["PLATFORMIO_BUILD_FLAGS"] = pattern.sub(lambda _m: define, overlay) print(f"Local firmware label: {label}")