fix(version): derive NuttX version from the fork branch name

NUTTX_GIT_TAG_STR was computed by taking the highest nuttx-X.Y.Z tag in
the NuttX submodule, without checking that the tag is an ancestor of the
checkout. The PX4/NuttX fork's tags were last synced in Oct 2022 and
topped out at nuttx-11.0.0, so every build has reported NuttX 11.0.0
regardless of the actual kernel (ver all, AUTOPILOT_VERSION.os_sw_version,
the ULog sys_os_ver_release field). With the nuttx-12.12.0 tag now pushed
for the NuttX 12.12 upgrade (#26215), fresh clones of main would flip to
misreporting 12.12.0 while still running the 10.3-era kernel.

Resolve the version from the fork branch name recorded in .gitmodules
(px4_firmware_nuttx-X.Y.Z+) instead, which is updated atomically with
every kernel change, and fall back to git describe for checkouts that do
not follow the fork convention. Output format is unchanged: vX.Y.Z, as
consumed by version_tag_to_number().

Assisted-by: Claude:claude-fable-5
Signed-off-by: Ramon Roche <mrpollo@gmail.com>
This commit is contained in:
Ramon Roche
2026-09-01 13:55:25 -07:00
parent 5208271705
commit 05e6780eaa

View File

@@ -128,14 +128,31 @@ if (os.path.exists('src/modules/mavlink/mavlink/.git')):
# NuttX
if (os.path.exists('platforms/nuttx/NuttX/nuttx/.git')):
nuttx_git_tags = subprocess.check_output('git -c versionsort.suffix=- tag --sort=v:refname'.split(),
cwd='platforms/nuttx/NuttX/nuttx', stderr=subprocess.STDOUT).decode('utf-8').strip()
# may be empty if shallow clone
if (len(nuttx_git_tags) > 0):
nuttx_git_tag = re.findall(r'nuttx-[0-9]+\.[0-9]+\.[0-9]+', nuttx_git_tags)[-1].replace("nuttx-", "v")
nuttx_git_tag = re.sub('-.*', '.0', nuttx_git_tag)
# The PX4/NuttX fork branch name recorded in .gitmodules is the
# authoritative kernel version: px4_firmware_nuttx-X.Y.Z+ is updated
# in the same commit as every kernel upgrade. Fall back to git
# describe for checkouts that do not follow the fork convention
# (e.g. upstream apache/nuttx directly, which carries release tags).
nuttx_git_tag = "v0.0.0"
try:
nuttx_branch = subprocess.check_output(
'git config -f .gitmodules submodule.platforms/nuttx/NuttX/nuttx.branch'.split(),
stderr=subprocess.STDOUT).decode('utf-8').strip()
branch_version = re.match(r'^px4_firmware_nuttx-([0-9]+\.[0-9]+\.[0-9]+)\+?$', nuttx_branch)
except subprocess.CalledProcessError:
branch_version = None
if branch_version:
nuttx_git_tag = "v" + branch_version.group(1)
else:
nuttx_git_tag = "v0.0.0"
try:
nuttx_describe = subprocess.check_output(
'git describe --tags --match nuttx-*'.split(),
cwd='platforms/nuttx/NuttX/nuttx', stderr=subprocess.STDOUT).decode('utf-8').strip()
describe_version = re.match(r'^nuttx-([0-9]+\.[0-9]+\.[0-9]+)', nuttx_describe)
if describe_version:
nuttx_git_tag = "v" + describe_version.group(1)
except subprocess.CalledProcessError:
pass
nuttx_git_version = subprocess.check_output('git rev-parse --verify HEAD'.split(),
cwd='platforms/nuttx/NuttX/nuttx', stderr=subprocess.STDOUT).decode('utf-8').strip()
nuttx_git_version_short = nuttx_git_version[0:16]