From e71f4d63902b401fd194fb665b0e3c347aad2d77 Mon Sep 17 00:00:00 2001 From: Hector Martinez Date: Thu, 12 Dec 2024 09:44:35 +0100 Subject: [PATCH] fix(): use defaultFlags when flags is empty Signed-off-by: Hector Martinez --- pkg/build/gobuild.go | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/pkg/build/gobuild.go b/pkg/build/gobuild.go index 6776896a4..eb661110c 100644 --- a/pkg/build/gobuild.go +++ b/pkg/build/gobuild.go @@ -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 @@ -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 { @@ -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, })