Skip to content

Commit ac08c05

Browse files
cixelgopherbot
authored andcommitted
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. Fixes #65264. 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]>
1 parent c9d88ea commit ac08c05

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
@@ -725,16 +725,16 @@ func runList(ctx context.Context, cmd *base.Command, args []string) {
725725
b.IsCmdList = true
726726
b.NeedExport = *listExport
727727
b.NeedCompiledGoFiles = *listCompiled
728+
if cfg.Experiment.CoverageRedesign && cfg.BuildCover {
729+
load.PrepareForCoverageBuild(pkgs)
730+
}
728731
a := &work.Action{}
729732
// TODO: Use pkgsFilter?
730733
for _, p := range pkgs {
731734
if len(p.GoFiles)+len(p.CgoFiles) > 0 {
732735
a.Deps = append(a.Deps, b.AutoAction(work.ModeInstall, work.ModeInstall, p))
733736
}
734737
}
735-
if cfg.Experiment.CoverageRedesign && cfg.BuildCover {
736-
load.PrepareForCoverageBuild(pkgs)
737-
}
738738
b.Do(ctx, a)
739739
}
740740

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)