Repository navigation
build: share the Go build cache across worktrees with -trimpath - #765
EricAndrechek wants to merge 4 commits into
Conversation
Go keys this module's own packages in the build cache by absolute directory, so every worktree compiled and cached its own copy of each variant (normal, test, -race, -cover). The Makefile now exports GOFLAGS=-trimpath, keeping any GOFLAGS the caller passes; CI runs the same targets and inherits it. The two tests that located repository files with runtime.Caller, whose path is module-relative under -trimpath, now find the root from the working directory: natstest walks up to go.mod, and the roles test builds from two levels above its package directory. Closes #763. Part of #740. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Guard the Makefile prepend so recursive makes and callers that already name -trimpath do not stack it, and -trimpath=false opts out. The debug build passes -trimpath=false so debuggers find absolute source paths. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
# Conflicts: # Makefile
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configuration
📒 Files selected for processing (6)
Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review. 📜 Recent review details🧰 Additional context used📚 Code guidelines (3)📓 Path-based instructions (8)Source excerpt: **Never hand-write `®` or `™` in prose.**📄 CodeRabbit inference engine (AGENTS.md) Files:
Source excerpt: **Integration test needing Docker** → add a subtest under `tests/integration/` (e.g.📄 CodeRabbit inference engine (docs/src/content/docs/development.md) Files:
Source excerpt: Create `*_test.go` files in the same package as the code under test.📄 CodeRabbit inference engine (AGENTS.md) Files:
Source excerpt: Create the package under `internal/`.📄 CodeRabbit inference engine (AGENTS.md) Files:
Source excerpt: **WH001 applies to every tracked Markdown file, with no carve-out** — `AGENTS.md`, `CHANGELOG.md`, `.github/` CI docs and `.claude/` agent prompts included.📄 CodeRabbit inference engine (AGENTS.md) Files:
Source excerpt: **Strict Go formatting**: Use `gofumpt` (a stricter superset of `gofmt`, enforced by CI).📄 CodeRabbit inference engine (docs/src/content/docs/development.md) Files:
Source excerpt: **Docs prose**: never hard-wrap Markdown — one paragraph is one line.📄 CodeRabbit inference engine (CONTRIBUTING.md) Files:
Source excerpt: Run `make fix` to apply them.📄 CodeRabbit inference engine (docs/src/content/docs/development.md) Files:
🪛 LanguageToolCHANGELOG.md[typographical] ~54-~54: Consider using an em dash in dialogues and enumerations. (DASH_RULE) [style] ~54-~54: Since ownership is already implied, this phrasing may be redundant. (PRP_OWN) 📝 SummarySummary by CodeRabbit
WalkthroughThe Makefile now enables ChangesGo build path handling
Priority: ➖ Normal Estimated code review effort: 2 (Simple) | ~12 minutes Change: Other · Severity of issue fixed: Medium Suggested reviewers: Merge Risk: ⚪ Minimal · up to The reviewed build and test path changes show no concrete issue that should block merging. 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
✨ Simplify code
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
@coderabbitai review |
|
|
@coderabbitai review |
|
|
@coderabbitai review |
|
|
@coderabbitai review |
✅ Action performedReview finished.
|
|
Superseded by #793: the same change (identical diff, which CodeRabbit approved here) rebuilt directly on — Posted by Claude Code on behalf of @EricAndrechek |
Go keys this module's own packages in the build cache by absolute directory, so every worktree compiled and cached its own copy of each variant (normal, test, `-race`, `-cover -coverpkg=./...`), and Go only evicts entries unused for five days. `-trimpath` makes the entries path-independent. - **Makefile.** Exports `GOFLAGS=-trimpath`, keeping any `GOFLAGS` the caller passes (also when given on the `make` command line). A `GOFLAGS` that already names `-trimpath` is left alone, so sub-makes don't prepend it again and `GOFLAGS=-trimpath=false make …` opts out. CI runs the same targets and inherits it. No workflow or `.goreleaser.yaml` change: they have no direct `go build`/`go test` calls that matter here, and release-build paths are #537. - **Path anchors.** `natstest.repoFile` walks up from the working directory to `go.mod`, because tests in several packages import it. The roles integration test builds the binary from two levels above its package directory, which is where `go test` runs it. Nothing else uses `runtime.Caller`; `debug.Stack` in `internal/api/router.go` only feeds a log field. - **Debugging.** `make build`'s debug binary is exempt (`scripts/build.sh` passes `-trimpath=false`) and keeps absolute source paths for Delve. Other binaries are trimmed and need a source-path substitution; `development.md` has the `dlv` example. ## Test plan This branch's diff is identical to #765's (same 6 files, +40/−11, compared line by line), which CodeRabbit approved. Re-run here against `main`: the pre-commit `make verify` and a full `make ci` (unit suite, integration suite including `TestRoles`, and the builds). The three measurement items below were measured on #765 and not repeated. - [x] `go test -trimpath -count=1 ./internal/mq/...` passes (inside `make ci`'s unit suite). - [x] `go test -trimpath -tags integration -run TestRoles ./tests/integration/` passes (inside `make ci`'s integration suite). - [x] `make test-unit` passes under the new flags (inside `make ci`). The profile naming files by import path, and `gocover-cobertura` emitting repo-relative filenames that all exist, were measured on #765. - [x] `make verify` passes. - [ ] (measured on #765) Cache sharing, counting `compile` steps of `go test -c -x ./internal/api` in a second checkout of the same commit: 0 with `-trimpath`, 23 without. - [ ] (measured on #765) A recursive make probe shows `GOFLAGS` stable at depth 0, 1 and 2 with it unset, in the environment, on the command line, and set to `-trimpath=false`. - [ ] (measured on #765) `make build`'s binary has absolute source paths; `make build-release`'s has none. - [x] `make ci` passes. ## Related Issues Closes #763. Related: #537 (`-trimpath` for release builds). Part of #740. Supersedes #765 (rebuilt on `main`, no longer stacked on #760). 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01Wjv2nu841pxTMdUWSAPmDH Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Summary
Go keys this module's own packages in the build cache by absolute directory, so every worktree compiled and cached its own copy of each variant (normal, test,
-race,-cover -coverpkg=./...), and Go only evicts entries unused for five days.-trimpathmakes the entries path-independent.GOFLAGS=-trimpath, keeping anyGOFLAGSthe caller passes (also when given on themakecommand line). AGOFLAGSthat already names-trimpathis left alone, so sub-makes don't prepend it again andGOFLAGS=-trimpath=false make …opts out. CI runs the same targets and inherits it. No workflow or.goreleaser.yamlchange: they have no directgo build/go testcalls that matter here, and release-build paths are build: add -trimpath to release, container, and goreleaser builds #537.natstest.repoFilewalks up from the working directory togo.mod, because tests in several packages import it. The roles integration test builds the binary from two levels above its package directory, which is wherego testruns it. Nothing else usesruntime.Caller;debug.Stackininternal/api/router.goonly feeds a log field.make build's debug binary is exempt (scripts/build.shpasses-trimpath=false) and keeps absolute source paths for Delve. Other binaries are trimmed and need a source-path substitution;development.mdhas thedlvexample.Test plan
go test -trimpath -count=1 ./internal/mq/...passes.go test -trimpath -tags integration -run TestRoles ./tests/integration/passes (72s).make test-unitpasses under the new flags and writes its profile; the profile names files by import path, andgocover-coberturaover it emits repo-relative filenames that all exist.make verifypasses.compilesteps ofgo test -c -x ./internal/apiin a second checkout of the same commit: 0 with-trimpath, 23 without.GOFLAGSstable at depth 0, 1 and 2 with it unset, in the environment, on the command line, and set to-trimpath=false.make build's binary has absolute source paths;make build-release's has none.make ci(run before pushing).Related Issues
Closes #763. Related: #537 (
-trimpathfor release builds). Stacked on #760 (baselint/markdown-mdx-parser); contains the whole stack below it and today'smain. Part of #740.🤖 Generated with Claude Code