From a937d1e45f04f0a9ed5773ca06a9c75c7c09671f Mon Sep 17 00:00:00 2001 From: tiffanny29631 Date: Wed, 7 Oct 2026 22:21:24 +0000 Subject: [PATCH] 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. --- Makefile | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Makefile b/Makefile index ac4268524..d277c62f6 100644 --- a/Makefile +++ b/Makefile @@ -163,10 +163,16 @@ DOTFILE_IMAGE = $(subst /,_,$(IMAGE))-$(OS_ARCH_TAG) LICENSES = .licenses +# go-licenses identifies stdlib packages by its compiled-in GOROOT, so it must +# be built with the same toolchain that the main module selects when it runs +# `go list`. Otherwise (e.g. with GOTOOLCHAIN=auto and an older host Go) the +# tools module and the main module can resolve to different toolchains, and +# every stdlib package is reported as "does not have module info". $(LICENSES): pushd tools >/dev/null; \ export GOOS=$(shell go env GOHOSTOS); \ export GOARCH=$(shell go env GOHOSTARCH); \ + export GOTOOLCHAIN=$(shell go env GOVERSION); \ go build -o ../bin/tools/ github.com/google/go-licenses/v2; \ popd >/dev/null rm -rf $(LICENSES)