From 6615324f79bf16e1c81951c9a18e51d1908f2698 Mon Sep 17 00:00:00 2001 From: "Bryan C. Mills" Date: Fri, 17 Mar 2023 13:12:13 -0400 Subject: [PATCH] cmd/go: compute BuildInfo and EmbedFiles when listing export data MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 'go list -export' lists the locations of compiled artifacts, so it needs to load all of the metadata needed to compile each package. Fixes #58885. Change-Id: Ie78527e0fb423698fb4195fe50e0b6925b05aa8c Reviewed-on: https://go-review.googlesource.com/c/go/+/477197 Reviewed-by: Matthew Dempsky Auto-Submit: Bryan Mills Run-TryBot: Bryan Mills TryBot-Result: Gopher Robot Reviewed-by: Daniel Martí --- src/cmd/go/internal/list/list.go | 4 ++-- .../go/testdata/script/list_export_embed.txt | 17 +++++++++++++++++ 2 files changed, 19 insertions(+), 2 deletions(-) create mode 100644 src/cmd/go/testdata/script/list_export_embed.txt diff --git a/src/cmd/go/internal/list/list.go b/src/cmd/go/internal/list/list.go index 31c14c86c6..672c3c122f 100644 --- a/src/cmd/go/internal/list/list.go +++ b/src/cmd/go/internal/list/list.go @@ -609,8 +609,8 @@ func runList(ctx context.Context, cmd *base.Command, args []string) { // might not expect those errors to stop showing up. // See issue #52443. SuppressDeps: !listJsonFields.needAny("Deps", "DepsErrors"), - SuppressBuildInfo: !listJsonFields.needAny("Stale", "StaleReason"), - SuppressEmbedFiles: !listJsonFields.needAny("EmbedFiles", "TestEmbedFiles", "XTestEmbedFiles"), + SuppressBuildInfo: !*listExport && !listJsonFields.needAny("Stale", "StaleReason"), + SuppressEmbedFiles: !*listExport && !listJsonFields.needAny("EmbedFiles", "TestEmbedFiles", "XTestEmbedFiles"), } pkgs := load.PackagesAndErrors(ctx, pkgOpts, args) if !*listE { diff --git a/src/cmd/go/testdata/script/list_export_embed.txt b/src/cmd/go/testdata/script/list_export_embed.txt new file mode 100644 index 0000000000..da74998085 --- /dev/null +++ b/src/cmd/go/testdata/script/list_export_embed.txt @@ -0,0 +1,17 @@ +# Regression test for https://go.dev/issue/58885: +# 'go list -json=Export' should not fail due to missing go:embed metadata. + +[short] skip 'runs the compiler to produce export data' + +go list -json=Export -export . + +-- go.mod -- +module example +go 1.20 +-- example.go -- +package example + +import _ "embed" + +//go:embed example.go +var src string