From d12035dfdc6da9d82d9f9d0fba01b218324cb314 Mon Sep 17 00:00:00 2001 From: Heschi Kreinick Date: Thu, 20 Dec 2018 16:07:38 -0500 Subject: [PATCH] go/packages: use -find, add GOPACKAGESDEBUG env var Pass -find whenever possible to speed up go list calls. Add an environment variable, GOPACKAGESDEBUG, that controls debug logging so that we don't have to tell users to recompile goimports to debug it. Change-Id: If39ff7829279dafa4e066e74a024c27a8235154b Reviewed-on: https://go-review.googlesource.com/c/155477 Run-TryBot: Heschi Kreinick Reviewed-by: Michael Matloob --- go/packages/golist.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/go/packages/golist.go b/go/packages/golist.go index 83e3ba0d..ffe36d2d 100644 --- a/go/packages/golist.go +++ b/go/packages/golist.go @@ -16,6 +16,7 @@ import ( "path/filepath" "reflect" "regexp" + "strconv" "strings" "sync" "time" @@ -26,7 +27,7 @@ import ( ) // debug controls verbose logging. -const debug = false +var debug, _ = strconv.ParseBool(os.Getenv("GOPACKAGESDEBUG")) // A goTooOldError reports that the go command // found by exec.LookPath is too old to use the new go list behavior. @@ -711,6 +712,9 @@ func golistargs(cfg *Config, words []string) []string { fmt.Sprintf("-test=%t", cfg.Tests), fmt.Sprintf("-export=%t", usesExportData(cfg)), fmt.Sprintf("-deps=%t", cfg.Mode >= LoadImports), + // go list doesn't let you pass -test and -find together, + // probably because you'd just get the TestMain. + fmt.Sprintf("-find=%t", cfg.Mode < LoadImports && !cfg.Tests), } fullargs = append(fullargs, cfg.BuildFlags...) fullargs = append(fullargs, "--")