[go] cmd/go: include the "-trimpath" flag in the stamped build settings

220 views
Skip to first unread message

Bryan Mills (Gerrit)

unread,
Mar 10, 2022, 11:46:51 PM3/10/22
to goph...@pubsubhelper.golang.org, Bryan Mills, golang-co...@googlegroups.com

Bryan Mills has uploaded this change for review.

View Change

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
---
M src/cmd/go/internal/load/pkg.go
1 file changed, 18 insertions(+), 0 deletions(-)

diff --git a/src/cmd/go/internal/load/pkg.go b/src/cmd/go/internal/load/pkg.go
index 4e60bcd..b6a0af7 100644
--- a/src/cmd/go/internal/load/pkg.go
+++ b/src/cmd/go/internal/load/pkg.go
@@ -2317,6 +2317,9 @@
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"

To view, visit change 391810. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: go
Gerrit-Branch: master
Gerrit-Change-Id: Id0d55572c0a0a4e2e4724363ed80dfa05b202186
Gerrit-Change-Number: 391810
Gerrit-PatchSet: 1
Gerrit-Owner: Bryan Mills <bcm...@google.com>
Gerrit-Reviewer: Bryan Mills <bcm...@google.com>
Gerrit-MessageType: newchange

Bryan Mills (Gerrit)

unread,
Mar 11, 2022, 12:05:30 AM3/11/22
to Bryan Mills, goph...@pubsubhelper.golang.org, golang-co...@googlegroups.com

View Change

1 comment:

  • Commit Message:

    • Patch Set #1, Line 7: cmd/go: include the "-trimpath" flag in the stamped build settings

      This ought to have a unit test.

To view, visit change 391810. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: go
Gerrit-Branch: master
Gerrit-Change-Id: Id0d55572c0a0a4e2e4724363ed80dfa05b202186
Gerrit-Change-Number: 391810
Gerrit-PatchSet: 2
Gerrit-Owner: Bryan Mills <bcm...@google.com>
Gerrit-Reviewer: Bryan Mills <bcm...@google.com>
Gerrit-Comment-Date: Fri, 11 Mar 2022 05:05:25 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Gerrit-MessageType: comment

Bryan Mills (Gerrit)

unread,
Mar 14, 2022, 5:07:23 PM3/14/22
to Bryan Mills, goph...@pubsubhelper.golang.org, golang-co...@googlegroups.com

Attention is currently required from: Bryan Mills, Michael Matloob.

Bryan Mills uploaded patch set #6 to this change.

View Change

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
---
M src/cmd/go/internal/load/pkg.go
1 file changed, 18 insertions(+), 0 deletions(-)

To view, visit change 391810. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: go
Gerrit-Branch: master
Gerrit-Change-Id: Id0d55572c0a0a4e2e4724363ed80dfa05b202186
Gerrit-Change-Number: 391810
Gerrit-PatchSet: 6
Gerrit-Owner: Bryan Mills <bcm...@google.com>
Gerrit-Reviewer: Bryan Mills <bcm...@google.com>
Gerrit-Reviewer: Gopher Robot <go...@golang.org>
Gerrit-Reviewer: Michael Matloob <mat...@golang.org>
Gerrit-Attention: Bryan Mills <bcm...@google.com>
Gerrit-Attention: Michael Matloob <mat...@golang.org>
Gerrit-MessageType: newpatchset

Bryan Mills (Gerrit)

unread,
Mar 18, 2022, 10:36:35 AM3/18/22
to Bryan Mills, goph...@pubsubhelper.golang.org, golang-co...@googlegroups.com

Attention is currently required from: Bryan Mills, Michael Matloob.

Bryan Mills uploaded patch set #15 to this change.

View Change

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
---
M src/cmd/go/internal/load/pkg.go
1 file changed, 18 insertions(+), 0 deletions(-)

To view, visit change 391810. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: go
Gerrit-Branch: master
Gerrit-Change-Id: Id0d55572c0a0a4e2e4724363ed80dfa05b202186
Gerrit-Change-Number: 391810
Gerrit-PatchSet: 15

Bryan Mills (Gerrit)

unread,
Mar 18, 2022, 10:37:39 AM3/18/22
to Bryan Mills, goph...@pubsubhelper.golang.org, golang-co...@googlegroups.com

Attention is currently required from: Bryan Mills, Michael Matloob.

Bryan Mills uploaded patch set #16 to this change.

View Change

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
---
M src/cmd/go/internal/load/pkg.go
1 file changed, 18 insertions(+), 0 deletions(-)

To view, visit change 391810. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: go
Gerrit-Branch: master
Gerrit-Change-Id: Id0d55572c0a0a4e2e4724363ed80dfa05b202186
Gerrit-Change-Number: 391810
Gerrit-PatchSet: 16

Bryan Mills (Gerrit)

unread,
Mar 18, 2022, 6:19:08 PM3/18/22
to Bryan Mills, goph...@pubsubhelper.golang.org, Gopher Robot, Russ Cox, Michael Matloob, golang-co...@googlegroups.com

Attention is currently required from: Michael Matloob.

View Change

1 comment:

  • Commit Message:

    • Patch Set #1, Line 7: cmd/go: include the "-trimpath" flag in the stamped build settings

      This ought to have a unit test.

    • Done

To view, visit change 391810. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: go
Gerrit-Branch: master
Gerrit-Change-Id: Id0d55572c0a0a4e2e4724363ed80dfa05b202186
Gerrit-Change-Number: 391810
Gerrit-PatchSet: 18
Gerrit-Owner: Bryan Mills <bcm...@google.com>
Gerrit-Reviewer: Bryan Mills <bcm...@google.com>
Gerrit-Reviewer: Gopher Robot <go...@golang.org>
Gerrit-Reviewer: Michael Matloob <mat...@golang.org>
Gerrit-Reviewer: Russ Cox <r...@golang.org>
Gerrit-Attention: Michael Matloob <mat...@golang.org>
Gerrit-Comment-Date: Fri, 18 Mar 2022 22:19:02 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Comment-In-Reply-To: Bryan Mills <bcm...@google.com>
Gerrit-MessageType: comment

Bryan Mills (Gerrit)

unread,
Mar 18, 2022, 6:19:08 PM3/18/22
to Bryan Mills, goph...@pubsubhelper.golang.org, golang-co...@googlegroups.com

Attention is currently required from: Michael Matloob.

Bryan Mills uploaded patch set #18 to this change.

View Change

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
---
M src/cmd/go/internal/load/pkg.go
1 file changed, 18 insertions(+), 0 deletions(-)

To view, visit change 391810. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: go
Gerrit-Branch: master
Gerrit-Change-Id: Id0d55572c0a0a4e2e4724363ed80dfa05b202186
Gerrit-Change-Number: 391810
Gerrit-PatchSet: 18
Gerrit-Owner: Bryan Mills <bcm...@google.com>
Gerrit-Reviewer: Bryan Mills <bcm...@google.com>
Gerrit-Reviewer: Gopher Robot <go...@golang.org>
Gerrit-Reviewer: Michael Matloob <mat...@golang.org>
Gerrit-Reviewer: Russ Cox <r...@golang.org>
Gerrit-Attention: Michael Matloob <mat...@golang.org>
Gerrit-MessageType: newpatchset

Bryan Mills (Gerrit)

unread,
Mar 18, 2022, 6:19:50 PM3/18/22
to Bryan Mills, goph...@pubsubhelper.golang.org, golang-co...@googlegroups.com

Attention is currently required from: Michael Matloob.

Bryan Mills uploaded patch set #19 to this change.

View Change

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
---
M src/cmd/go/internal/load/pkg.go
M src/cmd/go/testdata/script/version_build_settings.txt
2 files changed, 22 insertions(+), 0 deletions(-)

To view, visit change 391810. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: go
Gerrit-Branch: master
Gerrit-Change-Id: Id0d55572c0a0a4e2e4724363ed80dfa05b202186
Gerrit-Change-Number: 391810
Gerrit-PatchSet: 19

Bryan Mills (Gerrit)

unread,
Mar 18, 2022, 6:22:28 PM3/18/22
to Bryan Mills, goph...@pubsubhelper.golang.org, Gopher Robot, Russ Cox, Michael Matloob, golang-co...@googlegroups.com

Attention is currently required from: Michael Matloob.

Patch set 19:Run-TryBot +1

View Change

1 comment:

To view, visit change 391810. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: go
Gerrit-Branch: master
Gerrit-Change-Id: Id0d55572c0a0a4e2e4724363ed80dfa05b202186
Gerrit-Change-Number: 391810
Gerrit-PatchSet: 19
Gerrit-Owner: Bryan Mills <bcm...@google.com>
Gerrit-Reviewer: Bryan Mills <bcm...@google.com>
Gerrit-Reviewer: Gopher Robot <go...@golang.org>
Gerrit-Reviewer: Michael Matloob <mat...@golang.org>
Gerrit-Reviewer: Russ Cox <r...@golang.org>
Gerrit-Attention: Michael Matloob <mat...@golang.org>
Gerrit-Comment-Date: Fri, 18 Mar 2022 22:22:25 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: Yes
Gerrit-MessageType: comment

Bryan Mills (Gerrit)

unread,
Mar 18, 2022, 6:41:49 PM3/18/22
to Bryan Mills, goph...@pubsubhelper.golang.org, golang-...@googlegroups.com, Gopher Robot, Russ Cox, Michael Matloob, golang-co...@googlegroups.com

Bryan Mills submitted this change.

View Change



16 is the latest approved patch-set.
The change was submitted with unreviewed changes in the following files:

```
The name of the file: src/cmd/go/testdata/script/version_build_settings.txt
Insertions: 4, Deletions: 0.

The diff is too large to show. Please review the diff.
```

Approvals: Russ Cox: Looks good to me, approved Bryan Mills: Trusted; Run TryBots Gopher Robot: TryBots succeeded
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 <bcm...@google.com>
Reviewed-by: Russ Cox <r...@golang.org>
Run-TryBot: Bryan Mills <bcm...@google.com>
TryBot-Result: Gopher Robot <go...@golang.org>

---
M src/cmd/go/internal/load/pkg.go
M src/cmd/go/testdata/script/version_build_settings.txt
2 files changed, 27 insertions(+), 0 deletions(-)

diff --git a/src/cmd/go/internal/load/pkg.go b/src/cmd/go/internal/load/pkg.go
index ab70845..2592cf5 100644
--- a/src/cmd/go/internal/load/pkg.go
+++ b/src/cmd/go/internal/load/pkg.go
@@ -2333,6 +2333,9 @@

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"
diff --git a/src/cmd/go/testdata/script/version_build_settings.txt b/src/cmd/go/testdata/script/version_build_settings.txt
index dc9e676..90c72537 100644
--- a/src/cmd/go/testdata/script/version_build_settings.txt
+++ b/src/cmd/go/testdata/script/version_build_settings.txt
@@ -23,6 +23,10 @@
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

To view, visit change 391810. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: go
Gerrit-Branch: master
Gerrit-Change-Id: Id0d55572c0a0a4e2e4724363ed80dfa05b202186
Gerrit-Change-Number: 391810
Gerrit-PatchSet: 20
Gerrit-Owner: Bryan Mills <bcm...@google.com>
Gerrit-Reviewer: Bryan Mills <bcm...@google.com>
Gerrit-Reviewer: Gopher Robot <go...@golang.org>
Gerrit-Reviewer: Michael Matloob <mat...@golang.org>
Gerrit-Reviewer: Russ Cox <r...@golang.org>
Gerrit-MessageType: merged
Reply all
Reply to author
Forward
0 new messages