-
Notifications
You must be signed in to change notification settings - Fork 17.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[release-branch.go1.22] cmd/go/internal/toolchain: apply the -modcach…
…erw flag when downloading a module to determine what toolchain it needs Fixes #64282. Change-Id: I3f211c599ee70cb58254d0bc07eeb3c135124e58 Reviewed-on: https://go-review.googlesource.com/c/go/+/555436 Auto-Submit: Bryan Mills <bcmills@google.com> Reviewed-by: Russ Cox <rsc@golang.org> (cherry picked from commit cc38c68) Reviewed-on: https://go-review.googlesource.com/c/go/+/559218 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
- Loading branch information
Showing
2 changed files
with
149 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
src/cmd/go/testdata/script/install_modcacherw_issue64282.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
# Regression test for https://go.dev/issue/64282. | ||
# | ||
# 'go install' and 'go run' with pkg@version arguments should make | ||
# a best effort to parse flags relevant to downloading modules | ||
# (currently only -modcacherw) before actually downloading the module | ||
# to identify which toolchain version to use. | ||
# | ||
# However, the best-effort flag parsing should not interfere with | ||
# actual flag parsing if we don't switch toolchains. In particular, | ||
# unrecognized flags should still be diagnosed after the module for | ||
# the requested package has been downloaded and checked for toolchain | ||
# upgrades. | ||
|
||
|
||
! go install -cake=delicious -modcacherw example.com/printversion@v0.1.0 | ||
stderr '^flag provided but not defined: -cake$' | ||
# Because the -modcacherw flag was set, we should be able to modify the contents | ||
# of a directory within the module cache. | ||
cp $WORK/extraneous.txt $GOPATH/pkg/mod/example.com/printversion@v0.1.0/extraneous_file.go | ||
go clean -modcache | ||
|
||
|
||
! go install -unknownflag -tags -modcacherw example.com/printversion@v0.1.0 | ||
stderr '^flag provided but not defined: -unknownflag$' | ||
cp $WORK/extraneous.txt $GOPATH/pkg/mod/example.com/printversion@v0.1.0/extraneous_file.go | ||
go clean -modcache | ||
|
||
|
||
# Also try it with a 'go install' that succeeds. | ||
# (But skip in short mode, because linking a binary is expensive.) | ||
[!short] go install -modcacherw example.com/printversion@v0.1.0 | ||
[!short] cp $WORK/extraneous.txt $GOPATH/pkg/mod/example.com/printversion@v0.1.0/extraneous_file.go | ||
[!short] go clean -modcache | ||
|
||
|
||
# The flag should also be applied if given in GOFLAGS | ||
# instead of on the command line. | ||
env GOFLAGS=-modcacherw | ||
! go install -cake=delicious example.com/printversion@v0.1.0 | ||
stderr '^flag provided but not defined: -cake$' | ||
cp $WORK/extraneous.txt $GOPATH/pkg/mod/example.com/printversion@v0.1.0/extraneous_file.go | ||
|
||
|
||
-- $WORK/extraneous.txt -- | ||
This is not a Go source file. |