mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
cmd/go: fix two-step toolchain upgrade through go install, GOTOOLCHAIN
If we do one upgrade because of a go install target's go.mod file, we still might need a second upgrade to implement the GOTOOLCHAIN minimum. Instead of allowing a two-step switch (which we were cutting off anyway), skip the first step and go straight to the GOTOOLCHAIN min upgrade. Fixes #69051. Change-Id: I16f060f473574d8b8f84c55fae2fd0cdabc8aa19 Reviewed-on: https://go-review.googlesource.com/c/go/+/637496 Reviewed-by: Michael Matloob <matloob@golang.org> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
This commit is contained in:
parent
4f0561f9d3
commit
cb72406c36
2 changed files with 18 additions and 3 deletions
|
|
@ -169,7 +169,7 @@ func Select() {
|
||||||
}
|
}
|
||||||
|
|
||||||
gotoolchain = minToolchain
|
gotoolchain = minToolchain
|
||||||
if (mode == "auto" || mode == "path") && !goInstallVersion() {
|
if (mode == "auto" || mode == "path") && !goInstallVersion(minVers) {
|
||||||
// Read go.mod to find new minimum and suggested toolchain.
|
// Read go.mod to find new minimum and suggested toolchain.
|
||||||
file, goVers, toolchain := modGoToolchain()
|
file, goVers, toolchain := modGoToolchain()
|
||||||
gover.Startup.AutoFile = file
|
gover.Startup.AutoFile = file
|
||||||
|
|
@ -549,7 +549,7 @@ func modGoToolchain() (file, goVers, toolchain string) {
|
||||||
|
|
||||||
// goInstallVersion reports whether the command line is go install m@v or go run m@v.
|
// goInstallVersion reports whether the command line is go install m@v or go run m@v.
|
||||||
// If so, Select must not read the go.mod or go.work file in "auto" or "path" mode.
|
// If so, Select must not read the go.mod or go.work file in "auto" or "path" mode.
|
||||||
func goInstallVersion() bool {
|
func goInstallVersion(minVers string) bool {
|
||||||
// Note: We assume there are no flags between 'go' and 'install' or 'run'.
|
// Note: We assume there are no flags between 'go' and 'install' or 'run'.
|
||||||
// During testing there are some debugging flags that are accepted
|
// During testing there are some debugging flags that are accepted
|
||||||
// in that position, but in production go binaries there are not.
|
// in that position, but in production go binaries there are not.
|
||||||
|
|
@ -708,7 +708,11 @@ func goInstallVersion() bool {
|
||||||
if errors.Is(err, gover.ErrTooNew) {
|
if errors.Is(err, gover.ErrTooNew) {
|
||||||
// Run early switch, same one go install or go run would eventually do,
|
// Run early switch, same one go install or go run would eventually do,
|
||||||
// if it understood all the command-line flags.
|
// if it understood all the command-line flags.
|
||||||
SwitchOrFatal(ctx, err)
|
var s Switcher
|
||||||
|
s.Error(err)
|
||||||
|
if s.TooNew != nil && gover.Compare(s.TooNew.GoVersion, minVers) > 0 {
|
||||||
|
SwitchOrFatal(ctx, err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return true // pkg@version found
|
return true // pkg@version found
|
||||||
|
|
|
||||||
11
src/cmd/go/testdata/script/gotoolchain_local.txt
vendored
11
src/cmd/go/testdata/script/gotoolchain_local.txt
vendored
|
|
@ -197,6 +197,17 @@ go mod edit -go=1.501 -toolchain=none
|
||||||
go version
|
go version
|
||||||
stdout go1.501
|
stdout go1.501
|
||||||
|
|
||||||
|
# avoid two-step switch, first from install target requirement, then from GOTOOLCHAIN min
|
||||||
|
# instead, just jump directly to GOTOOLCHAIN min
|
||||||
|
env TESTGO_VERSION=go1.2.3
|
||||||
|
env GODEBUG=toolchaintrace=1
|
||||||
|
env GOTOOLCHAIN=go1.23.0+auto
|
||||||
|
! go install rsc.io/fortune/nonexist@v0.0.1
|
||||||
|
! stderr 'switching to go1.22.9'
|
||||||
|
stderr 'using go1.23.0'
|
||||||
|
env GODEBUG=
|
||||||
|
env GOTOOLCHAIN=auto
|
||||||
|
|
||||||
# go install m@v and go run m@v should ignore go.mod and use m@v
|
# go install m@v and go run m@v should ignore go.mod and use m@v
|
||||||
env TESTGO_VERSION=go1.2.3
|
env TESTGO_VERSION=go1.2.3
|
||||||
go mod edit -go=1.999 -toolchain=go1.998
|
go mod edit -go=1.999 -toolchain=go1.998
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue