Commit e652b7e6 authored by Russ Cox's avatar Russ Cox

cmd/go: fix module ... pattern to match standard library

The non-module ... pattern always has.

Fixes #26905.

Change-Id: I7b298747fb33b82c58d3e6a6bc6687b6e825e52c
Reviewed-on: https://go-review.googlesource.com/128997
Run-TryBot: Russ Cox <rsc@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: 's avatarBryan C. Mills <bcmills@google.com>
parent 12d0a288
...@@ -103,7 +103,7 @@ func ImportPaths(args []string) []string { ...@@ -103,7 +103,7 @@ func ImportPaths(args []string) []string {
case pkg == "all": case pkg == "all":
loaded.testAll = true loaded.testAll = true
// TODO: Don't print warnings multiple times. // TODO: Don't print warnings multiple times.
roots = append(roots, warnPattern("all", matchPackages("...", loaded.tags, []module.Version{Target}))...) roots = append(roots, warnPattern("all", matchPackages("...", loaded.tags, false, []module.Version{Target}))...)
paths = append(paths, "all") // will expand after load completes paths = append(paths, "all") // will expand after load completes
case search.IsMetaPackage(pkg): // std, cmd case search.IsMetaPackage(pkg): // std, cmd
...@@ -113,7 +113,7 @@ func ImportPaths(args []string) []string { ...@@ -113,7 +113,7 @@ func ImportPaths(args []string) []string {
case strings.Contains(pkg, "..."): case strings.Contains(pkg, "..."):
// TODO: Don't we need to reevaluate this one last time once the build list stops changing? // TODO: Don't we need to reevaluate this one last time once the build list stops changing?
list := warnPattern(pkg, matchPackages(pkg, loaded.tags, buildList)) list := warnPattern(pkg, matchPackages(pkg, loaded.tags, true, buildList))
roots = append(roots, list...) roots = append(roots, list...)
paths = append(paths, list...) paths = append(paths, list...)
...@@ -286,7 +286,7 @@ var anyTags = map[string]bool{"*": true} ...@@ -286,7 +286,7 @@ var anyTags = map[string]bool{"*": true}
// TargetPackages returns the list of packages in the target (top-level) module, // TargetPackages returns the list of packages in the target (top-level) module,
// under all build tag settings. // under all build tag settings.
func TargetPackages() []string { func TargetPackages() []string {
return matchPackages("...", anyTags, []module.Version{Target}) return matchPackages("...", anyTags, false, []module.Version{Target})
} }
// BuildList returns the module build list, // BuildList returns the module build list,
......
...@@ -19,7 +19,7 @@ import ( ...@@ -19,7 +19,7 @@ import (
// matchPackages returns a list of packages in the list of modules // matchPackages returns a list of packages in the list of modules
// matching the pattern. Package loading assumes the given set of tags. // matching the pattern. Package loading assumes the given set of tags.
func matchPackages(pattern string, tags map[string]bool, modules []module.Version) []string { func matchPackages(pattern string, tags map[string]bool, useStd bool, modules []module.Version) []string {
match := func(string) bool { return true } match := func(string) bool { return true }
treeCanMatch := func(string) bool { return true } treeCanMatch := func(string) bool { return true }
if !search.IsMetaPackage(pattern) { if !search.IsMetaPackage(pattern) {
...@@ -35,28 +35,18 @@ func matchPackages(pattern string, tags map[string]bool, modules []module.Versio ...@@ -35,28 +35,18 @@ func matchPackages(pattern string, tags map[string]bool, modules []module.Versio
} }
var pkgs []string var pkgs []string
for _, mod := range modules { walkPkgs := func(root, importPathRoot string) {
if !treeCanMatch(mod.Path) {
continue
}
var root string
if mod.Version == "" {
root = ModRoot
} else {
var err error
root, _, err = fetch(mod)
if err != nil {
base.Errorf("go: %v", err)
continue
}
}
root = filepath.Clean(root) root = filepath.Clean(root)
filepath.Walk(root, func(path string, fi os.FileInfo, err error) error { filepath.Walk(root, func(path string, fi os.FileInfo, err error) error {
if err != nil { if err != nil {
return nil return nil
} }
// Don't use GOROOT/src but do walk down into it.
if path == root && importPathRoot == "" {
return nil
}
want := true want := true
// Avoid .foo, _foo, and testdata directory trees. // Avoid .foo, _foo, and testdata directory trees.
_, elem := filepath.Split(path) _, elem := filepath.Split(path)
...@@ -64,7 +54,10 @@ func matchPackages(pattern string, tags map[string]bool, modules []module.Versio ...@@ -64,7 +54,10 @@ func matchPackages(pattern string, tags map[string]bool, modules []module.Versio
want = false want = false
} }
name := mod.Path + filepath.ToSlash(path[len(root):]) name := importPathRoot + filepath.ToSlash(path[len(root):])
if importPathRoot == "" {
name = name[1:] // cut leading slash
}
if !treeCanMatch(name) { if !treeCanMatch(name) {
want = false want = false
} }
...@@ -102,5 +95,28 @@ func matchPackages(pattern string, tags map[string]bool, modules []module.Versio ...@@ -102,5 +95,28 @@ func matchPackages(pattern string, tags map[string]bool, modules []module.Versio
return nil return nil
}) })
} }
if useStd {
walkPkgs(cfg.GOROOTsrc, "")
}
for _, mod := range modules {
if !treeCanMatch(mod.Path) {
continue
}
var root string
if mod.Version == "" {
root = ModRoot
} else {
var err error
root, _, err = fetch(mod)
if err != nil {
base.Errorf("go: %v", err)
continue
}
}
walkPkgs(root, mod.Path)
}
return pkgs return pkgs
} }
...@@ -15,15 +15,14 @@ stdout '^unsafe$' ...@@ -15,15 +15,14 @@ stdout '^unsafe$'
! stdout index/suffixarray ! stdout index/suffixarray
# 'go list ...' should list packages in all active modules and the standard library. # 'go list ...' should list packages in all active modules and the standard library.
# BUG: It currently omits the standard library (https://golang.org/issue/26905).
go list ... go list ...
stdout example.com/unused/useerrors stdout example.com/unused/useerrors
stdout example.com/m/useunsafe stdout example.com/m/useunsafe
[cgo] stdout example.com/m/useC [cgo] stdout example.com/m/useC
[!cgo] ! stdout example.com/m/useC [!cgo] ! stdout example.com/m/useC
# stdout '^unicode$' stdout '^unicode$'
# stdout '^unsafe$' stdout '^unsafe$'
# stdout index/suffixarray stdout index/suffixarray
# 'go list example.com/m/...' should list packages in all modules that begin with # 'go list example.com/m/...' should list packages in all modules that begin with
# "example.com/m/". # "example.com/m/".
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment