1
0
mirror of https://github.com/golang/go synced 2024-11-07 12:26:16 -07:00

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 <bcmills@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Russ Cox <rsc@golang.org>
This commit is contained in:
Bryan C. Mills 2018-10-09 17:03:48 -04:00
parent f8153fcd74
commit 6a6cbb995c
2 changed files with 52 additions and 0 deletions

View File

@ -228,6 +228,10 @@ func findModule(target, path string) module.Version {
if path == "." { if path == "." {
return buildList[0] return buildList[0]
} }
if cfg.BuildMod == "vendor" {
readVendorList()
return vendorMap[path]
}
for _, mod := range buildList { for _, mod := range buildList {
if maybeInModule(path, mod.Path) { if maybeInModule(path, mod.Path) {
return mod return mod

View File

@ -67,6 +67,7 @@ module m
require ( require (
a v1.0.0 a v1.0.0
diamondroot v0.0.0
mysite/myname/mypkg v1.0.0 mysite/myname/mypkg v1.0.0
w v1.0.0 // indirect w v1.0.0 // indirect
x v1.0.0 x v1.0.0
@ -76,6 +77,10 @@ require (
replace ( replace (
a v1.0.0 => ./a a v1.0.0 => ./a
diamondleft => ./diamondleft
diamondpoint => ./diamondpoint
diamondright => ./diamondright
diamondroot => ./diamondroot
mysite/myname/mypkg v1.0.0 => ./mypkg mysite/myname/mypkg v1.0.0 => ./mypkg
w v1.0.0 => ./w w v1.0.0 => ./w
x v1.0.0 => ./x x v1.0.0 => ./x
@ -200,6 +205,10 @@ import _ "z"
package m package m
import _ "x/x1" import _ "x/x1"
-- importdiamond.go --
package m
import _ "diamondroot"
-- w/go.mod -- -- w/go.mod --
module w module w
-- w/w.go -- -- w/w.go --
@ -228,3 +237,42 @@ package y
module z module z
-- z/z.go -- -- z/z.go --
package z 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