Commit 730749e
committed
Reland
### What does this PR do?
Relands #54887, which #54925 reverted after it broke E2E jobs on `main`.
Recalling that PR: `go_shim` wraps a tool so that `PATH` lookups of `go`
reach Bazel's hermetic SDK, and so that the tool runs from the current
working directory rather than the runfiles tree, superseding
`rules_multitool`'s `cwd()`.
It wraps `gotestsum` and `go_mod_tidy_all`, the latter dropping the
`$(rlocationpath @rules_go//go)` resolution it had grown for itself and
moving to its own package, where the shim taking over
`//:go_mod_tidy_all` leaves its `py_binary` the plain name.
Changed on top of it: `PATH` now holds the Go SDK's own `go`, resolved
through `@rules_go//go:toolchain`, in place of `@rules_go//go`.
The wrapper exports `GOROOT` and sets `GOTOOLCHAIN=local` itself rather
than leaning on `.bazelrc`, and `RUNFILES_DIR` goes away with the
launcher that needed it.
### Motivation
Unbreak `dda inv test` on hosts whose ambient `go` differs from the one
`go.work` requires,
[reported](https://dd.slack.com/archives/C06PBHLD4DQ/p1786618886362859)
by @vitkyrka and followed up by @pgimalac and @hush-hush.
#54107 routed it through `bazel run //internal/tools:gotestsum`,
bringing `gotestsum` under `.bazelrc`'s `--run_env=GOTOOLCHAIN=local`
while it still resolved `go` through `PATH`, so every invocation failed
with `go.work requires go >= 1.26.5` and exporting `GOTOOLCHAIN=auto`
did not help.
That fix then broke `main`, because `@rules_go//go` is a launcher rather
than a `go`: it assigns `cmd.Dir` from `$BUILD_WORKING_DIRECTORY` on
every exec, discarding the directory its caller chose.
`gotest-custom` chooses one per test package, so each prebuilt E2E test
binary ran at the repository root and no longer found its fixtures,
failing on `compose/data`, `usmtest/test_tags.ps1`, `testdataprovision`
and `checks/shared-library/files`.
The SDK's `go` honors its caller, which is the whole of the difference.
### Describe how you validated your changes
On Linux, a child `go` invoked from `test/new-e2e` under the shim
reports that module's `go.mod`, where #54887 reported the repository
root's.
Building a program importing `net/http` through the shim links,
confirming the SDK's sources and tools are reachable.
The reported reproducer still holds: with a stub announcing itself as go
1.24.0 first in `PATH`, tools reach go1.26.5 and never the stub, and
`bazel run //:go_mod_tidy_all -- -diff` exits 0 across every module.
### Additional Notes
Prepending to `PATH` has no declarative spelling: `RunEnvironmentInfo`
carries static strings only, a key given in both `environment` and
`inherited_environment` resolves to the inherited value, and replacing
`PATH` outright would hide `sh`, `cc`, `git` and whatever else the
toolchain reaches for.
Hence a (thin) wrapper reading the environment at runtime.
The runfiles mirror `go_bin_for_host`, rules_go's own definition of a
runnable `go`: the SDK binary plus its headers, libs, sources and tools.
`install_gotestsum` and its per-platform variants keep extracting the
raw binary, the shim being runfiles-bound and those tools driving
pre-built test binaries through `--raw-command`, never resolving `go`.go_shim, replacing go runner by SDK's raw go
1 parent a0a423d commit 730749e
10 files changed
Lines changed: 95 additions & 24 deletions
File tree
- bazel
- rules
- go_mod_tidy_all
- go_shim
- tools
- internal/tools
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
992 | 992 | | |
993 | 993 | | |
994 | 994 | | |
| 995 | + | |
995 | 996 | | |
996 | 997 | | |
997 | 998 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
| 15 | + | |
15 | 16 | | |
16 | 17 | | |
17 | 18 | | |
| |||
123 | 124 | | |
124 | 125 | | |
125 | 126 | | |
126 | | - | |
| 127 | + | |
127 | 128 | | |
128 | | - | |
| 129 | + | |
129 | 130 | | |
130 | 131 | | |
131 | 132 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
Lines changed: 9 additions & 11 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
15 | | - | |
16 | 15 | | |
17 | | - | |
18 | | - | |
19 | | - | |
| 16 | + | |
| 17 | + | |
20 | 18 | | |
21 | 19 | | |
22 | 20 | | |
| |||
30 | 28 | | |
31 | 29 | | |
32 | 30 | | |
33 | | - | |
| 31 | + | |
34 | 32 | | |
35 | 33 | | |
36 | | - | |
| 34 | + | |
37 | 35 | | |
38 | | - | |
| 36 | + | |
39 | 37 | | |
40 | 38 | | |
41 | | - | |
42 | | - | |
| 39 | + | |
| 40 | + | |
43 | 41 | | |
44 | 42 | | |
45 | 43 | | |
46 | 44 | | |
47 | | - | |
| 45 | + | |
48 | 46 | | |
49 | 47 | | |
50 | 48 | | |
51 | 49 | | |
52 | 50 | | |
53 | | - | |
| 51 | + | |
54 | 52 | | |
55 | 53 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
4 | | - | |
5 | | - | |
6 | | - | |
7 | | - | |
8 | | - | |
9 | | - | |
10 | | - | |
11 | | - | |
12 | | - | |
13 | 4 | | |
14 | 5 | | |
15 | 6 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | | - | |
3 | 2 | | |
4 | 3 | | |
| 4 | + | |
5 | 5 | | |
6 | | - | |
| 6 | + | |
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
| |||
0 commit comments