Skip to content

Commit a937d1e

Browse files
committed
Build go-licenses with the same toolchain as the main module
go-licenses decides whether a package is part of the standard library by comparing its directory against the GOROOT it was compiled with. The Makefile builds go-licenses from the tools/ module but runs it against the main module, and with GOTOOLCHAIN=auto those can resolve to different toolchains (tools/go.mod has `toolchain go1.24.1`, go.mod has `go 1.25.0`). When that happens every stdlib package is reported as "does not have module info" and `make container` fails. This does not show up in CI because CI pins a Go version that satisfies both modules, but it reproduces with any host Go older than the main module's `go` line: docker run --rm -e GOTOOLCHAIN=auto -v "$PWD":/src -w /src \ golang:1.23.0 make .licenses Pin GOTOOLCHAIN for the tools build to the version the main module resolves to, so both steps use the same GOROOT.
1 parent cf98d83 commit a937d1e

1 file changed

Lines changed: 6 additions & 0 deletions

File tree

‎Makefile‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,10 +163,16 @@ DOTFILE_IMAGE = $(subst /,_,$(IMAGE))-$(OS_ARCH_TAG)
163163

164164
LICENSES = .licenses
165165

166+
# go-licenses identifies stdlib packages by its compiled-in GOROOT, so it must
167+
# be built with the same toolchain that the main module selects when it runs
168+
# `go list`. Otherwise (e.g. with GOTOOLCHAIN=auto and an older host Go) the
169+
# tools module and the main module can resolve to different toolchains, and
170+
# every stdlib package is reported as "does not have module info".
166171
$(LICENSES):
167172
pushd tools >/dev/null; \
168173
export GOOS=$(shell go env GOHOSTOS); \
169174
export GOARCH=$(shell go env GOHOSTARCH); \
175+
export GOTOOLCHAIN=$(shell go env GOVERSION); \
170176
go build -o ../bin/tools/ github.com/google/go-licenses/v2; \
171177
popd >/dev/null
172178
rm -rf $(LICENSES)

0 commit comments

Comments
 (0)