]> Cypherpunks repositories - gostls13.git/commit
cmd/go: change go tool to build tools missing from GOROOT/pkg/tool
authorMichael Matloob <matloob@golang.org>
Thu, 6 Feb 2025 21:11:50 +0000 (16:11 -0500)
committerMichael Matloob <matloob@google.com>
Fri, 9 May 2025 19:31:21 +0000 (12:31 -0700)
commit2f2f8fe2e810747fecf6d3366d7b76eb65352ee1
treefee523b839972ca786713cab8c32d7185d5048f7
parentd73aa535ded764933aa63e4c2c8fb34e479270cb
cmd/go: change go tool to build tools missing from GOROOT/pkg/tool

If a tool in cmd is not installed in $GOROOT/pkg/tool/${GOOS}_${GOARCH},
go tool will build (if it's not cached) and run it in a similar way
(with some changes) to how tools declared with tool directives are built
and run.

The main change in how builtin tools are run as compared to mod tools is
that they are built "in host mode" using the running go command's GOOS
and GOARCH. The "-exec" flag is also ignored and we don't add GOROOT/bin
to the PATH.

A ForceHost function has been added to the cfg package to force the
configuration to runtime.GOOS/runtime.GOARCH. It has to recompute the
BuildContext because it's normally determined at init time but we're
changing it after we realize we're running a builtin tool. (Detecting
that we're running a builtin tool at init time would mean replicating
the cmd line parsing logic so recomputing BuildContext sounds like the
smaller change.)

For #71867

Change-Id: I3b2edf2cb985c1dcf5f845fbf39b7dc11dea4df7
Reviewed-on: https://go-review.googlesource.com/c/go/+/666476
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Michael Pratt <mpratt@google.com>
Reviewed-by: Michael Matloob <matloob@google.com>
src/cmd/go/internal/base/tool.go
src/cmd/go/internal/cfg/cfg.go
src/cmd/go/internal/tool/tool.go
src/cmd/go/internal/work/exec.go
src/cmd/go/internal/work/gc.go
src/cmd/go/internal/work/init.go
src/cmd/go/testdata/script/tool_build_as_needed.txt [new file with mode: 0644]