aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/go/internal/modload/search.go
diff options
context:
space:
mode:
authorBryan C. Mills <bcmills@google.com>2019-02-15 17:06:57 -0500
committerBryan C. Mills <bcmills@google.com>2019-03-11 14:22:02 +0000
commitfd080ea3bcc2b170b787b38ab7920d170ca65682 (patch)
treed3d2f03ca5f58817ef9c8f72c80bba0530fe761d /src/cmd/go/internal/modload/search.go
parent1c2d4da10f6edf9a83fb0cffaaf9f631f462d26b (diff)
downloadgo-fd080ea3bcc2b170b787b38ab7920d170ca65682.tar.gz
go-fd080ea3bcc2b170b787b38ab7920d170ca65682.zip
cmd/go: resolve non-standard imports from within GOROOT/src using vendor directories
Updates #30228 Fixes #26924 Change-Id: Ie625c64721559c7633396342320536396cd1fcf5 Reviewed-on: https://go-review.googlesource.com/c/go/+/164621 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/modload/search.go')
-rw-r--r--src/cmd/go/internal/modload/search.go30
1 files changed, 13 insertions, 17 deletions
diff --git a/src/cmd/go/internal/modload/search.go b/src/cmd/go/internal/modload/search.go
index 45e7ee2674..2e82b92cc5 100644
--- a/src/cmd/go/internal/modload/search.go
+++ b/src/cmd/go/internal/modload/search.go
@@ -35,12 +35,8 @@ func matchPackages(pattern string, tags map[string]bool, useStd bool, modules []
}
var pkgs []string
- walkPkgs := func(root, importPathRoot string) {
+ walkPkgs := func(root, importPathRoot string, includeVendor bool) {
root = filepath.Clean(root)
- var cmd string
- if root == cfg.GOROOTsrc {
- cmd = filepath.Join(root, "cmd")
- }
filepath.Walk(root, func(path string, fi os.FileInfo, err error) error {
if err != nil {
return nil
@@ -51,14 +47,6 @@ func matchPackages(pattern string, tags map[string]bool, useStd bool, modules []
return nil
}
- // GOROOT/src/cmd makes use of GOROOT/src/cmd/vendor,
- // which module mode can't deal with. Eventually we'll stop using
- // that vendor directory, and then we can remove this exclusion.
- // golang.org/issue/26924.
- if path == cmd {
- return filepath.SkipDir
- }
-
want := true
// Avoid .foo, _foo, and testdata directory trees.
_, elem := filepath.Split(path)
@@ -86,6 +74,7 @@ func matchPackages(pattern string, tags map[string]bool, useStd bool, modules []
if !want {
return filepath.SkipDir
}
+ // Stop at module boundaries.
if path != root {
if _, err := os.Stat(filepath.Join(path, "go.mod")); err == nil {
return filepath.SkipDir
@@ -101,7 +90,7 @@ func matchPackages(pattern string, tags map[string]bool, useStd bool, modules []
}
}
- if elem == "vendor" {
+ if elem == "vendor" && !includeVendor {
return filepath.SkipDir
}
return nil
@@ -109,11 +98,14 @@ func matchPackages(pattern string, tags map[string]bool, useStd bool, modules []
}
if useStd {
- walkPkgs(cfg.GOROOTsrc, "")
+ walkPkgs(cfg.GOROOTsrc, "", true)
+ if treeCanMatch("cmd") {
+ walkPkgs(filepath.Join(cfg.GOROOTsrc, "cmd"), "cmd", true)
+ }
}
if cfg.BuildMod == "vendor" {
- walkPkgs(filepath.Join(ModRoot(), "vendor"), "")
+ walkPkgs(filepath.Join(ModRoot(), "vendor"), "", false)
return pkgs
}
@@ -135,7 +127,11 @@ func matchPackages(pattern string, tags map[string]bool, useStd bool, modules []
continue
}
}
- walkPkgs(root, mod.Path)
+ modPrefix := mod.Path
+ if mod.Path == "std" {
+ modPrefix = ""
+ }
+ walkPkgs(root, modPrefix, false)
}
return pkgs