Skip to content

Commit

Permalink
cmd/go: use overlaid path contents in build cache
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
matloob committed Nov 12, 2020
1 parent f016172 commit 30ba798
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/cmd/go/internal/work/buildid.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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 ""
Expand Down
32 changes: 32 additions & 0 deletions src/cmd/go/testdata/script/build_overlay.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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>

Expand Down

0 comments on commit 30ba798

Please sign in to comment.