IgnoreImports: *listFind,
ModResolveTests: *listTest,
LoadVCS: true,
+ // SuppressDeps is set if the user opts to explicitly ask for the json fields they
+ // need, don't ask for Deps or DepsErrors. It's not set when using a template string,
+ // even if *listFmt doesn't contain .Deps because Deps are used to find import cycles
+ // 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"),
}
pkgs := load.PackagesAndErrors(ctx, pkgOpts, args)
if !*listE {
}
}
p.Internal.Imports = imports
- p.collectDeps()
+ if !opts.SuppressDeps {
+ p.collectDeps()
+ }
if p.Error == nil && p.Name == "main" && !p.Internal.ForceLibrary && len(p.DepsErrors) == 0 {
// TODO(bcmills): loading VCS metadata can be fairly slow.
// Consider starting this as a background goroutine and retrieving the result
// 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
+ // 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
}
// PackagesAndErrors returns the packages named by the command line arguments
go list -json=ImportPath,Name,GoFiles,Imports
cmp stdout want-json-multiple.txt
+# Test -json=<field> with Deps outputs the Deps field.
+go list -json=Deps
+stdout '"Deps": \['
+stdout '"errors",'
+
-- go.mod --
module example.com/a