Skip to content

Commit

Permalink
Merge pull request #82 from grafana/feature/goflags
Browse files Browse the repository at this point in the history
Update build flags to make `-trimpath` go flag configurable
  • Loading branch information
oleiade authored Jan 30, 2024
2 parents 7028164 + c11283f commit ff146f7
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
3 changes: 1 addition & 2 deletions builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ func (b Builder) Build(ctx context.Context, outputFile string) error {
raceArg := "-race"

// trim debug symbols by default
buildFlags := b.osEnvOrDefaultValue("XK6_BUILD_FLAGS", "-ldflags='-w -s'")
buildFlags := b.osEnvOrDefaultValue("XK6_BUILD_FLAGS", "-ldflags='-w -s' -trimpath")

buildFlagsSlice := buildCommandArgs(buildFlags, absOutputFile)

Expand Down Expand Up @@ -297,7 +297,6 @@ func buildCommandArgs(buildFlags, absOutputFile string) []string {
}

buildFlagsSlice = append(buildFlagsSlice, tmp...)
buildFlagsSlice = append(buildFlagsSlice, "-trimpath")

return buildFlagsSlice
}
10 changes: 5 additions & 5 deletions builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,31 +100,31 @@ func TestBuildCommandArgs(t *testing.T) {
{
buildFlags: "",
want: []string{
"build", "-o", "binfile", "-trimpath",
"build", "-o", "binfile",
},
},
{
buildFlags: "-ldflags='-w -s'",
want: []string{
"build", "-o", "binfile", "-ldflags=-w -s", "-trimpath",
"build", "-o", "binfile", "-ldflags=-w -s",
},
},
{
buildFlags: "-race -buildvcs=false",
want: []string{
"build", "-o", "binfile", "-race", "-buildvcs=false", "-trimpath",
"build", "-o", "binfile", "-race", "-buildvcs=false",
},
},
{
buildFlags: `-buildvcs=false -ldflags="-s -w" -race`,
want: []string{
"build", "-o", "binfile", "-buildvcs=false", "-ldflags=-s -w", "-race", "-trimpath",
"build", "-o", "binfile", "-buildvcs=false", "-ldflags=-s -w", "-race",
},
},
{
buildFlags: `-ldflags="-s -w" -race -buildvcs=false`,
want: []string{
"build", "-o", "binfile", "-ldflags=-s -w", "-race", "-buildvcs=false", "-trimpath",
"build", "-o", "binfile", "-ldflags=-s -w", "-race", "-buildvcs=false",
},
},
}
Expand Down

0 comments on commit ff146f7

Please sign in to comment.