// for test variants of packages and users who have been providing format strings
// might not expect those errors to stop showing up.
// See issue #52443.
- SuppressDeps: !listJsonFields.needAny("Deps", "DepsErrors"),
+ SuppressDeps: !listJsonFields.needAny("Deps", "DepsErrors"),
+ SuppressBuildInfo: !listJsonFields.needAny("Stale", "StaleReason"),
}
pkgs := load.PackagesAndErrors(ctx, pkgOpts, args)
if !*listE {
if !opts.SuppressDeps {
p.collectDeps()
}
- if p.Error == nil && p.Name == "main" && !p.Internal.ForceLibrary && len(p.DepsErrors) == 0 {
+ if p.Error == nil && p.Name == "main" && !p.Internal.ForceLibrary && len(p.DepsErrors) == 0 && !opts.SuppressBuildInfo {
// TODO(bcmills): loading VCS metadata can be fairly slow.
// Consider starting this as a background goroutine and retrieving the result
// asynchronously when we're actually ready to build the package, or when we
// LoadVCS controls whether we also load version-control metadata for main packages.
LoadVCS bool
- // NeedDepsFields is true if the caller does not need Deps and DepsErrors to be populated
+ // SuppressDeps is true if the caller does not need Deps and DepsErrors to be populated
// on the package. TestPackagesAndErrors examines the Deps field to determine if the test
// variant has an import cycle, so SuppressDeps should not be set if TestPackagesAndErrors
// will be called on the package.
SuppressDeps bool
+
+ // SuppressBuildInfo is true if the caller does not need p.Stale, p.StaleReason, or p.Internal.BuildInfo
+ // to be populated on the package.
+ SuppressBuildInfo bool
}
// PackagesAndErrors returns the packages named by the command line arguments
stdout '"Deps": \['
stdout '"errors",'
+[!exec:git] skip
+
+# Test -json=<field> without Stale skips computing buildinfo
+cd repo
+exec git init
+# Control case: with -json=Stale cmd/go executes git status to compute buildinfo
+go list -json=Stale -x
+stderr 'git status'
+# Test case: without -json=Stale cmd/go skips git status
+go list -json=Name -x
+! stderr 'git status'
+
-- go.mod --
module example.com/a
"fmt"
]
}
+-- repo/go.mod --
+module example.com/repo
+-- repo/main.go --
+package main
+
+func main() {}