Files
Winden-Telemetry/extra_script.py
T
2026-08-30 11:25:03 +02:00

27 lines
995 B
Python

import os
from typing import Any
# PlatformIO injects Import() and env at runtime. The editor does not know these
# names at file-load time, so we keep a short, explicit guard and silence the
# static-analysis warning for the SCons hook itself.
try:
Import("env") # type: ignore[name-defined]
except NameError:
env: Any = None
if env is None:
raise RuntimeError("This script must be run by PlatformIO's SCons environment.")
# Access to global construction environment
build_tag = env["PIOENV"]
version_tag = os.getenv("FIRMWARE_VERSION", "dev").strip()
# CPPDEFINES ensures the macro expands to a valid C string literal instead of a bare identifier.
env.Append(CPPDEFINES=[("FIRMWARE_VERSION", f'\\"{version_tag}\\"')])
env.Replace(PROGNAME="firmware_%s_%s" % (build_tag, version_tag))
# include toolchain paths
env.Replace(COMPILATIONDB_INCLUDE_TOOLCHAIN=True)
# override compilation DB path
env.Replace(COMPILATIONDB_PATH=os.path.join("$BUILD_DIR", "compile_commands.json"))