]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/go: fix build config before creating actions for 'go list -cover'
authorEhden Sinai <ehdens@gmail.com>
Thu, 1 Feb 2024 18:38:56 +0000 (13:38 -0500)
committerGopher Robot <gobot@golang.org>
Thu, 1 Feb 2024 22:47:28 +0000 (22:47 +0000)
When -covermode is set to atomic, instrumented packages need to import
sync/atomic. If this is not already imported by a package being
instrumented, the build needs to ensure that sync/atomic is compiled
whenever 'go list' is run in a way that triggers package builds.

The build config was already being made to ensure the import, but only
after the action graph had been created, so there was no guarantee that
sync/atomic would be built when needed.

Fixes #65264.

Change-Id: Ib3f1e102ce2ef554ea08330d9db69a8c98790ac5
Reviewed-on: https://go-review.googlesource.com/c/go/+/560236
Run-TryBot: Bryan Mills <bcmills@google.com>
Auto-Submit: Bryan Mills <bcmills@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Bryan Mills <bcmills@google.com>
Reviewed-by: Michael Matloob <matloob@golang.org>
src/cmd/go/internal/list/list.go
src/cmd/go/testdata/script/cover_list.txt

index db587148826281b432bcadb1ddf756bee774cc04..66fb5aa31cb7146cc969540c6f47706c0e1cac6e 100644 (file)
@@ -725,6 +725,9 @@ func runList(ctx context.Context, cmd *base.Command, args []string) {
                b.IsCmdList = true
                b.NeedExport = *listExport
                b.NeedCompiledGoFiles = *listCompiled
+               if cfg.Experiment.CoverageRedesign && cfg.BuildCover {
+                       load.PrepareForCoverageBuild(pkgs)
+               }
                a := &work.Action{}
                // TODO: Use pkgsFilter?
                for _, p := range pkgs {
@@ -732,9 +735,6 @@ func runList(ctx context.Context, cmd *base.Command, args []string) {
                                a.Deps = append(a.Deps, b.AutoAction(work.ModeInstall, work.ModeInstall, p))
                        }
                }
-               if cfg.Experiment.CoverageRedesign && cfg.BuildCover {
-                       load.PrepareForCoverageBuild(pkgs)
-               }
                b.Do(ctx, a)
        }
 
index 6b8aaf45d1e123e7b7b3d7036d7bb4f6ccc79a87..1b1f32666221557fdc67b2b0fe6a8390b873e9f2 100644 (file)
@@ -38,6 +38,10 @@ cp stdout $WORK/toolbuildid.txt
 # Build IDs should match here.
 cmp $WORK/toolbuildid.txt $WORK/listbuildid.txt
 
+# Make sure that the build succeeds regardless of covermode.
+go list -export -covermode=atomic m/example
+go list -export -covermode=count m/example
+
 -- go.mod --
 module m