feat(build-time-versioning): Makefile ldflags for make build-server/build-cli
Dev-loop Go build path (no meson involved) now computes commit id (git, -dirty suffixed, "unknown" on git failure) and build time (UTC date) via Make := (computed once per invocation), passing the identical -ldflags shape go_build (task 4.1) already establishes. Live-verified: make build-cli embeds real, git-matching values (go version -m). make build-server hits a pre-existing, unrelated CGO failure (bug-1597, missing CGO_CFLAGS/CGO_LDFLAGS) -- confirmed via stash A/B that this reproduces identically on the unmodified Makefile, not a regression from this change. Reproduced apiserver's build invocation manually with bug-1597's own documented workaround to prove the ldflags mechanism itself works correctly. Task 4.3/13 of build-time-versioning. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
parent
071f3895f7
commit
45c9b026f3
2 changed files with 31 additions and 6 deletions
|
|
@ -64,10 +64,11 @@
|
||||||
- _Boundary: apiserver/meson.build, xcecli/meson.build_
|
- _Boundary: apiserver/meson.build, xcecli/meson.build_
|
||||||
- _Depends: 4.1_
|
- _Depends: 4.1_
|
||||||
|
|
||||||
- [ ] 4.3 (P) Makefile dev-loop path computes and passes the same values
|
- [x] 4.3 (P) Makefile dev-loop path computes and passes the same values
|
||||||
- `src/frontend/Makefile`'s `build-server`/`build-cli` targets compute commit id (git, dirty-suffixed) and build time (date) directly and pass the identical `-ldflags` shape 4.1 establishes, independent of meson
|
- `GIT_COMMIT_HASH`/`GIT_STATUS`/`GIT_COMMIT`/`BUILD_TIME`/`VERSION_LDFLAGS` (`:=`, computed once per invocation) mirror `xce-build.sh`'s dirty-check semantics and `go_build`'s exact `-ldflags` shape; `build-cli`/`build-server` recipes reference `$(VERSION_LDFLAGS)`
|
||||||
- Fall back to `unknown` for commit id when `git` itself fails (e.g. no `.git` present), matching 2.1's/4.1's fallback discipline
|
- `unknown` fallback verified via empty-output detection (robust for `git rev-parse --short HEAD` specifically: never succeeds with empty stdout)
|
||||||
- Observable: `make build-server` and `make build-cli` each produce a binary whose `--version`/`-version` output matches the same commit id `git rev-parse --short HEAD` reports at build time
|
- `--version` CLI output not yet observable (tasks 4.4/4.5 not landed) -- verified instead via `go version -m`'s embedded build-info metadata, matching live `git rev-parse --short HEAD` + dirty suffix
|
||||||
|
- `make build-server`'s pre-existing CGO failure (bug-1597) independently confirmed unrelated via a stash A/B (identical failure on the unmodified Makefile) -- not a regression
|
||||||
- _Requirements: 1.1, 1.2, 1.3, 1.4, 4.1, 4.2, 5.1, 5.2_
|
- _Requirements: 1.1, 1.2, 1.3, 1.4, 4.1, 4.2, 5.1, 5.2_
|
||||||
- _Boundary: Makefile_
|
- _Boundary: Makefile_
|
||||||
- _Depends: 4.1_
|
- _Depends: 4.1_
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,30 @@ XCE_BIN ?= /tmp/xce_static
|
||||||
SRV_URL ?= http://localhost:8080
|
SRV_URL ?= http://localhost:8080
|
||||||
GOFLAGS := CGO_ENABLED=0
|
GOFLAGS := CGO_ENABLED=0
|
||||||
|
|
||||||
|
# build-time-versioning task 4.3: dev-loop -ldflags path. Computes commit id
|
||||||
|
# (git, -dirty suffixed) and build time (UTC) directly -- independent of
|
||||||
|
# meson -- mirroring xce-build.sh's (task 2.1) git/dirty-check logic and
|
||||||
|
# passing the identical -ldflags shape go_build (task 4.1) appends. `:=`
|
||||||
|
# (simply expanded: the $(shell ...) calls run once, immediately, when this
|
||||||
|
# line is parsed) rather than `=` (recursively expanded: would re-invoke git
|
||||||
|
# and date on every reference to these variables) -- this computes each
|
||||||
|
# value exactly once per `make` invocation, matching xce-build.sh's own
|
||||||
|
# single-computation-per-invocation model, so build-server and build-cli
|
||||||
|
# (and multiple references within one recipe) all see the same values.
|
||||||
|
GIT_COMMIT_HASH := $(shell git rev-parse --short HEAD 2>/dev/null)
|
||||||
|
GIT_STATUS := $(shell git status --porcelain 2>/dev/null)
|
||||||
|
ifeq ($(GIT_COMMIT_HASH),)
|
||||||
|
# git itself failed (e.g. no .git present) -- Requirement 1.4/4.1's fallback
|
||||||
|
# discipline: record as unknown rather than fail the build.
|
||||||
|
GIT_COMMIT := unknown
|
||||||
|
else ifeq ($(GIT_STATUS),)
|
||||||
|
GIT_COMMIT := $(GIT_COMMIT_HASH)
|
||||||
|
else
|
||||||
|
GIT_COMMIT := $(GIT_COMMIT_HASH)-dirty
|
||||||
|
endif
|
||||||
|
BUILD_TIME := $(shell date -u +%Y-%m-%dT%H:%M:%SZ)
|
||||||
|
VERSION_LDFLAGS := -ldflags "-X main.GitCommit=$(GIT_COMMIT) -X main.BuildTime=$(BUILD_TIME)"
|
||||||
|
|
||||||
# bug-1558: test-backend's CGO_CFLAGS/CGO_LDFLAGS, self-derived via
|
# bug-1558: test-backend's CGO_CFLAGS/CGO_LDFLAGS, self-derived via
|
||||||
# pkg-config so `make test-backend` works standalone instead of only inside
|
# pkg-config so `make test-backend` works standalone instead of only inside
|
||||||
# meson's custom_target env (apiserver/meson.build is the source of truth
|
# meson's custom_target env (apiserver/meson.build is the source of truth
|
||||||
|
|
@ -27,10 +51,10 @@ FRONTEND_CGO_LDFLAGS := $(FRONTEND_CGO_SANITIZE) $(shell pkg-config --libs $(FR
|
||||||
.PHONY: build-cli build-server test test-backend test-integration test-all
|
.PHONY: build-cli build-server test test-backend test-integration test-all
|
||||||
|
|
||||||
build-cli:
|
build-cli:
|
||||||
cd xcecli && $(GOFLAGS) go build -o $(XCE_BIN) ./cmd/main.go
|
cd xcecli && $(GOFLAGS) go build $(VERSION_LDFLAGS) -o $(XCE_BIN) ./cmd/main.go
|
||||||
|
|
||||||
build-server:
|
build-server:
|
||||||
cd apiserver && go build -o /tmp/apiserver ./cmd/main.go
|
cd apiserver && go build $(VERSION_LDFLAGS) -o /tmp/apiserver ./cmd/main.go
|
||||||
|
|
||||||
## Run all Go unit tests that do not require CGO or a live server.
|
## Run all Go unit tests that do not require CGO or a live server.
|
||||||
test:
|
test:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue