Commit 6cba4dbf authored by Bryan C. Mills's avatar Bryan C. Mills

cmd/go/internal/list: disallow 'list -m' with '-mod=vendor'

Updates #33848

Change-Id: I81663386297282397ce1b546a8b15597bfbcea78
Reviewed-on: https://go-review.googlesource.com/c/go/+/199821
Run-TryBot: Bryan C. Mills <bcmills@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: default avatarJay Conrod <jayconrod@google.com>
parent 1736f3a1
...@@ -69,6 +69,13 @@ TODO ...@@ -69,6 +69,13 @@ TODO
<code>go.mod</code> file. <code>go.mod</code> file.
</p> </p>
<p>
<code>go</code> <code>list</code> <code>-m</code> no longer silently omits
transitive dependencies that do not provide packages in
the <code>vendor</code> directory. It now fails explicitly if
<code>-mod=vendor</code> is set.
</p>
<p><!-- golang.org/issue/32502, golang.org/issue/30345 --> <p><!-- golang.org/issue/32502, golang.org/issue/30345 -->
The <code>go</code> <code>get</code> command no longer accepts The <code>go</code> <code>get</code> command no longer accepts
the <code>-mod</code> flag. Previously, the flag's setting either the <code>-mod</code> flag. Previously, the flag's setting either
......
...@@ -384,6 +384,9 @@ func runList(cmd *base.Command, args []string) { ...@@ -384,6 +384,9 @@ func runList(cmd *base.Command, args []string) {
if modload.Init(); !modload.Enabled() { if modload.Init(); !modload.Enabled() {
base.Fatalf("go list -m: not using modules") base.Fatalf("go list -m: not using modules")
} }
if cfg.BuildMod == "vendor" {
base.Fatalf("go list -m: can't list modules with -mod=vendor\n\tuse -mod=mod or -mod=readonly to ignore the vendor directory")
}
modload.LoadBuildList() modload.LoadBuildList()
mods := modload.ListModules(args, *listU, *listVersions) mods := modload.ListModules(args, *listU, *listVersions)
......
...@@ -120,7 +120,8 @@ func moduleInfo(m module.Version, fromBuildList bool) *modinfo.ModulePublic { ...@@ -120,7 +120,8 @@ func moduleInfo(m module.Version, fromBuildList bool) *modinfo.ModulePublic {
} }
if cfg.BuildMod == "vendor" { if cfg.BuildMod == "vendor" {
info.Dir = filepath.Join(ModRoot(), "vendor", m.Path) // The vendor directory doesn't contain enough information to reconstruct
// anything more about the module.
return info return info
} }
......
...@@ -6,12 +6,12 @@ env GOPATH=$WORK/empty ...@@ -6,12 +6,12 @@ env GOPATH=$WORK/empty
env GOPROXY=file:///nonexist env GOPROXY=file:///nonexist
go list -mod=vendor go list -mod=vendor
go list -mod=vendor -m -f '{{.Path}} {{.Version}} {{.Dir}}' all go list -mod=vendor -f '{{with .Module}}{{.Path}} {{.Version}}{{end}} {{.Dir}}' all
stdout '^rsc.io/quote v1.5.1 .*vendor[\\/]rsc.io[\\/]quote$' stdout '^rsc.io/quote v1.5.1 .*vendor[\\/]rsc.io[\\/]quote$'
stdout '^golang.org/x/text v0.0.0.* .*vendor[\\/]golang.org[\\/]x[\\/]text$' stdout '^golang.org/x/text v0.0.0.* .*vendor[\\/]golang.org[\\/]x[\\/]text[\\/]language$'
! go list -mod=vendor -m rsc.io/quote@latest ! go list -mod=vendor -m rsc.io/quote@latest
stderr 'module lookup disabled by -mod=vendor' stderr 'go list -m: can''t list modules with -mod=vendor\n\tuse -mod=mod or -mod=readonly to ignore the vendor directory'
! go get -mod=vendor -u ! go get -mod=vendor -u
stderr 'flag provided but not defined: -mod' stderr 'flag provided but not defined: -mod'
......
env GO111MODULE=on env GO111MODULE=on
# Without vendoring, a build should succeed unless -mod=vendor is set.
[!short] go build [!short] go build
[!short] ! go build -mod=vendor [!short] ! go build -mod=vendor
# Without vendoring, 'go list' should report the replacement directory for
# a package in a replaced module.
go list -f {{.Dir}} x go list -f {{.Dir}} x
stdout 'src[\\/]x' stdout 'src[\\/]x'
# 'go mod vendor' should copy all replaced modules to the vendor directory.
go mod vendor -v go mod vendor -v
stderr '^# x v1.0.0 => ./x' stderr '^# x v1.0.0 => ./x'
stderr '^x' stderr '^x'
...@@ -16,28 +20,38 @@ stderr '^z' ...@@ -16,28 +20,38 @@ stderr '^z'
! stderr '^w' ! stderr '^w'
grep 'a/foo/bar/b\na/foo/bar/c' vendor/modules.txt # must be sorted grep 'a/foo/bar/b\na/foo/bar/c' vendor/modules.txt # must be sorted
# An explicit '-mod=mod' should ignore the vendor directory.
go list -mod=mod -f {{.Dir}} x go list -mod=mod -f {{.Dir}} x
stdout 'src[\\/]x' stdout 'src[\\/]x'
go list -mod=mod -f {{.Dir}} -m x go list -mod=mod -f {{.Dir}} -m x
stdout 'src[\\/]x' stdout 'src[\\/]x'
# An explicit '-mod=vendor' should report package directories within
# the vendor directory.
go list -mod=vendor -f {{.Dir}} x go list -mod=vendor -f {{.Dir}} x
stdout 'src[\\/]vendor[\\/]x' stdout 'src[\\/]vendor[\\/]x'
go list -mod=vendor -f {{.Dir}} -m x # 'go list -mod=vendor -m' does not have enough information to list modules
stdout 'src[\\/]vendor[\\/]x' # accurately, and should fail.
! go list -mod=vendor -f {{.Dir}} -m x
stderr 'can''t list modules with -mod=vendor\n\tuse -mod=mod or -mod=readonly to ignore the vendor directory'
go list -mod=mod -f {{.Dir}} -m w # 'go list -mod=mod' should report packages outside the import graph,
# but 'go list -mod=vendor' should error out for them.
go list -mod=mod -f {{.Dir}} w
stdout 'src[\\/]w' stdout 'src[\\/]w'
! go list -mod=vendor -f {{.Dir}} w ! go list -mod=vendor -f {{.Dir}} w
stderr 'src[\\/]vendor[\\/]w' stderr 'src[\\/]vendor[\\/]w'
# Test dependencies should not be copied.
! exists vendor/x/testdata ! exists vendor/x/testdata
! exists vendor/a/foo/bar/b/ignored.go ! exists vendor/a/foo/bar/b/ignored.go
! exists vendor/a/foo/bar/b/main_test.go ! exists vendor/a/foo/bar/b/main_test.go
# Licenses and other metadata for each module should be copied
# if any package within their module is copied.
exists vendor/a/foo/AUTHORS.txt exists vendor/a/foo/AUTHORS.txt
exists vendor/a/foo/CONTRIBUTORS exists vendor/a/foo/CONTRIBUTORS
exists vendor/a/foo/LICENSE exists vendor/a/foo/LICENSE
...@@ -55,7 +69,8 @@ exists vendor/mysite/myname/mypkg/LICENSE.txt ...@@ -55,7 +69,8 @@ exists vendor/mysite/myname/mypkg/LICENSE.txt
[short] stop [short] stop
go build # 'go build' and 'go test' using vendored packages should succeed.
go build -mod=mod
go build -mod=vendor go build -mod=vendor
go test -mod=vendor . ./subdir go test -mod=vendor . ./subdir
go test -mod=vendor ./... go test -mod=vendor ./...
......
...@@ -15,15 +15,11 @@ stdout '^'$WORK'[/\\]auto$' ...@@ -15,15 +15,11 @@ stdout '^'$WORK'[/\\]auto$'
stdout '^'$WORK'[/\\]auto[/\\]vendor[/\\]example.com[/\\]printversion$' stdout '^'$WORK'[/\\]auto[/\\]vendor[/\\]example.com[/\\]printversion$'
stdout '^'$WORK'[/\\]auto[/\\]vendor[/\\]example.com[/\\]version$' stdout '^'$WORK'[/\\]auto[/\\]vendor[/\\]example.com[/\\]version$'
go list -m all ! go list -m all
stdout '^example.com/auto$' stderr 'can''t list modules with -mod=vendor'
stdout 'example.com/printversion v1.0.0'
stdout 'example.com/version v1.0.0'
go list -m -f '{{.Dir}}' all ! go list -m -f '{{.Dir}}' all
stdout '^'$WORK'[/\\]auto$' stderr 'can''t list modules with -mod=vendor'
stdout '^'$WORK'[/\\]auto[/\\]vendor[/\\]example.com[/\\]printversion$'
stdout '^'$WORK'[/\\]auto[/\\]vendor[/\\]example.com[/\\]version$'
# An explicit -mod=mod should force the vendor directory to be ignored. # An explicit -mod=mod should force the vendor directory to be ignored.
env GOFLAGS=-mod=mod env GOFLAGS=-mod=mod
......
env GO111MODULE=on env GO111MODULE=on
# Before vendoring, we expect to see the original directory. # Before vendoring, we expect to see the original directory.
go list -f '{{.Version}} {{.Dir}}' -m rsc.io/quote/v3 go list -f '{{with .Module}}{{.Version}}{{end}} {{.Dir}}' rsc.io/quote/v3
stdout 'v3.0.0' stdout 'v3.0.0'
stdout '.*[/\\]not-rsc.io[/\\]quote[/\\]v3' stdout '.*[/\\]not-rsc.io[/\\]quote[/\\]v3'
...@@ -15,7 +15,7 @@ go mod vendor ...@@ -15,7 +15,7 @@ go mod vendor
# without attempting to look up the non-replaced version. # without attempting to look up the non-replaced version.
cmp vendor/rsc.io/quote/v3/quote.go local/not-rsc.io/quote/v3/quote.go cmp vendor/rsc.io/quote/v3/quote.go local/not-rsc.io/quote/v3/quote.go
go list -mod=vendor -f '{{.Version}} {{.Dir}}' -m rsc.io/quote/v3 go list -mod=vendor -f '{{with .Module}}{{.Version}}{{end}} {{.Dir}}' rsc.io/quote/v3
stdout 'v3.0.0' stdout 'v3.0.0'
stdout '.*[/\\]vendor[/\\]rsc.io[/\\]quote[/\\]v3' stdout '.*[/\\]vendor[/\\]rsc.io[/\\]quote[/\\]v3'
! stderr 'finding' ! stderr 'finding'
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment