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 <matloob@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
This commit is contained in:
Michael Matloob 2019-01-25 16:12:01 -05:00
parent 0a99049195
commit 9cefa6771f
4 changed files with 10 additions and 14 deletions

View File

@ -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.

View File

@ -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)

View File

@ -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)
}
}

View File

@ -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)