File tree 2 files changed +29
-1
lines changed 2 files changed +29
-1
lines changed Original file line number Diff line number Diff line change @@ -2348,8 +2348,9 @@ func (p *Package) setBuildInfo(ctx context.Context, autoVCS bool) {
2348
2348
// redact only those paths from the recorded -ldflags setting and still
2349
2349
// record the system-independent parts of the flags.
2350
2350
if ! cfg .BuildTrimpath {
2351
- appendSetting ( "- ldflags" , ldflags )
2351
+ ldflags = trimLdFlags ( ldflags )
2352
2352
}
2353
+ appendSetting ("-ldflags" , ldflags )
2353
2354
}
2354
2355
if cfg .BuildCover {
2355
2356
appendSetting ("-cover" , "true" )
@@ -2505,6 +2506,12 @@ omitVCS:
2505
2506
p .Internal .BuildInfo = info
2506
2507
}
2507
2508
2509
+ // trimLdFlags replaces know paths with variable and removes
2510
+ // flags with absolute paths
2511
+ func trimLdFlags (flags string ) string {
2512
+ return flags
2513
+ }
2514
+
2508
2515
// SafeArg reports whether arg is a "safe" command-line argument,
2509
2516
// meaning that when it appears in a command-line, it probably
2510
2517
// doesn't have some special meaning other than its own name.
Original file line number Diff line number Diff line change @@ -247,6 +247,27 @@ build -ldflags="-flag1 -flag2"
247
247
build CGO_ENABLED=0
248
248
build GOARCH=foo
249
249
build GOOS=bar
250
+ ` ,
251
+ },
252
+ {
253
+ name : "ldflags with trimpath" ,
254
+ buildContext : map [string ]string {
255
+ "arch" : "foo" ,
256
+ "os" : "bar" ,
257
+ "compiler" : "baz" ,
258
+ "cgo" : "false" ,
259
+ "ldflags" : "-flag1 -flag2" ,
260
+ "trimpath" : "true" ,
261
+ },
262
+ pkg : Package {},
263
+ autoVCS : true ,
264
+ want : `build -buildmode=
265
+ build -compiler=baz
266
+ build -ldflags="-flag1 -flag2"
267
+ build -trimpath=true
268
+ build CGO_ENABLED=0
269
+ build GOARCH=foo
270
+ build GOOS=bar
250
271
` ,
251
272
},
252
273
{
You can’t perform that action at this time.
0 commit comments