From: Ehden Sinai Date: Thu, 1 Feb 2024 18:38:56 +0000 (-0500) Subject: [release-branch.go1.21] cmd/go: fix build config before creating actions for 'go... X-Git-Tag: go1.21.13~3 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=e073febe901cecb3737c712b6d53a8c48684ffb5;p=gostls13.git [release-branch.go1.21] cmd/go: fix build config before creating actions for 'go list -cover' 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. For #65264 For #68212 Fixes #68221 Change-Id: Ib3f1e102ce2ef554ea08330d9db69a8c98790ac5 Reviewed-on: https://go-review.googlesource.com/c/go/+/560236 Run-TryBot: Bryan Mills Auto-Submit: Bryan Mills TryBot-Result: Gopher Robot Reviewed-by: Bryan Mills Reviewed-by: Michael Matloob (cherry picked from commit ac08c05d4daa11957fcada6db33f2150936bac27) Reviewed-on: https://go-review.googlesource.com/c/go/+/595495 LUCI-TryBot-Result: Go LUCI Reviewed-by: Than McIntosh Reviewed-by: Sam Thanawalla --- diff --git a/src/cmd/go/internal/list/list.go b/src/cmd/go/internal/list/list.go index 92020da946..f15e09b7ed 100644 --- a/src/cmd/go/internal/list/list.go +++ b/src/cmd/go/internal/list/list.go @@ -723,6 +723,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 { @@ -730,9 +733,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) } diff --git a/src/cmd/go/testdata/script/cover_list.txt b/src/cmd/go/testdata/script/cover_list.txt index 6b8aaf45d1..1b1f326662 100644 --- a/src/cmd/go/testdata/script/cover_list.txt +++ b/src/cmd/go/testdata/script/cover_list.txt @@ -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