]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/go: fix reuse of cached objects during cover
authorRuss Cox <rsc@golang.org>
Fri, 1 Dec 2017 18:19:39 +0000 (13:19 -0500)
committerRuss Cox <rsc@golang.org>
Fri, 1 Dec 2017 21:06:14 +0000 (21:06 +0000)
The cover variable indices could vary from build to build,
but they were not included in the build ID hash, so that
reusing the previously built package was not safe.
Make the indices no longer vary from build to build,
so that caching is safe.

Fixes #22652.

Change-Id: Ie26d73c648aadd285f97e0bf39619cabc3da54f2
Reviewed-on: https://go-review.googlesource.com/81515
Run-TryBot: Russ Cox <rsc@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
src/cmd/go/go_test.go
src/cmd/go/internal/test/test.go
src/cmd/go/internal/work/buildid.go

index 691945b9efc1d6927324db88bc583d551ed1a770..c2fe8b09b4815750b823c7fb9678d0e7d6b06848 100644 (file)
@@ -4908,6 +4908,22 @@ func TestCacheOutput(t *testing.T) {
        }
 }
 
+func TestCacheCoverage(t *testing.T) {
+       if strings.Contains(os.Getenv("GODEBUG"), "gocacheverify") {
+               t.Skip("GODEBUG gocacheverify")
+       }
+
+       tg := testgo(t)
+       defer tg.cleanup()
+       tg.parallel()
+       tg.setenv("GOPATH", filepath.Join(tg.pwd(), "testdata"))
+       tg.makeTempdir()
+
+       tg.setenv("GOCACHE", filepath.Join(tg.tempdir, "c1"))
+       tg.run("test", "-cover", "strings")
+       tg.run("test", "-cover", "math", "strings")
+}
+
 func TestIssue22588(t *testing.T) {
        // Don't get confused by stderr coming from tools.
        tg := testgo(t)
index 1513a8083f88c8443e607be69d24a8d8ea7cf956..a14a3f443807a7fd3151f2cdc4673d74d1b64b68 100644 (file)
@@ -1173,8 +1173,6 @@ func recompileForTest(pmain, preal, ptest *load.Package) {
        }
 }
 
-var coverIndex = 0
-
 // isTestFile reports whether the source file is a set of tests and should therefore
 // be excluded from coverage analysis.
 func isTestFile(file string) bool {
@@ -1186,6 +1184,7 @@ func isTestFile(file string) bool {
 // to the files, to be used when annotating the files.
 func declareCoverVars(importPath string, files ...string) map[string]*load.CoverVar {
        coverVars := make(map[string]*load.CoverVar)
+       coverIndex := 0
        for _, file := range files {
                if isTestFile(file) {
                        continue
index 7c09b0d8e5b720f488915af82737339c91de7504..3c90c15a7015d8ebe2ac359bd3a1c8aa1866fb5e 100644 (file)
@@ -474,7 +474,10 @@ func (b *Builder) updateBuildID(a *Action, target string, rewrite bool) error {
                        if a.output == nil {
                                panic("internal error: a.output not set")
                        }
-                       c.Put(a.actionID, r)
+                       outputID, _, err := c.Put(a.actionID, r)
+                       if err == nil && cfg.BuildX {
+                               b.Showcmd("", "%s # internal", joinUnambiguously(str.StringList("cp", target, c.OutputFile(outputID))))
+                       }
                        c.PutBytes(cache.Subkey(a.actionID, "stdout"), a.output)
                        r.Close()
                }