Skip to content

Commit e1fbf13

Browse files
author
Bryan C. Mills
committed
cmd/go: include the "-trimpath" flag in the stamped build settings
The -trimpath flag has a strong effect on the resulting binary: in particular, it determines whether runtime.GOROOT can report a meaningful path in the absence of an explicit GOROOT environment variable. For #51461 Change-Id: Id0d55572c0a0a4e2e4724363ed80dfa05b202186 Reviewed-on: https://go-review.googlesource.com/c/go/+/391810 Trust: Bryan Mills <[email protected]> Reviewed-by: Russ Cox <[email protected]> Run-TryBot: Bryan Mills <[email protected]> TryBot-Result: Gopher Robot <[email protected]>
1 parent 0433f57 commit e1fbf13

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

src/cmd/go/internal/load/pkg.go

+3
Original file line numberDiff line numberDiff line change
@@ -2333,6 +2333,9 @@ func (p *Package) setBuildInfo(includeVCS bool) {
23332333
if tags := cfg.BuildContext.BuildTags; len(tags) > 0 {
23342334
appendSetting("-tags", strings.Join(tags, ","))
23352335
}
2336+
if cfg.BuildTrimpath {
2337+
appendSetting("-trimpath", "true")
2338+
}
23362339
cgo := "0"
23372340
if cfg.BuildContext.CgoEnabled {
23382341
cgo = "1"

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

+4
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ go build -ldflags=example.com/m=-w
2323
go version -m m$GOEXE
2424
stdout '^\tbuild\t-ldflags=example\.com/m=-w$'
2525

26+
go build -trimpath
27+
go version -m m$GOEXE
28+
stdout '\tbuild\t-trimpath=true$'
29+
2630
# gccgoflags are not added when gc is used, and vice versa.
2731
# TODO: test gccgo.
2832
go build -gccgoflags=all=UNUSED

0 commit comments

Comments
 (0)