Skip to content

Commit e073feb

Browse files
cixelcagedmantis
authored andcommitted
[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 <[email protected]> Auto-Submit: Bryan Mills <[email protected]> TryBot-Result: Gopher Robot <[email protected]> Reviewed-by: Bryan Mills <[email protected]> Reviewed-by: Michael Matloob <[email protected]> (cherry picked from commit ac08c05) Reviewed-on: https://go-review.googlesource.com/c/go/+/595495 LUCI-TryBot-Result: Go LUCI <[email protected]> Reviewed-by: Than McIntosh <[email protected]> Reviewed-by: Sam Thanawalla <[email protected]>
1 parent 12e9b96 commit e073feb

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

src/cmd/go/internal/list/list.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -723,16 +723,16 @@ func runList(ctx context.Context, cmd *base.Command, args []string) {
723723
b.IsCmdList = true
724724
b.NeedExport = *listExport
725725
b.NeedCompiledGoFiles = *listCompiled
726+
if cfg.Experiment.CoverageRedesign && cfg.BuildCover {
727+
load.PrepareForCoverageBuild(pkgs)
728+
}
726729
a := &work.Action{}
727730
// TODO: Use pkgsFilter?
728731
for _, p := range pkgs {
729732
if len(p.GoFiles)+len(p.CgoFiles) > 0 {
730733
a.Deps = append(a.Deps, b.AutoAction(work.ModeInstall, work.ModeInstall, p))
731734
}
732735
}
733-
if cfg.Experiment.CoverageRedesign && cfg.BuildCover {
734-
load.PrepareForCoverageBuild(pkgs)
735-
}
736736
b.Do(ctx, a)
737737
}
738738

src/cmd/go/testdata/script/cover_list.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ cp stdout $WORK/toolbuildid.txt
3838
# Build IDs should match here.
3939
cmp $WORK/toolbuildid.txt $WORK/listbuildid.txt
4040

41+
# Make sure that the build succeeds regardless of covermode.
42+
go list -export -covermode=atomic m/example
43+
go list -export -covermode=count m/example
44+
4145
-- go.mod --
4246
module m
4347

0 commit comments

Comments
 (0)