]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/go: go env GOMOD should not download newer toolchain
authorSam Thanawalla <samthanawalla@google.com>
Tue, 23 Apr 2024 17:52:55 +0000 (17:52 +0000)
committerSam Thanawalla <samthanawalla@google.com>
Thu, 25 Apr 2024 16:05:39 +0000 (16:05 +0000)
It is not neccessary to download a newer toolchain to display the path
to GOMOD or GOWORK.

Fixes: #61455
Cq-Include-Trybots: luci.golang.try:gotip-linux-amd64-longtest,gotip-windows-amd64-longtest
Change-Id: I0b031651ad9bfeb5565361ecaff6908640ccf9c8
Reviewed-on: https://go-review.googlesource.com/c/go/+/581275
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Michael Matloob <matloob@golang.org>
src/cmd/go/internal/toolchain/select.go
src/cmd/go/testdata/script/env_gomod_issue61455.txt [new file with mode: 0644]

index 6181f7c480ad110bb0783cde439f51bca4f43505..79f12f34bd0f0b313197409bce8d739f7354695c 100644 (file)
@@ -110,6 +110,14 @@ func Select() {
                return
        }
 
+       // As a special case, let "go env GOMOD" and "go env GOWORK" be handled by
+       // the local toolchain. Users expect to be able to look up GOMOD and GOWORK
+       // since the go.mod and go.work file need to be determined to determine
+       // the minimum toolchain. See issue #61455.
+       if len(os.Args) == 3 && os.Args[1] == "env" && (os.Args[2] == "GOMOD" || os.Args[2] == "GOWORK") {
+               return
+       }
+
        // Interpret GOTOOLCHAIN to select the Go toolchain to run.
        gotoolchain := cfg.Getenv("GOTOOLCHAIN")
        gover.Startup.GOTOOLCHAIN = gotoolchain
diff --git a/src/cmd/go/testdata/script/env_gomod_issue61455.txt b/src/cmd/go/testdata/script/env_gomod_issue61455.txt
new file mode 100644 (file)
index 0000000..8a94549
--- /dev/null
@@ -0,0 +1,24 @@
+env TESTGO_VERSION=go1.500
+env TESTGO_VERSION_SWITCH=mismatch
+
+# go env GOMOD should not trigger a toolchain download
+cd $GOPATH/mod
+go env GOMOD
+stdout mod[/\\]go.mod
+! stderr 'go: toolchain go1.500 invoked to provide go1.700'
+
+# go env GOWORK should not trigger a toolchain download
+cd $GOPATH/work
+go env GOWORK
+stdout work[/\\]go.work
+! stderr 'go: toolchain go1.500 invoked to provide go1.700'
+
+-- $GOPATH/mod/go.mod --
+module example.com
+
+go 1.700
+
+-- $GOPATH/work/go.work --
+module example.com
+
+go 1.700
\ No newline at end of file