1
0
mirror of https://github.com/golang/go synced 2024-11-18 18:04:46 -07:00

go/gcexportdata: add -package flag to diagnostic tool

...to show information about indirectly mentioned packages.

Change-Id: Ib74b56493861bf41d9720760e76ace186efae2ea
Reviewed-on: https://go-review.googlesource.com/121195
Reviewed-by: Robert Griesemer <gri@golang.org>
Run-TryBot: Robert Griesemer <gri@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
This commit is contained in:
Alan Donovan 2018-06-27 10:16:43 -04:00
parent 56e9b8e653
commit 16699b2d33

View File

@ -20,11 +20,13 @@ import (
"golang.org/x/tools/go/types/typeutil"
)
var packageFlag = flag.String("package", "", "alternative package to print")
func main() {
log.SetPrefix("gcexportdata: ")
log.SetFlags(0)
flag.Usage = func() {
fmt.Fprintln(os.Stderr, "usage: gcexportdata file.a")
fmt.Fprintln(os.Stderr, "usage: gcexportdata [-package path] file.a")
}
flag.Parse()
if flag.NArg() != 1 {
@ -44,11 +46,27 @@ func main() {
}
// Decode the package.
const primary = "<primary>"
imports := make(map[string]*types.Package)
fset := token.NewFileSet()
pkg, err := gcexportdata.Read(r, fset, imports, "dummy")
pkg, err := gcexportdata.Read(r, fset, imports, primary)
if err != nil {
log.Fatal("%s: %s", filename, err)
log.Fatalf("%s: %s", filename, err)
}
// Optionally select an indirectly mentioned package.
if *packageFlag != "" {
pkg = imports[*packageFlag]
if pkg == nil {
fmt.Fprintf(os.Stderr, "export data file %s does not mention %s; has:\n",
filename, *packageFlag)
for p := range imports {
if p != primary {
fmt.Fprintf(os.Stderr, "\t%s\n", p)
}
}
os.Exit(1)
}
}
// Print all package-level declarations, including non-exported ones.