Skip to content

Commit 30ba798

Browse files
committed
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 <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>
1 parent f016172 commit 30ba798

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

src/cmd/go/internal/work/buildid.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515
"cmd/go/internal/base"
1616
"cmd/go/internal/cache"
1717
"cmd/go/internal/cfg"
18+
"cmd/go/internal/fsys"
1819
"cmd/go/internal/str"
1920
"cmd/internal/buildid"
2021
)
@@ -375,6 +376,7 @@ func (b *Builder) buildID(file string) string {
375376

376377
// fileHash returns the content hash of the named file.
377378
func (b *Builder) fileHash(file string) string {
379+
file, _ = fsys.OverlayPath(file)
378380
sum, err := cache.FileHash(file)
379381
if err != nil {
380382
return ""

src/cmd/go/testdata/script/build_overlay.txt

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,14 @@ go build -overlay overlay.json -o main_call_asm$GOEXE ./call_asm
4747
exec ./main_call_asm$GOEXE
4848
! stdout .
4949

50+
# Change the contents of a file in the overlay and ensure that makes the target stale
51+
go install -overlay overlay.json ./test_cache
52+
go list -overlay overlay.json -f '{{.Stale}}' ./test_cache
53+
stdout '^false$'
54+
cp overlay/test_cache_different.go overlay/test_cache.go
55+
go list -overlay overlay.json -f '{{.Stale}}' ./test_cache
56+
stdout '^true$'
57+
5058
go list -compiled -overlay overlay.json -f '{{range .CompiledGoFiles}}{{. | printf "%s\n"}}{{end}}' ./cgo_hello_replace
5159
cp stdout compiled_cgo_sources.txt
5260
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
8795
exec ./main_call_asm_gccgo$GOEXE
8896
! stdout .
8997

98+
go install -gccgo -overlay overlay.json ./test_cache
99+
go list -gccgo -overlay overlay.json -f '{{.Stale}}' ./test_cache
100+
stdout '^false$'
101+
cp overlay/test_cache_different.go overlay/test_cache.go
102+
go list -gccgo -overlay overlay.json -f '{{.Stale}}' ./test_cache
103+
stdout '^true$'
104+
90105
-- m/go.mod --
91106
// TODO(matloob): how do overlays work with go.mod (especially if mod=readonly)
92107
module m
@@ -114,6 +129,7 @@ the actual code is in the overlay
114129
"printpath/main.go": "overlay/printpath.go",
115130
"printpath/other.go": "overlay2/printpath2.go",
116131
"call_asm/asm.s": "overlay/asm_file.s",
132+
"test_cache/main.go": "overlay/test_cache.go",
117133
"cgo_hello_replace/cgo_header.h": "overlay/cgo_head.h",
118134
"cgo_hello_replace/hello.c": "overlay/hello.c",
119135
"cgo_hello_quote/cgo_hello.go": "overlay/cgo_hello_quote.go",
@@ -230,6 +246,22 @@ void say_hello() { puts("hello cgo\n"); fflush(stdout); }
230246
TEXT ·foo(SB),0,$0
231247
RET
232248

249+
-- m/overlay/test_cache.go --
250+
package foo
251+
252+
import "fmt"
253+
254+
func bar() {
255+
fmt.Println("something")
256+
}
257+
-- m/overlay/test_cache_different.go --
258+
package foo
259+
260+
import "fmt"
261+
262+
func bar() {
263+
fmt.Println("different")
264+
}
233265
-- m/cgo_hello_quote/hello.c --
234266
#include <stdio.h>
235267

0 commit comments

Comments
 (0)