]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/go: include package source dir in build action for non-GOROOT packages
authorRuss Cox <rsc@golang.org>
Mon, 6 Nov 2017 15:16:34 +0000 (10:16 -0500)
committerRuss Cox <rsc@golang.org>
Tue, 7 Nov 2017 00:42:54 +0000 (00:42 +0000)
The package source dir is recorded in the archives,
so it must be recorded in the build action hash too.

Fixes #22596.

Change-Id: I1d3c2523181c302e9917e5fb79c26b00ea03077a
Reviewed-on: https://go-review.googlesource.com/76025
Run-TryBot: Russ Cox <rsc@golang.org>
Reviewed-by: David Crawshaw <crawshaw@golang.org>
src/cmd/go/go_test.go
src/cmd/go/internal/work/exec.go

index 9ec2e0b0ee8d9dbc6ae8def6c345b0e9d4c715e9..c56cd94732d39e19678abb13b2fcca8b1c328165 100644 (file)
@@ -4783,6 +4783,34 @@ func TestIssue22531(t *testing.T) {
        tg.run("tool", "buildid", filepath.Join(tg.tempdir, "bin/m"+exeSuffix))
 }
 
+func TestIssue22596(t *testing.T) {
+       if strings.Contains(os.Getenv("GODEBUG"), "gocacheverify") {
+               t.Skip("GODEBUG gocacheverify")
+       }
+       tg := testgo(t)
+       defer tg.cleanup()
+       tg.parallel()
+       tg.makeTempdir()
+       tg.setenv("GOCACHE", filepath.Join(tg.tempdir, "cache"))
+       tg.tempFile("gopath1/src/p/p.go", "package p; func F(){}\n")
+       tg.tempFile("gopath2/src/p/p.go", "package p; func F(){}\n")
+
+       tg.setenv("GOPATH", filepath.Join(tg.tempdir, "gopath1"))
+       tg.run("list", "-f={{.Target}}", "p")
+       target1 := strings.TrimSpace(tg.getStdout())
+       tg.run("install", "p")
+       tg.wantNotStale("p", "", "p stale after install")
+
+       tg.setenv("GOPATH", filepath.Join(tg.tempdir, "gopath2"))
+       tg.run("list", "-f={{.Target}}", "p")
+       target2 := strings.TrimSpace(tg.getStdout())
+       tg.must(os.MkdirAll(filepath.Dir(target2), 0777))
+       tg.must(copyFile(target1, target2, 0666))
+       tg.wantStale("p", "build ID mismatch", "p not stale after copy from gopath1")
+       tg.run("install", "p")
+       tg.wantNotStale("p", "", "p stale after install2")
+}
+
 func TestTestCache(t *testing.T) {
        if strings.Contains(os.Getenv("GODEBUG"), "gocacheverify") {
                t.Skip("GODEBUG gocacheverify")
index 39b39fa9de7b61180c69954ccc2ea1e16a8d3149..26c875b83062e40ba343ff20ece8923c135cbdc5 100644 (file)
@@ -177,6 +177,14 @@ func (b *Builder) buildActionID(a *Action) cache.ActionID {
        // same compiler settings and can reuse each other's results.
        // If not, the reason is already recorded in buildGcflags.
        fmt.Fprintf(h, "compile\n")
+       // The compiler hides the exact value of $GOROOT
+       // when building things in GOROOT,
+       // but it does not hide the exact value of $GOPATH.
+       // Include the full dir in that case.
+       // Assume b.WorkDir is being trimmed properly.
+       if !p.Goroot && !strings.HasPrefix(p.Dir, b.WorkDir) {
+               fmt.Fprintf(h, "dir %s\n", p.Dir)
+       }
        fmt.Fprintf(h, "goos %s goarch %s\n", cfg.Goos, cfg.Goarch)
        fmt.Fprintf(h, "import %q\n", p.ImportPath)
        fmt.Fprintf(h, "omitdebug %v standard %v local %v prefix %q\n", p.Internal.OmitDebug, p.Standard, p.Internal.Local, p.Internal.LocalPrefix)