From 30ba7980932dfb7ec6660ee929b4e1982256285f Mon Sep 17 00:00:00 2001 From: Michael Matloob Date: Fri, 30 Oct 2020 16:47:58 -0400 Subject: [PATCH] cmd/go: use overlaid path contents in build cache 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 Run-TryBot: Michael Matloob TryBot-Result: Go Bot Reviewed-by: Bryan C. Mills Reviewed-by: Jay Conrod --- src/cmd/go/internal/work/buildid.go | 2 ++ src/cmd/go/testdata/script/build_overlay.txt | 32 ++++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/src/cmd/go/internal/work/buildid.go b/src/cmd/go/internal/work/buildid.go index 9ef141c619..a88544e1af 100644 --- a/src/cmd/go/internal/work/buildid.go +++ b/src/cmd/go/internal/work/buildid.go @@ -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 "" diff --git a/src/cmd/go/testdata/script/build_overlay.txt b/src/cmd/go/testdata/script/build_overlay.txt index 2e558874fd..5614b41578 100644 --- a/src/cmd/go/testdata/script/build_overlay.txt +++ b/src/cmd/go/testdata/script/build_overlay.txt @@ -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