mirror of
https://github.com/golang/go
synced 2024-11-21 23:24:41 -07:00
trim paths from ldflags in BuildInfo instead of removing them
Fixes #63432
This commit is contained in:
parent
3145a2fed6
commit
7f6c9d55dd
@ -2348,8 +2348,9 @@ func (p *Package) setBuildInfo(ctx context.Context, autoVCS bool) {
|
|||||||
// redact only those paths from the recorded -ldflags setting and still
|
// redact only those paths from the recorded -ldflags setting and still
|
||||||
// record the system-independent parts of the flags.
|
// record the system-independent parts of the flags.
|
||||||
if !cfg.BuildTrimpath {
|
if !cfg.BuildTrimpath {
|
||||||
appendSetting("-ldflags", ldflags)
|
ldflags = trimLdFlags(ldflags)
|
||||||
}
|
}
|
||||||
|
appendSetting("-ldflags", ldflags)
|
||||||
}
|
}
|
||||||
if cfg.BuildCover {
|
if cfg.BuildCover {
|
||||||
appendSetting("-cover", "true")
|
appendSetting("-cover", "true")
|
||||||
@ -2505,6 +2506,12 @@ omitVCS:
|
|||||||
p.Internal.BuildInfo = info
|
p.Internal.BuildInfo = info
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// trimLdFlags replaces know paths with variable and removes
|
||||||
|
// flags with absolute paths
|
||||||
|
func trimLdFlags(flags string) string {
|
||||||
|
return flags
|
||||||
|
}
|
||||||
|
|
||||||
// SafeArg reports whether arg is a "safe" command-line argument,
|
// SafeArg reports whether arg is a "safe" command-line argument,
|
||||||
// meaning that when it appears in a command-line, it probably
|
// meaning that when it appears in a command-line, it probably
|
||||||
// doesn't have some special meaning other than its own name.
|
// doesn't have some special meaning other than its own name.
|
||||||
|
@ -247,6 +247,27 @@ build -ldflags="-flag1 -flag2"
|
|||||||
build CGO_ENABLED=0
|
build CGO_ENABLED=0
|
||||||
build GOARCH=foo
|
build GOARCH=foo
|
||||||
build GOOS=bar
|
build GOOS=bar
|
||||||
|
`,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "ldflags with trimpath",
|
||||||
|
buildContext: map[string]string{
|
||||||
|
"arch": "foo",
|
||||||
|
"os": "bar",
|
||||||
|
"compiler": "baz",
|
||||||
|
"cgo": "false",
|
||||||
|
"ldflags": "-flag1 -flag2",
|
||||||
|
"trimpath": "true",
|
||||||
|
},
|
||||||
|
pkg: Package{},
|
||||||
|
autoVCS: true,
|
||||||
|
want: `build -buildmode=
|
||||||
|
build -compiler=baz
|
||||||
|
build -ldflags="-flag1 -flag2"
|
||||||
|
build -trimpath=true
|
||||||
|
build CGO_ENABLED=0
|
||||||
|
build GOARCH=foo
|
||||||
|
build GOOS=bar
|
||||||
`,
|
`,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user