aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/go/internal/list/list.go
diff options
context:
space:
mode:
authorBryan C. Mills <bcmills@google.com>2019-10-23 16:10:55 -0400
committerBryan C. Mills <bcmills@google.com>2019-10-24 13:21:45 +0000
commitdc77dc2b9bd0f232631f683638bd7a23fab3598c (patch)
tree38481992f6b61922815a8e87368628bd79da4c21 /src/cmd/go/internal/list/list.go
parenta42a396846453e44ff9abadc1430a8c0c6a11e25 (diff)
downloadgo-dc77dc2b9bd0f232631f683638bd7a23fab3598c.tar.gz
go-dc77dc2b9bd0f232631f683638bd7a23fab3598c.zip
cmd/go/internal/list: ensure that cfg.BuildMod is initialized before reading it in 'go list -m'
The default value of cfg.BuildMod depends on the 'go' version in the go.mod file. The go.mod file is read and parsed, and its settings are applied, in modload.InitMod. As it turns out, modload.Enabled does not invoke InitMod, so cfg.BuildMod is not necessarily set even if modload.Enabled returns true. Updates #33848 Change-Id: I13a4dd80730528e6f1a5acc492fcfe07cb59d94e Reviewed-on: https://go-review.googlesource.com/c/go/+/202917 Run-TryBot: Bryan C. Mills <bcmills@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Jay Conrod <jayconrod@google.com>
Diffstat (limited to 'src/cmd/go/internal/list/list.go')
-rw-r--r--src/cmd/go/internal/list/list.go10
1 files changed, 9 insertions, 1 deletions
diff --git a/src/cmd/go/internal/list/list.go b/src/cmd/go/internal/list/list.go
index d8c75776bb..7965a84f99 100644
--- a/src/cmd/go/internal/list/list.go
+++ b/src/cmd/go/internal/list/list.go
@@ -381,12 +381,20 @@ func runList(cmd *base.Command, args []string) {
base.Fatalf("go list -test cannot be used with -m")
}
+ buildModIsDefault := (cfg.BuildMod == "")
if modload.Init(); !modload.Enabled() {
base.Fatalf("go list -m: not using modules")
}
+
+ modload.InitMod() // Parses go.mod and sets cfg.BuildMod.
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")
+ if buildModIsDefault {
+ base.Fatalf("go list -m: can't list modules using the vendor directory\n\tUse -mod=mod or -mod=readonly to ignore it.")
+ } else {
+ 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()
mods := modload.ListModules(args, *listU, *listVersions)