Skip to content

Commit 8c0da42

Browse files
committed
cmd/go: go env GOMOD should not download newer toolchain
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 <[email protected]> Reviewed-by: Michael Matloob <[email protected]>
1 parent 8960925 commit 8c0da42

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

src/cmd/go/internal/toolchain/select.go

+8
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,14 @@ func Select() {
110110
return
111111
}
112112

113+
// As a special case, let "go env GOMOD" and "go env GOWORK" be handled by
114+
// the local toolchain. Users expect to be able to look up GOMOD and GOWORK
115+
// since the go.mod and go.work file need to be determined to determine
116+
// the minimum toolchain. See issue #61455.
117+
if len(os.Args) == 3 && os.Args[1] == "env" && (os.Args[2] == "GOMOD" || os.Args[2] == "GOWORK") {
118+
return
119+
}
120+
113121
// Interpret GOTOOLCHAIN to select the Go toolchain to run.
114122
gotoolchain := cfg.Getenv("GOTOOLCHAIN")
115123
gover.Startup.GOTOOLCHAIN = gotoolchain
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
env TESTGO_VERSION=go1.500
2+
env TESTGO_VERSION_SWITCH=mismatch
3+
4+
# go env GOMOD should not trigger a toolchain download
5+
cd $GOPATH/mod
6+
go env GOMOD
7+
stdout mod[/\\]go.mod
8+
! stderr 'go: toolchain go1.500 invoked to provide go1.700'
9+
10+
# go env GOWORK should not trigger a toolchain download
11+
cd $GOPATH/work
12+
go env GOWORK
13+
stdout work[/\\]go.work
14+
! stderr 'go: toolchain go1.500 invoked to provide go1.700'
15+
16+
-- $GOPATH/mod/go.mod --
17+
module example.com
18+
19+
go 1.700
20+
21+
-- $GOPATH/work/go.work --
22+
module example.com
23+
24+
go 1.700

0 commit comments

Comments
 (0)