1
0
mirror of https://github.com/golang/go synced 2024-11-07 16:26:11 -07:00

cmd/go: add list -find to find packages but not resolve imports

This is needed by golang.org/x/tools/go/packages
and also gives a way to do a quicker scan for
packages with a given final path element:

	go list -find .../template

Change-Id: I092f4ac5ba7af7d727eb8204379fa436667061b9
Reviewed-on: https://go-review.googlesource.com/126716
Run-TryBot: Russ Cox <rsc@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Bryan C. Mills <bcmills@google.com>
This commit is contained in:
Russ Cox 2018-07-30 13:51:35 -04:00
parent cdac6c22c3
commit 27e546be86
3 changed files with 27 additions and 0 deletions

View File

@ -167,6 +167,9 @@ a non-nil Error field; other information may or may not be missing
The -export flag causes list to set the Export field to the name of a
file containing up-to-date export information for the given package.
The -find flag causes list to identify the named packages but not
resolve their dependencies: the Imports and Deps lists will be empty.
The -test flag causes list to report not only the named packages
but also their test binaries (for packages with tests), to convey to
source code analysis tools exactly how test binaries are constructed.
@ -289,6 +292,7 @@ var (
listE = CmdList.Flag.Bool("e", false, "")
listExport = CmdList.Flag.Bool("export", false, "")
listFmt = CmdList.Flag.String("f", "", "")
listFind = CmdList.Flag.Bool("find", false, "")
listJson = CmdList.Flag.Bool("json", false, "")
listM = CmdList.Flag.Bool("m", false, "")
listU = CmdList.Flag.Bool("u", false, "")
@ -365,6 +369,9 @@ func runList(cmd *base.Command, args []string) {
if *listExport {
base.Fatalf("go list -export cannot be used with -m")
}
if *listFind {
base.Fatalf("go list -find cannot be used with -m")
}
if *listTest {
base.Fatalf("go list -test cannot be used with -m")
}
@ -397,6 +404,15 @@ func runList(cmd *base.Command, args []string) {
base.Fatalf("go list -versions can only be used with -m")
}
// These pairings make no sense.
if *listFind && *listDeps {
base.Fatalf("go list -deps cannot be used with -find")
}
if *listFind && *listTest {
base.Fatalf("go list -test cannot be used with -find")
}
load.IgnoreImports = *listFind
var pkgs []*load.Package
if *listE {
pkgs = load.PackagesAndErrors(args)

View File

@ -287,6 +287,7 @@ func (p *Package) copyBuild(pp *build.Package) {
p.XTestImports = pp.XTestImports
if IgnoreImports {
p.Imports = nil
p.Internal.RawImports = nil
p.TestImports = nil
p.XTestImports = nil
}

View File

@ -0,0 +1,10 @@
# go list -find should not report imports
go list -f {{.Incomplete}} x/y/z... # should probably exit non-zero but never has
stdout true
go list -find -f '{{.Incomplete}} {{.Imports}}' x/y/z...
stdout '^false \[\]'
-- x/y/z/z.go --
package z
import "does/not/exist"