]> Cypherpunks repositories - gostls13.git/commit
cmd/go/internal/cfg: fix GOROOT setting when forcing host config
authorMichael Matloob <matloob@golang.org>
Fri, 30 May 2025 20:16:27 +0000 (16:16 -0400)
committerMichael Matloob <matloob@google.com>
Tue, 3 Jun 2025 14:30:34 +0000 (07:30 -0700)
commit792548a4835f019b40bf8bd4442c893eae280467
tree2feee6db0a2eaf94e4f8aee735e41815c7fcf33c
parent49f63047245a50f4ec38044fc6fa2bc75719726a
cmd/go/internal/cfg: fix GOROOT setting when forcing host config

We manage the state using a bunch of global config, so we need to make
sure we're doing things in the right order. In this case, the SetGOROOT
function was being called in init, setting the GOROOT on the global
Context, but when we reset the context in ForceHost we lost the goroot
configuration. We need to call SetGOROOT in ForceHost to re-set the
GOROOT on the new context.

This was uncovered by CL 677558 because a go command that was built with
trimpath would try to use its runtime.GOROOT(), which wouldn't be valid
in trimpath mode. Setting GOROOT properly with SetGOROOT will use the
value from findGOROOT, assuming GOROOT isn't set in the environment,
and findGOROOT will try to determine GOROOT using the path of the go
command executable.

For #71867

Change-Id: I731b6c5d859b4504fc128b29ab904e3a2886ff3c
Reviewed-on: https://go-review.googlesource.com/c/go/+/677636
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Michael Matloob <matloob@google.com>
Reviewed-by: Michael Pratt <mpratt@google.com>
src/cmd/go/internal/cfg/cfg.go