Skip to content

Commit

Permalink
[release-branch.go1.22] cmd/go: fix build config before creating acti…
Browse files Browse the repository at this point in the history
…ons 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 #68222

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>
(cherry picked from commit ac08c05)
Reviewed-on: https://go-review.googlesource.com/c/go/+/595496
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Than McIntosh <thanm@google.com>
  • Loading branch information
cixel authored and cagedmantis committed Jul 10, 2024
1 parent ea96074 commit 49906f9
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/cmd/go/internal/list/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -723,16 +723,16 @@ 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 {
if len(p.GoFiles)+len(p.CgoFiles) > 0 {
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)
}

Expand Down
4 changes: 4 additions & 0 deletions src/cmd/go/testdata/script/cover_list.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 49906f9

Please sign in to comment.