Skip to content

Commit 1d1ba85

Browse files
cespareBryan C. Mills
authored and
Bryan C. Mills
committed
cmd/go: teach the build cache about -trimpath
Fixes #31896 Change-Id: I228a809568cd37c599987f9f1e99df5c229e6c9b Reviewed-on: https://go-review.googlesource.com/c/go/+/176112 Run-TryBot: Caleb Spare <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Bryan C. Mills <[email protected]>
1 parent d0aca57 commit 1d1ba85

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

src/cmd/go/internal/work/exec.go

+6
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,9 @@ func (b *Builder) buildActionID(a *Action) cache.ActionID {
211211
fmt.Fprintf(h, "goos %s goarch %s\n", cfg.Goos, cfg.Goarch)
212212
fmt.Fprintf(h, "import %q\n", p.ImportPath)
213213
fmt.Fprintf(h, "omitdebug %v standard %v local %v prefix %q\n", p.Internal.OmitDebug, p.Standard, p.Internal.Local, p.Internal.LocalPrefix)
214+
if cfg.BuildTrimpath {
215+
fmt.Fprintln(h, "trimpath")
216+
}
214217
if p.Internal.ForceLibrary {
215218
fmt.Fprintf(h, "forcelibrary\n")
216219
}
@@ -1116,6 +1119,9 @@ func (b *Builder) linkActionID(a *Action) cache.ActionID {
11161119
fmt.Fprintf(h, "buildmode %s goos %s goarch %s\n", cfg.BuildBuildmode, cfg.Goos, cfg.Goarch)
11171120
fmt.Fprintf(h, "import %q\n", p.ImportPath)
11181121
fmt.Fprintf(h, "omitdebug %v standard %v local %v prefix %q\n", p.Internal.OmitDebug, p.Standard, p.Internal.Local, p.Internal.LocalPrefix)
1122+
if cfg.BuildTrimpath {
1123+
fmt.Fprintln(h, "trimpath")
1124+
}
11191125

11201126
// Toolchain-dependent configuration, shared with b.linkSharedActionID.
11211127
b.printLinkerConfig(h, p)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
env GO111MODULE=on
2+
3+
# Set up fresh GOCACHE.
4+
env GOCACHE=$WORK/gocache
5+
mkdir $GOCACHE
6+
7+
cd $WORK
8+
go build -o a.out
9+
10+
# Varying -trimpath should cause a rebuild.
11+
go build -x -o a.out -trimpath
12+
stderr '(compile|gccgo)( |\.exe)'
13+
stderr 'link( |\.exe)'
14+
15+
-- $WORK/hello.go --
16+
package main
17+
func main() { println("hello") }
18+
19+
-- $WORK/go.mod --
20+
module m

0 commit comments

Comments
 (0)