]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/go: include coverage build flags for "go list"
authorThan McIntosh <thanm@google.com>
Fri, 13 Jan 2023 21:46:49 +0000 (16:46 -0500)
committerThan McIntosh <thanm@google.com>
Tue, 17 Jan 2023 16:41:24 +0000 (16:41 +0000)
This patch ensures that the go command's "list" subcommand accepts
coverage-related build options, which were incorrectly left out when
"go build -cover" was rolled out. This is needed in order to do things
like check the staleness of an installed cover-instrumented target.

Fixes #57785.

Change-Id: I140732ff1e6b83cd9c453701bb8199b333fc0f2e
Reviewed-on: https://go-review.googlesource.com/c/go/+/462116
Reviewed-by: Bryan Mills <bcmills@google.com>
Reviewed-by: Russ Cox <rsc@golang.org>
Run-TryBot: Than McIntosh <thanm@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>

src/cmd/go/internal/list/list.go
src/cmd/go/testdata/script/cover_list.txt [new file with mode: 0644]

index 72201850b284b3cbaa6054bf5f0b4fc909e5ae6c..811d659ba3bd542bf03cba29d2b835125a15c01b 100644 (file)
@@ -336,6 +336,9 @@ For more about modules, see https://golang.org/ref/mod.
 func init() {
        CmdList.Run = runList // break init cycle
        work.AddBuildFlags(CmdList, work.DefaultBuildFlags)
+       if cfg.Experiment != nil && cfg.Experiment.CoverageRedesign {
+               work.AddCoverFlags(CmdList, nil)
+       }
        CmdList.Flag.Var(&listJsonFields, "json", "")
 }
 
diff --git a/src/cmd/go/testdata/script/cover_list.txt b/src/cmd/go/testdata/script/cover_list.txt
new file mode 100644 (file)
index 0000000..c66c087
--- /dev/null
@@ -0,0 +1,28 @@
+
+# This test is intended to verify that "go list" accepts coverage related
+# build arguments (such as -cover, -covermode). See issue #57785.
+
+[short] skip
+[!GOEXPERIMENT:coverageredesign] skip
+
+env GOBIN=$WORK/bin
+
+# Install a target and then do an ordinary staleness check on it.
+go install m/example
+! stale m/example
+
+# Run a second staleness check with "-cover" as a build flag. The
+# installed target should indeed be stale, since we didn't build it
+# with -cover.
+stale -cover m/example
+
+-- go.mod --
+module m
+
+go 1.20
+-- example/main.go --
+package main
+
+func main() {
+     println("hi mom")
+}