feat(build-time-versioning): xceadmin generates build-info module

xceadmin/meson.build passes the resolved commit_id/build_time meson
options as two new positional args (matching this custom_target's
existing all-positional style) to meson-build.sh, which writes a small
_build_info.py (GIT_COMMIT/BUILD_TIME, independent per-field "unknown"
fallback) into the mirrored source tree's xceadmin package directory,
before the pip install step -- same before-install ordering as the
existing schema-sync step. A file-existence guard checks the exact path
just written and fails loudly rather than silently proceeding with a
missing/wrong module.

Live-verified via a full real build+test+wheel cycle (run independently
twice, once by implementation and once by review): the mirrored tree's
_build_info.py and the packaged wheel both contain real, matching,
non-"unknown" values (commit id matching git rev-parse --short HEAD plus
dirty suffix, real UTC timestamp); full pytest suite passes (258 passed,
3 skipped -- documented live-HA e2e tests, skip-by-design).

Task 5.1/13 of build-time-versioning.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
Rongsong Shen 2026-08-20 14:22:45 +00:00
parent fb09afe6be
commit e1cd9d257c
No known key found for this signature in database
GPG key ID: 5BCDAAE0123E9FE2
3 changed files with 55 additions and 5 deletions

View file

@ -91,11 +91,9 @@
- _Depends: 4.1_
- [ ] 5. Core: xceadmin version display
- [ ] 5.1 (P) meson-build.sh generates a build-info module before packaging
- `src/xceadmin/meson.build`'s `custom_target()` passes the resolved commit id/build time to `meson-build.sh` (new positional args or env vars)
- `meson-build.sh` writes a small `_build_info.py` (containing `GIT_COMMIT`/`BUILD_TIME` string constants, `unknown` fallback) into the mirrored source tree's xceadmin package directory, before the existing `pip install` step, matching the schema-sync step's own before-install ordering
- After writing the module, verify it actually landed in the mirrored tree before proceeding to `pip install` (e.g. a file-exists check) and fail the build loudly if it did not, rather than silently packaging the fallback-shaped-but-wrong wheel
- Observable: a meson-driven `/xce-build xceadmin` produces a wheel whose installed `_build_info.py` contains non-`unknown` values when 2.1's values are set
- [x] 5.1 (P) meson-build.sh generates a build-info module before packaging
- `commit_id`/`build_time` passed as 2 new positional args (`$6`/`$7`, matching this custom_target's existing all-positional style); write block sits between schema-sync and `pip install`, with an independent-per-field `unknown` fallback and a file-existence guard checking the exact path it just wrote (the mirrored tree, not the real source tree)
- Observable confirmed live (full real build+test+wheel cycle, independently re-run by review): mirrored tree's `_build_info.py` and the packaged wheel both contain real, matching, non-`unknown` values; 258 tests pass, 3 skips confirmed as documented live-HA e2e tests
- _Requirements: 1.1, 1.2, 1.4, 4.1, 4.2_
- _Boundary: xceadmin/meson.build, xceadmin/meson-build.sh_
- _Depends: 1_

View file

@ -22,6 +22,21 @@ REPO_ROOT="$3" # real repo root (contains ha/, src/)
PYTHON="$4" # meson's resolved python3 (import('python').find_installation()),
# NOT a bare `python3` PATH lookup -- see meson.build's comment
STAMP_FILE="$5"
GIT_COMMIT="$6" # build-time-versioning task 5.1: get_option('commit_id'),
# resolved by xce-build.sh (task 2.1) -- empty if meson was
# invoked without -Dcommit_id= (e.g. a bare `meson setup`)
BUILD_TIME="$7" # build-time-versioning task 5.1: get_option('build_time'), same as above
# Requirement 1.4 / 4.2: never hand the mirrored tree a genuinely empty
# value -- fall back to the literal "unknown", same empty -> "unknown"
# discipline as src/tools/go_build's XCE_GIT_COMMIT/XCE_BUILD_TIME handling
# and src/lib/utils.c's xce_version_field().
if [ -z "$GIT_COMMIT" ]; then
GIT_COMMIT=unknown
fi
if [ -z "$BUILD_TIME" ]; then
BUILD_TIME=unknown
fi
SRC_DIR="$REPO_ROOT/src"
@ -52,6 +67,33 @@ cp "$SRC_DIR/schema/controller.capnp" "$SCHEMA_DST/controller.capnp"
cp "$SRC_DIR/schema/c.capnp" "$SCHEMA_DST/c.capnp"
cp "$SRC_DIR/configs/schema/"*.schema.json "$SCHEMA_DST/json/"
# build-time-versioning task 5.1: generate the build-info module into the
# MIRRORED tree's xceadmin package dir (src/xceadmin/, containing cli.py) --
# never the real, checked-in src/xceadmin/src/xceadmin/ tree, which stays a
# static "unknown"-only fallback stub (task 5.2, separate). Must land before
# `pip install` below, same before-install ordering as the schema sync just
# above, so both the pinned dev-venv install and the wheel built later from
# this same $WORK_DIR package it.
BUILD_INFO_DST="$WORK_DIR/src/xceadmin/_build_info.py"
echo "=== xceadmin (meson): writing generated build-info module ==="
cat > "$BUILD_INFO_DST" <<EOF
# Generated by meson-build.sh (build-time-versioning task 5.1) -- do not edit.
# Overwritten on every meson build; never checked in. See
# src/xceadmin/src/xceadmin/_build_info.py (task 5.2) for the committed,
# "unknown"-only fallback stub used by \`pip install -e .\` editable installs,
# which never run this script.
GIT_COMMIT = "$GIT_COMMIT"
BUILD_TIME = "$BUILD_TIME"
EOF
# Requirement 4.2: never silently proceed to pip install/pytest/wheel-build
# packaging a fallback-shaped-but-actually-missing module -- confirm the
# write actually landed in the mirrored tree first and fail loudly if not.
if [ ! -f "$BUILD_INFO_DST" ]; then
echo "ERROR: xceadmin (meson): failed to write generated build-info module to $BUILD_INFO_DST -- refusing to proceed to pip install with a missing/wrong build-info module." >&2
exit 1
fi
echo "=== xceadmin (meson): pinned install into build-dir venv (python: $PYTHON) ==="
rm -rf "$VENV_DIR"
"$PYTHON" -m venv --system-site-packages "$VENV_DIR"

View file

@ -40,6 +40,16 @@ xceadmin_stamp = custom_target('xceadmin',
meson.current_source_dir() / '..' / '..', # repo root (contains ha/, src/)
python3_prog.full_path(),
'@OUTPUT@',
# build-time-versioning task 5.1: same resolved commit_id/build_time
# option values src/meson.build:30-31 (C) and apiserver/xcecli's
# meson.build (Go, via XCE_GIT_COMMIT/XCE_BUILD_TIME) already thread
# through -- passed here as two more positional args, matching this
# custom_target's existing positional (not env-var) style. Empty when
# unset (meson.options' default); meson-build.sh is responsible for the
# empty -> "unknown" fallback, same discipline as go_build's
# XCE_GIT_COMMIT/XCE_BUILD_TIME handling.
get_option('commit_id'),
get_option('build_time'),
],
build_by_default: true,
build_always_stale: true,