From 6a6cbb995c915a0edc0d0e95130b746ef7f8815a Mon Sep 17 00:00:00 2001 From: "Bryan C. Mills" Date: Tue, 9 Oct 2018 17:03:48 -0400 Subject: [PATCH] cmd/go/internal/modload: use vendorMap in findModule The build list is very incomplete in vendor mode, so we can't rely on it in general. findModule may be called in modload.PackageModuleInfo, which load.LoadImport invokes relatively early during a build. Before this change, the accompanying test failed at 'go build -mod=vendor' with the message: build diamondpoint: cannot find module for path diamondpoint Change-Id: I5e667d8e406872be703510afeb079f6cbfdbd3c8 Reviewed-on: https://go-review.googlesource.com/c/140861 Run-TryBot: Bryan C. Mills TryBot-Result: Gobot Gobot Reviewed-by: Russ Cox --- src/cmd/go/internal/modload/build.go | 4 ++ src/cmd/go/testdata/script/mod_vendor.txt | 48 +++++++++++++++++++++++ 2 files changed, 52 insertions(+) diff --git a/src/cmd/go/internal/modload/build.go b/src/cmd/go/internal/modload/build.go index b87a700256..7606806908 100644 --- a/src/cmd/go/internal/modload/build.go +++ b/src/cmd/go/internal/modload/build.go @@ -228,6 +228,10 @@ func findModule(target, path string) module.Version { if path == "." { return buildList[0] } + if cfg.BuildMod == "vendor" { + readVendorList() + return vendorMap[path] + } for _, mod := range buildList { if maybeInModule(path, mod.Path) { return mod diff --git a/src/cmd/go/testdata/script/mod_vendor.txt b/src/cmd/go/testdata/script/mod_vendor.txt index b3769a8504..203183be88 100644 --- a/src/cmd/go/testdata/script/mod_vendor.txt +++ b/src/cmd/go/testdata/script/mod_vendor.txt @@ -67,6 +67,7 @@ module m require ( a v1.0.0 + diamondroot v0.0.0 mysite/myname/mypkg v1.0.0 w v1.0.0 // indirect x v1.0.0 @@ -76,6 +77,10 @@ require ( replace ( a v1.0.0 => ./a + diamondleft => ./diamondleft + diamondpoint => ./diamondpoint + diamondright => ./diamondright + diamondroot => ./diamondroot mysite/myname/mypkg v1.0.0 => ./mypkg w v1.0.0 => ./w x v1.0.0 => ./x @@ -200,6 +205,10 @@ import _ "z" package m import _ "x/x1" +-- importdiamond.go -- +package m + +import _ "diamondroot" -- w/go.mod -- module w -- w/w.go -- @@ -228,3 +237,42 @@ package y module z -- z/z.go -- package z + +-- diamondroot/go.mod -- +module diamondroot + +require ( + diamondleft v0.0.0 + diamondright v0.0.0 +) +-- diamondroot/x.go -- +package diamondroot + +import ( + _ "diamondleft" + _ "diamondright" +) +-- diamondleft/go.mod -- +module diamondleft + +require ( + diamondpoint v0.0.0 +) +-- diamondleft/x.go -- +package diamondleft + +import _ "diamondpoint" +-- diamondright/go.mod -- +module diamondright + +require ( + diamondpoint v0.0.0 +) +-- diamondright/x.go -- +package diamondright + +import _ "diamondpoint" +-- diamondpoint/go.mod -- +module diamondpoint +-- diamondpoint/x.go -- +package diamondpoint -- 2.50.0