]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/go: compute BuildInfo and EmbedFiles when listing export data
authorBryan C. Mills <bcmills@google.com>
Fri, 17 Mar 2023 17:12:13 +0000 (13:12 -0400)
committerGopher Robot <gobot@golang.org>
Wed, 29 Mar 2023 22:01:35 +0000 (22:01 +0000)
'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 <mdempsky@google.com>
Auto-Submit: Bryan Mills <bcmills@google.com>
Run-TryBot: Bryan Mills <bcmills@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Daniel Martí <mvdan@mvdan.cc>
src/cmd/go/internal/list/list.go
src/cmd/go/testdata/script/list_export_embed.txt [new file with mode: 0644]

index 31c14c86c6a63ee7b6898b8ac23ae582d1ac1d21..672c3c122f6291191ef810b7f1217f668e81dbdf 100644 (file)
@@ -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 (file)
index 0000000..da74998
--- /dev/null
@@ -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