Commit 8ac93e66 authored by Russ Cox's avatar Russ Cox

cmd/go: include package source dir in build action for non-GOROOT packages

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: 's avatarDavid Crawshaw <crawshaw@golang.org>
parent 17ff23f7
......@@ -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")
......
......@@ -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)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment