]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/go: include the "-trimpath" flag in the stamped build settings
authorBryan C. Mills <bcmills@google.com>
Wed, 9 Mar 2022 17:01:16 +0000 (12:01 -0500)
committerBryan Mills <bcmills@google.com>
Fri, 18 Mar 2022 22:41:45 +0000 (22:41 +0000)
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 <bcmills@google.com>
Reviewed-by: Russ Cox <rsc@golang.org>
Run-TryBot: Bryan Mills <bcmills@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>

src/cmd/go/internal/load/pkg.go
src/cmd/go/testdata/script/version_build_settings.txt

index ab70845959650fee08117810444dc79247ffce17..2592cf54477405fb2776dc7cb3b5fb3f5120cc3a 100644 (file)
@@ -2333,6 +2333,9 @@ func (p *Package) setBuildInfo(includeVCS bool) {
        if tags := cfg.BuildContext.BuildTags; len(tags) > 0 {
                appendSetting("-tags", strings.Join(tags, ","))
        }
+       if cfg.BuildTrimpath {
+               appendSetting("-trimpath", "true")
+       }
        cgo := "0"
        if cfg.BuildContext.CgoEnabled {
                cgo = "1"
index dc9e67681ea998049e2da46a0584b1d6d514174a..90c72537648702855c65e5da706cce50c09dea4f 100644 (file)
@@ -23,6 +23,10 @@ go build -ldflags=example.com/m=-w
 go version -m m$GOEXE
 stdout '^\tbuild\t-ldflags=example\.com/m=-w$'
 
+go build -trimpath
+go version -m m$GOEXE
+stdout '\tbuild\t-trimpath=true$'
+
 # gccgoflags are not added when gc is used, and vice versa.
 # TODO: test gccgo.
 go build -gccgoflags=all=UNUSED