Skip to content

Commit

Permalink
fix(): use defaultFlags when flags is empty
Browse files Browse the repository at this point in the history
Signed-off-by: Hector Martinez <hemartin@redhat.com>
  • Loading branch information
rh-hemartin committed Dec 12, 2024
1 parent 7a0941f commit e71f4d6
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions pkg/build/gobuild.go
Original file line number Diff line number Diff line change
Expand Up @@ -917,6 +917,11 @@ func createBuildArgs(ctx context.Context, buildCtx buildContext) ([]string, erro

func (g *gobuild) configForImportPath(ip string) Config {
config := g.buildConfigs[ip]
if len(config.Flags) == 0 {
// Use the default, if any.
config.Flags = g.defaultFlags
}

if g.trimpath {
// The `-trimpath` flag removes file system paths from the resulting binary, to aid reproducibility.
// Ref: https://pkg.go.dev/cmd/go#hdr-Compile_packages_and_dependencies
Expand Down Expand Up @@ -1000,13 +1005,6 @@ func (g *gobuild) buildOne(ctx context.Context, refStr string, base v1.Image, pl
return nil, fmt.Errorf("could not create env for %s: %w", ref.Path(), err)
}

// Get the build flags.
flags := config.Flags
if len(flags) == 0 {
// Use the default, if any.
flags = g.defaultFlags
}

// Get the build ldflags.
ldflags := config.Ldflags
if len(ldflags) == 0 {
Expand All @@ -1020,7 +1018,7 @@ func (g *gobuild) buildOne(ctx context.Context, refStr string, base v1.Image, pl
ip: ref.Path(),
dir: g.dir,
env: env,
flags: flags,
flags: config.Flags,
ldflags: ldflags,
platform: *platform,
})
Expand Down

0 comments on commit e71f4d6

Please sign in to comment.