From 9cefa6771f8f3c72b346adb1995b7432464d4038 Mon Sep 17 00:00:00 2001 From: Michael Matloob Date: Fri, 25 Jan 2019 16:12:01 -0500 Subject: [PATCH] go/packages: rename name= query and "disable" it It was originally added to support goimports, but goimports is going with another solution. We're going to disable it for now, but not delete it, so that the goimports code path that uses it can continue to be tested if and when we want to use it. We don't think there are any other users of name= but if there are, please let us know and we'll work with you to fix you, or we'll stop or revert this change. Thanks! Change-Id: I73b7b6c0a5788148af5f3380189055b450f7b45e Reviewed-on: https://go-review.googlesource.com/c/159702 Run-TryBot: Michael Matloob TryBot-Result: Gobot Gobot Reviewed-by: Heschi Kreinick --- go/packages/doc.go | 6 +----- go/packages/golist.go | 2 +- go/packages/packages_test.go | 14 +++++++------- imports/fix.go | 2 +- 4 files changed, 10 insertions(+), 14 deletions(-) diff --git a/go/packages/doc.go b/go/packages/doc.go index 0ec0fab2..3799f8ed 100644 --- a/go/packages/doc.go +++ b/go/packages/doc.go @@ -14,7 +14,7 @@ but all patterns with the prefix "query=", where query is a non-empty string of letters from [a-z], are reserved and may be interpreted as query operators. -Three query operators are currently supported: "file", "pattern", and "name". +Two query operators are currently supported: "file" and "pattern". The query "file=path/to/file.go" matches the package or packages enclosing the Go source file path/to/file.go. For example "file=~/go/src/fmt/print.go" @@ -25,10 +25,6 @@ the underlying build tool. In most cases this is unnecessary, but an application can use Load("pattern=" + x) as an escaping mechanism to ensure that x is not interpreted as a query operator if it contains '='. -The query "name=identifier" matches packages whose package declaration contains -the specified identifier. For example, "name=rand" would match the packages -"math/rand" and "crypto/rand", and "name=main" would match all executables. - All other query operators are reserved for future use and currently cause Load to report an error. diff --git a/go/packages/golist.go b/go/packages/golist.go index 7ca5ebe4..2fee7fb1 100644 --- a/go/packages/golist.go +++ b/go/packages/golist.go @@ -104,7 +104,7 @@ extractQueries: containFiles = append(containFiles, value) case "pattern": restPatterns = append(restPatterns, value) - case "name": + case "iamashamedtousethedisabledqueryname": packagesNamed = append(packagesNamed, value) case "": // not a reserved query restPatterns = append(restPatterns, pattern) diff --git a/go/packages/packages_test.go b/go/packages/packages_test.go index bf7f1da7..c27e940a 100644 --- a/go/packages/packages_test.go +++ b/go/packages/packages_test.go @@ -59,8 +59,8 @@ func TestLoadZeroConfig(t *testing.T) { hash := initial[0] // Even though the hash package has imports, // they are not reported. - got := fmt.Sprintf("name=%s srcs=%v imports=%v", hash.Name, srcs(hash), hash.Imports) - want := "name=hash srcs=[hash.go] imports=map[]" + got := fmt.Sprintf("iamashamedtousethedisabledqueryname=%s srcs=%v imports=%v", hash.Name, srcs(hash), hash.Imports) + want := "iamashamedtousethedisabledqueryname=hash srcs=[hash.go] imports=map[]" if got != want { t.Fatalf("got %s, want %s", got, want) } @@ -1165,7 +1165,7 @@ func testName(t *testing.T, exporter packagestest.Exporter) { defer exported.Cleanup() exported.Config.Mode = packages.LoadImports - initial, err := packages.Load(exported.Config, "name=needle") + initial, err := packages.Load(exported.Config, "iamashamedtousethedisabledqueryname=needle") if err != nil { t.Fatal(err) } @@ -1206,7 +1206,7 @@ func TestName_Modules(t *testing.T) { // - src/b/pkg exported.Config.Mode = packages.LoadImports exported.Config.Env = append(exported.Config.Env, "GOPATH="+wd+"/testdata/TestName_Modules") - initial, err := packages.Load(exported.Config, "name=pkg") + initial, err := packages.Load(exported.Config, "iamashamedtousethedisabledqueryname=pkg") if err != nil { t.Fatal(err) } @@ -1244,7 +1244,7 @@ func TestName_ModulesDedup(t *testing.T) { // but, inexplicably, not v2.0.0. Nobody knows why. exported.Config.Mode = packages.LoadImports exported.Config.Env = append(exported.Config.Env, "GOPATH="+wd+"/testdata/TestName_ModulesDedup") - initial, err := packages.Load(exported.Config, "name=pkg") + initial, err := packages.Load(exported.Config, "iamashamedtousethedisabledqueryname=pkg") if err != nil { t.Fatal(err) } @@ -1268,12 +1268,12 @@ func testRedundantQueries(t *testing.T, exporter packagestest.Exporter) { }}}) defer exported.Cleanup() - initial, err := packages.Load(exported.Config, "errors", "name=errors") + initial, err := packages.Load(exported.Config, "errors", "iamashamedtousethedisabledqueryname=errors") if err != nil { t.Fatal(err) } if len(initial) != 1 || initial[0].Name != "errors" { - t.Fatalf(`Load("errors", "name=errors") = %v, wanted just the errors package`, initial) + t.Fatalf(`Load("errors", "iamashamedtousethedisabledqueryname=errors") = %v, wanted just the errors package`, initial) } } diff --git a/imports/fix.go b/imports/fix.go index f18c4135..cb2d3eb0 100644 --- a/imports/fix.go +++ b/imports/fix.go @@ -657,7 +657,7 @@ func (r *goPackagesResolver) loadPackageNames(importPaths []string, srcDir strin func (r *goPackagesResolver) scan(refs references) ([]*pkg, error) { var loadQueries []string for pkgName := range refs { - loadQueries = append(loadQueries, "name="+pkgName) + loadQueries = append(loadQueries, "iamashamedtousethedisabledqueryname="+pkgName) } sort.Strings(loadQueries) cfg := r.env.newPackagesConfig(packages.LoadFiles)