From 3f95c6634578c08ac4fc93560638031f114d076b Mon Sep 17 00:00:00 2001 From: Alan Donovan Date: Sat, 20 Feb 2016 19:34:40 -0500 Subject: [PATCH] cmd/guru: allow foo/... and -foo patterns in scope argument Also, document -scope argument. Depends on CL 19746 (buildutil.ExpandPatterns) Change-Id: I3c9000e94d87cca5c2c49fe8de12a77fc43f7257 Reviewed-on: https://go-review.googlesource.com/19747 Reviewed-by: Daniel Morsing Reviewed-by: Michael Matloob --- cmd/guru/guru.go | 16 ++++++---------- cmd/guru/main.go | 12 ++++++++++-- 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/cmd/guru/guru.go b/cmd/guru/guru.go index 960b061934..7b25884999 100644 --- a/cmd/guru/guru.go +++ b/cmd/guru/guru.go @@ -22,6 +22,7 @@ import ( "golang.org/x/tools/cmd/guru/serial" "golang.org/x/tools/go/ast/astutil" + "golang.org/x/tools/go/buildutil" "golang.org/x/tools/go/loader" "golang.org/x/tools/go/pointer" "golang.org/x/tools/go/ssa" @@ -129,18 +130,13 @@ func Run(q *Query) error { } func setPTAScope(lconf *loader.Config, scope []string) error { - if len(scope) == 0 { + pkgs := buildutil.ExpandPatterns(lconf.Build, scope) + if len(pkgs) == 0 { return fmt.Errorf("no packages specified for pointer analysis scope") } - - // Determine initial packages for PTA. - args, err := lconf.FromArgs(scope, true) - if err != nil { - return err - } - if len(args) > 0 { - return fmt.Errorf("surplus arguments: %q", args) - } + // The value of each entry in pkgs is true, + // giving ImportWithTests (not Import) semantics. + lconf.ImportPkgs = pkgs return nil } diff --git a/cmd/guru/main.go b/cmd/guru/main.go index 538bcd5bbc..97d7acacb0 100644 --- a/cmd/guru/main.go +++ b/cmd/guru/main.go @@ -34,7 +34,7 @@ import ( // flags var ( modifiedFlag = flag.Bool("modified", false, "read archive of modified files from standard input") - scopeFlag = flag.String("scope", "", "comma-separated list of `packages` the analysis should be limited to (default=all)") + scopeFlag = flag.String("scope", "", "comma-separated list of `packages` the analysis should be limited to") ptalogFlag = flag.String("ptalog", "", "write points-to analysis log to `file`") formatFlag = flag.String("format", "plain", "output `format`; one of {plain,json,xml}") reflectFlag = flag.Bool("reflect", false, "analyze reflection soundly (slow)") @@ -78,13 +78,21 @@ The -format flag controls the output format: xml structured data in XML syntax. The -modified flag causes guru to read an archive from standard input. - Files in this archive will be used in preference to those in the file system. In this way, a text editor may supply guru with the contents of its unsaved buffers. Each archive entry consists of the file name, a newline, the decimal file size, another newline, and the contents of the file. +The -scope flag restricts analysis to the specified packages. + Its value is a comma-separated list of patterns of these forms: + golang.org/x/tools/cmd/guru # a single package + golang.org/x/tools/... # all packages beneath dir + ... # the entire workspace. + A pattern preceded by '-' is negative, so the scope + encoding/...,-encoding/xml + matches all encoding packages except encoding/xml: + User manual: http://golang.org/s/oracle-user-manual Example: describe syntax at offset 530 in this file (an import spec):