]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/go: use overlaid path contents in build cache
authorMichael Matloob <matloob@golang.org>
Fri, 30 Oct 2020 20:47:58 +0000 (16:47 -0400)
committerMichael Matloob <matloob@golang.org>
Thu, 12 Nov 2020 22:50:40 +0000 (22:50 +0000)
When caching actions, use the overlaid file contents, because those
are the ones actually used to produce the outputs.

For #39958

Change-Id: Ia1f85b2fcf1f26e3b5be82f4d35c2726b134a36b
Reviewed-on: https://go-review.googlesource.com/c/go/+/266720
Trust: Michael Matloob <matloob@golang.org>
Run-TryBot: Michael Matloob <matloob@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Bryan C. Mills <bcmills@google.com>
Reviewed-by: Jay Conrod <jayconrod@google.com>
src/cmd/go/internal/work/buildid.go
src/cmd/go/testdata/script/build_overlay.txt

index 9ef141c619a96ba3a28878f367a5ae53a33fa3a5..a88544e1af97c80bf30d179e9df283e916b37203 100644 (file)
@@ -15,6 +15,7 @@ import (
        "cmd/go/internal/base"
        "cmd/go/internal/cache"
        "cmd/go/internal/cfg"
+       "cmd/go/internal/fsys"
        "cmd/go/internal/str"
        "cmd/internal/buildid"
 )
@@ -375,6 +376,7 @@ func (b *Builder) buildID(file string) string {
 
 // fileHash returns the content hash of the named file.
 func (b *Builder) fileHash(file string) string {
+       file, _ = fsys.OverlayPath(file)
        sum, err := cache.FileHash(file)
        if err != nil {
                return ""
index 2e558874fd992ef935c02b34cda81feb621405eb..5614b415783d93caaaa5c907b5e3201d7f2a3de6 100644 (file)
@@ -47,6 +47,14 @@ go build -overlay overlay.json -o main_call_asm$GOEXE ./call_asm
 exec ./main_call_asm$GOEXE
 ! stdout .
 
+# Change the contents of a file in the overlay and ensure that makes the target stale
+go install -overlay overlay.json ./test_cache
+go list -overlay overlay.json -f '{{.Stale}}' ./test_cache
+stdout '^false$'
+cp overlay/test_cache_different.go overlay/test_cache.go
+go list -overlay overlay.json -f '{{.Stale}}' ./test_cache
+stdout '^true$'
+
 go list -compiled -overlay overlay.json -f '{{range .CompiledGoFiles}}{{. | printf "%s\n"}}{{end}}' ./cgo_hello_replace
 cp stdout compiled_cgo_sources.txt
 go run ../print_line_comments.go compiled_cgo_sources.txt
@@ -87,6 +95,13 @@ go build -compiler=gccgo -overlay overlay.json -o main_call_asm_gccgo$GOEXE ./ca
 exec ./main_call_asm_gccgo$GOEXE
 ! stdout .
 
+go install -gccgo -overlay overlay.json ./test_cache
+go list -gccgo -overlay overlay.json -f '{{.Stale}}' ./test_cache
+stdout '^false$'
+cp overlay/test_cache_different.go overlay/test_cache.go
+go list -gccgo -overlay overlay.json -f '{{.Stale}}' ./test_cache
+stdout '^true$'
+
 -- m/go.mod --
 // TODO(matloob): how do overlays work with go.mod (especially if mod=readonly)
 module m
@@ -114,6 +129,7 @@ the actual code is in the overlay
                "printpath/main.go": "overlay/printpath.go",
                "printpath/other.go": "overlay2/printpath2.go",
                "call_asm/asm.s": "overlay/asm_file.s",
+               "test_cache/main.go": "overlay/test_cache.go",
                "cgo_hello_replace/cgo_header.h": "overlay/cgo_head.h",
                "cgo_hello_replace/hello.c": "overlay/hello.c",
                "cgo_hello_quote/cgo_hello.go": "overlay/cgo_hello_quote.go",
@@ -230,6 +246,22 @@ void say_hello() { puts("hello cgo\n"); fflush(stdout); }
 TEXT ·foo(SB),0,$0
        RET
 
+-- m/overlay/test_cache.go --
+package foo
+
+import "fmt"
+
+func bar() {
+    fmt.Println("something")
+}
+-- m/overlay/test_cache_different.go --
+package foo
+
+import "fmt"
+
+func bar() {
+    fmt.Println("different")
+}
 -- m/cgo_hello_quote/hello.c --
 #include <stdio.h>