When adding support for module tools, we added the ability for `go tool`
to edit the module cache. For users with `GOFLAGS=-modcacherw` this
could have led to a situation where some of the files in the mod cache
were unexpectedly not deletable.
We also allow -modfile so that people can select which module they are
working in when looking for tools.
We still do not support arbitrary build flags for tools with `go tool`.
If you want those, use `go run` or `go build`, etc. instead.
Updates #48429
Change-Id: Ic3c56bb8b6ba46114196465ca6ee2dcb08b9dcc0
Reviewed-on: https://go-review.googlesource.com/c/go/+/632575
Reviewed-by: Michael Matloob <matloob@golang.org>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
func init() {
base.AddChdirFlag(&CmdTool.Flag)
+ base.AddModCommonFlags(&CmdTool.Flag)
CmdTool.Flag.BoolVar(&toolN, "n", false, "")
}
! go mod verify
[!root] ! cp $WORK/extraneous.txt $GOPATH/pkg/mod/rsc.io/quote@v1.5.2/go.mod
+# Repeat part of the test with 'go tool'
+go mod edit -tool example.com/tools/cmd/hello -require example.com/tools@v1.0.0
+go mod download -modcacherw example.com/tools
+go clean -modcache
+go tool -modcacherw hello
+cp $WORK/extraneous.txt $GOPATH/pkg/mod/example.com/tools@v1.0.0/extraneous_file.go
+! go mod verify
+[!root] ! cp $WORK/extraneous.txt $GOPATH/pkg/mod/example.com/tools@v1.0.0/cmd/hello/hello.go
+
-- $WORK/extraneous.txt --
module oops
go test -n -mod=mod .
go get rsc.io/quote
+# 'go tool' and tool management should work.
+go get -tool example.com/tools/cmd/hello@v1.0.0
+grep cmd/hello go.alt.mod
+go tool hello
# 'go mod vendor' should work.
go mod vendor