crosspoint-reader/scripts/version_hash.py

27 lines
955 B
Python
Raw Normal View History

2026-01-27 13:16:20 -05:00
"""
Build script that adds git hash to CROSSPOINT_VERSION for dev builds.
This script runs during the build process and modifies the CROSSPOINT_VERSION
define to include the short git commit hash, e.g., "0.15.1-dev@7349fbb"
"""
Import("env")
from version_utils import get_git_short_hash
# Only modify version for non-release builds
pio_env = env.get("PIOENV", "default")
if pio_env != "gh_release":
git_hash = get_git_short_hash()
if git_hash:
# Get current build flags and find/replace CROSSPOINT_VERSION
build_flags = env.get("BUILD_FLAGS", [])
new_flags = []
for flag in build_flags:
if "CROSSPOINT_VERSION" in flag and "-dev" in flag:
# Replace -dev with -dev@hash
flag = flag.replace("-dev", f"-dev@{git_hash}")
new_flags.append(flag)
env.Replace(BUILD_FLAGS=new_flags)
print(f"[version_hash] Added git hash to version: @{git_hash}")