]> Cypherpunks.ru repositories - gostls13.git/commit
cmd/go/internal/toolchain: make a best effort to parse 'go run' and 'go install'...
authorBryan C. Mills <bcmills@google.com>
Fri, 1 Dec 2023 19:25:48 +0000 (14:25 -0500)
committerGopher Robot <gobot@golang.org>
Thu, 14 Dec 2023 20:10:04 +0000 (20:10 +0000)
commite44b8b15b19058b7a22a859ab4159f924856f688
treedfcd1307b6da531b25a6e826842bd3c8dc00069e
parent7c282ba12a9078eefab1d6e1a42ca8a1ae723737
cmd/go/internal/toolchain: make a best effort to parse 'go run' and 'go install' flags

When the argument to 'go install' or 'go run' looks like a versioned
package, we make a best effort to switch to a toolchain compatible
with the module containing that package, by fetching its go.mod file
and checking the go version it specifies.

At this point in the code, we have not yet parsed the arguments given
on the command line: instead, we just make a best effort to find one
we can use to select a toolchain version. Since that toolchain may be
newer, the command to install it may also include flags that are only
supported by that Go version — and we don't want to fail due to an
error that would be resolved by switching to a more appropriate
toolchain.

So at this point in the code we can't parse the flags in a way that
will surface errors, but we want to make a best effort to parse the
ones that we know about. It turns out that “parse the flags we know
about” is already a familiar problem: that's also what we do in
'go test', so we can reuse the cmdflag library from that to do the
best-effort pass of parsing.

If it turns out that we don't need to switch toolchains after all,
cmd/go's main function will parse the flags again, and will report any
errors at that point.

This fixes a regression, introduced in CL 497879, which caused
'go install -modcacherw pkg@version' to unset the write bit for
directories created while selecting the toolchain to use.

Fixes #64282.
Updates #57001.

Change-Id: Icc409c57858aa15c7d58a97a61964b4bc2560547
Cq-Include-Trybots: luci.golang.try:gotip-linux-amd64-longtest,gotip-windows-amd64-longtest
Reviewed-on: https://go-review.googlesource.com/c/go/+/546635
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Auto-Submit: Bryan Mills <bcmills@google.com>
Reviewed-by: Michael Matloob <matloob@golang.org>
src/cmd/go/internal/base/goflags.go
src/cmd/go/internal/modfetch/fetch.go
src/cmd/go/internal/test/testflag.go
src/cmd/go/internal/toolchain/exec.go
src/cmd/go/internal/toolchain/select.go
src/cmd/go/internal/vet/vetflag.go
src/cmd/go/main.go
src/cmd/go/testdata/script/install_modcacherw_issue64282.txt [new file with mode: 0644]
src/cmd/go/testdata/script/malformed_gosum_issue62345.txt
src/cmd/go/testdata/script/work_sum_mismatch.txt