]> Cypherpunks.ru repositories - gostls13.git/commitdiff
cmd/go: fix module ... pattern to match standard library
authorRuss Cox <rsc@golang.org>
Fri, 10 Aug 2018 16:49:54 +0000 (12:49 -0400)
committerRuss Cox <rsc@golang.org>
Fri, 10 Aug 2018 18:31:32 +0000 (18:31 +0000)
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: Bryan C. Mills <bcmills@google.com>
src/cmd/go/internal/modload/load.go
src/cmd/go/internal/modload/search.go
src/cmd/go/testdata/script/mod_patterns.txt

index b42d0d2e50fccac6a08188409fcf61f770a4264f..389c643db2c09ba7e0f1d4218a49163e9dd4df6a 100644 (file)
@@ -103,7 +103,7 @@ func ImportPaths(args []string) []string {
                        case pkg == "all":
                                loaded.testAll = true
                                // 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
 
                        case search.IsMetaPackage(pkg): // std, cmd
@@ -113,7 +113,7 @@ func ImportPaths(args []string) []string {
 
                        case strings.Contains(pkg, "..."):
                                // 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...)
                                paths = append(paths, list...)
 
@@ -286,7 +286,7 @@ var anyTags = map[string]bool{"*": true}
 // TargetPackages returns the list of packages in the target (top-level) module,
 // under all build tag settings.
 func TargetPackages() []string {
-       return matchPackages("...", anyTags, []module.Version{Target})
+       return matchPackages("...", anyTags, false, []module.Version{Target})
 }
 
 // BuildList returns the module build list,
index 9ce65f0511a8eca1f994d91a267be891e182945e..6aaabe6a08760fe1db3a58eed5a6960f8f0bf8f4 100644 (file)
@@ -19,7 +19,7 @@ import (
 
 // matchPackages returns a list of packages in the list of modules
 // 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 }
        treeCanMatch := func(string) bool { return true }
        if !search.IsMetaPackage(pattern) {
@@ -35,28 +35,18 @@ func matchPackages(pattern string, tags map[string]bool, modules []module.Versio
        }
        var pkgs []string
 
-       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 := func(root, importPathRoot string) {
                root = filepath.Clean(root)
-
                filepath.Walk(root, func(path string, fi os.FileInfo, err error) error {
                        if err != nil {
                                return nil
                        }
 
+                       // Don't use GOROOT/src but do walk down into it.
+                       if path == root && importPathRoot == "" {
+                               return nil
+                       }
+
                        want := true
                        // Avoid .foo, _foo, and testdata directory trees.
                        _, elem := filepath.Split(path)
@@ -64,7 +54,10 @@ func matchPackages(pattern string, tags map[string]bool, modules []module.Versio
                                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) {
                                want = false
                        }
@@ -102,5 +95,28 @@ func matchPackages(pattern string, tags map[string]bool, modules []module.Versio
                        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
 }
index 83b86ee0979cc6e2f3c0398524b628537eb7cae1..2a3629f764e5470a170d45c6fbe65ee0f9ef6485 100644 (file)
@@ -15,15 +15,14 @@ stdout '^unsafe$'
 ! stdout index/suffixarray
 
 # '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 ...
 stdout example.com/unused/useerrors
 stdout example.com/m/useunsafe
 [cgo] stdout example.com/m/useC
 [!cgo] ! stdout example.com/m/useC
-stdout '^unicode$'
-stdout '^unsafe$'
-stdout index/suffixarray
+stdout '^unicode$'
+stdout '^unsafe$'
+stdout index/suffixarray
 
 # 'go list example.com/m/...' should list packages in all modules that begin with
 # "example.com/m/".