]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/go/internal/modload: use vendorMap in findModule
authorBryan C. Mills <bcmills@google.com>
Tue, 9 Oct 2018 21:03:48 +0000 (17:03 -0400)
committerBryan C. Mills <bcmills@google.com>
Fri, 26 Oct 2018 19:50:21 +0000 (19:50 +0000)
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>
src/cmd/go/internal/modload/build.go
src/cmd/go/testdata/script/mod_vendor.txt

index b87a7002567a761af328e593ce97bf0fd75ad4e7..76068069087f784dd287a978973c71a4128d7726 100644 (file)
@@ -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
index b3769a850415fe1b6d828dc4082126563793c449..203183be881f2a43366ef4710785a7e0a2e11488 100644 (file)
@@ -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