build(version): derive the base version from the upstream tag, not a literal
build_version.py replaced one hardcoded version with another: it stamped "v1.16.0-tth-<sha>" with v1.16.0 written into the script. The SHA made the build identifiable, but the base would have kept claiming v1.16.0 for as long as nobody remembered to edit this file -- the same stale-by- construction string the script exists to eliminate. Now taken from the newest upstream release tag HEAD descends from (`git describe`, upstream tags them per-example as companion-v1.16.0 / repeater-v1.16.0, so match any *v[0-9]* and strip the prefix). Our own release tags carry '+tth.<timestamp>' and are excluded so they cannot shadow the upstream base. Also documents the wiring in the header, because the failure mode is silence: an env that forgets the script builds fine and ships a node that lies about its own version. Verified stamping on all nine envs we flash -- T1000E_cmp_cz, the four XIAO test nodes plus oldble, and the three SenseCap repeaters. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
1 parent
4759954c58
commit
0dbaba046c
1 file changed
+40
-7
+40
-7
@@ -1,22 +1,55 @@
|
||||
# CUSTOM (TeTeHacko): custom version and build date/time for the `ver` command.
|
||||
# Injects FIRMWARE_VERSION (v1.16.0-tth-<git sha>, '+' = dirty tree) and
|
||||
# CUSTOM (TeTeHacko): real version and build timestamp for the `ver` command.
|
||||
#
|
||||
# WIRE THIS INTO EVERY ENV WE FLASH. Without it the node reports the fallback
|
||||
# literal from examples/*/MyMesh.h -- "v1.16.0", "6 Jun 2026" -- which is the
|
||||
# same in every build ever made, so `ver` cannot tell one flash from another.
|
||||
# That is not a cosmetic problem: after a 14-minute BLE DFU onto the T1000-E,
|
||||
# every field the node reported back was byte-for-byte what it said beforehand,
|
||||
# and the only evidence the image had landed was a line in a scrollback buffer.
|
||||
#
|
||||
# extra_scripts = ${nrf52_base.extra_scripts}
|
||||
# pre:tools/build_version.py
|
||||
#
|
||||
# Injects FIRMWARE_VERSION (<upstream tag>-tth-<git sha>, '+' = dirty tree) and
|
||||
# FIRMWARE_BUILD_DATE (compile time). NOTE: the define changes every build =
|
||||
# full rebuild each time (~10-30 s) -- the price for an always-fresh timestamp.
|
||||
Import("env")
|
||||
import subprocess
|
||||
from datetime import datetime
|
||||
|
||||
sha = "nogit"
|
||||
dirty = ""
|
||||
|
||||
def git(cwd, *args):
|
||||
return subprocess.check_output(("git",) + args, cwd=cwd,
|
||||
stderr=subprocess.DEVNULL).decode().strip()
|
||||
|
||||
|
||||
cwd = env.subst("$PROJECT_DIR")
|
||||
|
||||
# The base version follows the newest upstream release tag that HEAD descends
|
||||
# from, rather than being written here as a literal -- a literal would keep
|
||||
# claiming v1.16.0 long after upstream moved on, which is exactly the kind of
|
||||
# stale-by-construction string this script exists to get rid of.
|
||||
# Upstream tags them per-example ("companion-v1.16.0", "repeater-v1.16.0"), so
|
||||
# match anything carrying a v<digit> and strip the prefix. Our own release tags
|
||||
# (`...+tth.<timestamp>`) are excluded so they cannot shadow the upstream base.
|
||||
base = "nover"
|
||||
try:
|
||||
cwd = env.subst("$PROJECT_DIR")
|
||||
sha = subprocess.check_output(["git", "rev-parse", "--short", "HEAD"], cwd=cwd).decode().strip()
|
||||
tag = git(cwd, "describe", "--tags", "--abbrev=0",
|
||||
"--match", "*v[0-9]*", "--exclude", "*+tth*")
|
||||
i = tag.find("v")
|
||||
base = tag[i:] if i >= 0 else tag
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
sha, dirty = "nogit", ""
|
||||
try:
|
||||
sha = git(cwd, "rev-parse", "--short", "HEAD")
|
||||
if subprocess.call(["git", "diff", "--quiet"], cwd=cwd) != 0:
|
||||
dirty = "+"
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
version = "v1.16.0-tth-%s%s" % (sha, dirty)
|
||||
version = "%s-tth-%s%s" % (base, sha, dirty)
|
||||
build_date = datetime.now().strftime("%d %b %Y %H:%M")
|
||||
env.Append(CPPDEFINES=[
|
||||
("FIRMWARE_VERSION", env.StringifyMacro(version)),
|
||||
|
||||
Reference in new issue
Block a user