diff options
author | Russ Cox <rsc@golang.org> | 2018-07-11 23:55:39 -0400 |
---|---|---|
committer | Russ Cox <rsc@golang.org> | 2018-07-12 20:46:50 +0000 |
commit | f7248f05946c1804b5519d0b3eb0db054dc9c5d6 (patch) | |
tree | 73a9d64a6af33d4feefa5f3acf6eb7f7206a8a95 /src/cmd/go/internal/search/search.go | |
parent | f22dd66b23ec1a703a3984cad1840bc8692cf1d0 (diff) | |
download | go-f7248f05946c1804b5519d0b3eb0db054dc9c5d6.tar.gz go-f7248f05946c1804b5519d0b3eb0db054dc9c5d6.zip |
cmd/go: merge module support from x/vgo repo
This CL corresponds to CL 123361, the final manual CL in that repo,
making this the final manual sync.
All future commits will happen in this repo (the main Go repo),
and we'll update x/vgo automatically with a fixed patch+script.
Change-Id: I572243309c1809727604fd704705a23c30e85d1a
Reviewed-on: https://go-review.googlesource.com/123576
Run-TryBot: Russ Cox <rsc@golang.org>
Reviewed-by: Bryan C. Mills <bcmills@google.com>
Diffstat (limited to 'src/cmd/go/internal/search/search.go')
-rw-r--r-- | src/cmd/go/internal/search/search.go | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/src/cmd/go/internal/search/search.go b/src/cmd/go/internal/search/search.go index 42a6be0520..0c3400915a 100644 --- a/src/cmd/go/internal/search/search.go +++ b/src/cmd/go/internal/search/search.go @@ -173,6 +173,7 @@ func MatchPackagesInFS(pattern string) []string { if err != nil || !fi.IsDir() { return nil } + top := false if path == dir { // filepath.Walk starts at dir and recurses. For the recursive case, // the path is the result of filepath.Join, which calls filepath.Clean. @@ -182,6 +183,7 @@ func MatchPackagesInFS(pattern string) []string { // "cd $GOROOT/src; go list ./io/..." would incorrectly skip the io // package, because prepending the prefix "./" to the unclean path would // result in "././io", and match("././io") returns false. + top = true path = filepath.Clean(path) } @@ -192,6 +194,13 @@ func MatchPackagesInFS(pattern string) []string { return filepath.SkipDir } + if !top && cfg.ModulesEnabled { + // Ignore other modules found in subdirectories. + if _, err := os.Stat(filepath.Join(path, "go.mod")); err == nil { + return filepath.SkipDir + } + } + name := prefix + filepath.ToSlash(path) if !match(name) { return nil @@ -352,7 +361,7 @@ func CleanImportPaths(args []string) []string { // ImportPathsNoDotExpansion returns the import paths to use for the given // command line, but it does no ... expansion. -// TODO(vgo): Delete once old go get is gone. +// TODO(rsc): Delete once old go get is gone. func ImportPathsNoDotExpansion(args []string) []string { args = CleanImportPaths(args) var out []string @@ -421,3 +430,10 @@ func IsStandardImportPath(path string) bool { elem := path[:i] return !strings.Contains(elem, ".") } + +// IsRelativePath reports whether pattern should be interpreted as a directory +// path relative to the current directory, as opposed to a pattern matching +// import paths. +func IsRelativePath(pattern string) bool { + return strings.HasPrefix(pattern, "./") || strings.HasPrefix(pattern, "../") || pattern == "." || pattern == ".." +} |