From b2fcbaeb490614650a8d2051e399acc41e4b0041 Mon Sep 17 00:00:00 2001 From: Carlos Alexandro Becker Date: Wed, 22 Feb 2017 09:25:43 -0300 Subject: [PATCH 1/2] support for custom build flags --- README.md | 7 ++++++- config/config.go | 1 + pipeline/build/build.go | 6 +++++- 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 57bf1b2e4..0ff4200e4 100644 --- a/README.md +++ b/README.md @@ -169,9 +169,14 @@ build: # Default is `main.go` main: ./cmd/main.go - # Name of the binary. Default is the name of the project directory. + # Name of the binary. + # Default is the name of the project directory. binary_name: program + # Custom build tags. + # Default is empty + flags: -tags dev + # Custom ldflags. # Default is `-s -w` ldflags: -s -w diff --git a/config/config.go b/config/config.go index a6244523b..d3e9132c1 100644 --- a/config/config.go +++ b/config/config.go @@ -28,6 +28,7 @@ type Build struct { Goarch []string Main string Ldflags string + Flags string BinaryName string `yaml:"binary_name"` Hooks Hooks } diff --git a/pipeline/build/build.go b/pipeline/build/build.go index 9b3f7bd77..3cbf3fe9e 100644 --- a/pipeline/build/build.go +++ b/pipeline/build/build.go @@ -49,7 +49,11 @@ func build(name, goos, goarch string, ctx *context.Context) error { return err } } - cmd := []string{"go", "build", "-ldflags=" + ldflags, "-o", output, ctx.Config.Build.Main} + cmd := []string{"go", "build"} + if ctx.Config.Build.Flags != "" { + cmd = append(cmd, strings.Split(ctx.Config.Build.Flags, " ")...) + } + cmd = append(cmd, "-ldflags="+ldflags, "-o", output, ctx.Config.Build.Main) if err := run(goos, goarch, cmd); err != nil { return err } From 4bee6161210c18b0805a207b50fe2aecf036477b Mon Sep 17 00:00:00 2001 From: Carlos Alexandro Becker Date: Thu, 23 Feb 2017 09:27:54 -0300 Subject: [PATCH 2/2] using strings.Split --- pipeline/build/build.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pipeline/build/build.go b/pipeline/build/build.go index 3cbf3fe9e..cb1b7796f 100644 --- a/pipeline/build/build.go +++ b/pipeline/build/build.go @@ -51,7 +51,7 @@ func build(name, goos, goarch string, ctx *context.Context) error { } cmd := []string{"go", "build"} if ctx.Config.Build.Flags != "" { - cmd = append(cmd, strings.Split(ctx.Config.Build.Flags, " ")...) + cmd = append(cmd, strings.Fields(ctx.Config.Build.Flags)...) } cmd = append(cmd, "-ldflags="+ldflags, "-o", output, ctx.Config.Build.Main) if err := run(goos, goarch, cmd); err != nil {