From: Russ Cox Date: Fri, 10 Aug 2018 19:25:15 +0000 (-0400) Subject: cmd/go: don't let ... match GOROOT/src/cmd in module mode X-Git-Tag: go1.11rc1~5 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=5c11480631f5654e9e6937ff08c453660138c64d;p=gostls13.git cmd/go: don't let ... match GOROOT/src/cmd in module mode GOROOT/src/cmd uses GOROOT/src/cmd/vendor, which module mode simply cannot handle. Exposed by making ... match the standard library, which it still should. But for now it's fine to just exclude commands. Change-Id: I2201b94445f11239022de8a2473aa3b573f405c0 Reviewed-on: https://go-review.googlesource.com/129055 Run-TryBot: Russ Cox Reviewed-by: Bryan C. Mills TryBot-Result: Gobot Gobot --- diff --git a/src/cmd/go/internal/modload/search.go b/src/cmd/go/internal/modload/search.go index 6aaabe6a08..24825cc35d 100644 --- a/src/cmd/go/internal/modload/search.go +++ b/src/cmd/go/internal/modload/search.go @@ -37,6 +37,10 @@ func matchPackages(pattern string, tags map[string]bool, useStd bool, modules [] walkPkgs := func(root, importPathRoot string) { 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 @@ -47,6 +51,14 @@ 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) diff --git a/src/cmd/go/testdata/script/mod_patterns.txt b/src/cmd/go/testdata/script/mod_patterns.txt index 2a3629f764..36d738a867 100644 --- a/src/cmd/go/testdata/script/mod_patterns.txt +++ b/src/cmd/go/testdata/script/mod_patterns.txt @@ -15,6 +15,7 @@ stdout '^unsafe$' ! stdout index/suffixarray # 'go list ...' should list packages in all active modules and the standard library. +# But not cmd/* - see golang.org/issue/26924. go list ... stdout example.com/unused/useerrors stdout example.com/m/useunsafe @@ -23,6 +24,7 @@ stdout example.com/m/useunsafe stdout '^unicode$' stdout '^unsafe$' stdout index/suffixarray +! stdout cmd/pprof # 'go list example.com/m/...' should list packages in all modules that begin with # "example.com/m/".