1
0
mirror of https://github.com/goreleaser/goreleaser.git synced 2025-02-07 13:31:37 +02:00

feat: template on flags (#923)

This commit is contained in:
Carlos Alexandro Becker 2019-01-17 10:50:00 -02:00 committed by GitHub
parent cdfaae9b28
commit 7d7951a223
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 31 additions and 2 deletions

View File

@ -60,7 +60,11 @@ func (*Builder) Build(ctx *context.Context, build config.Build, options api.Opti
}
cmd := []string{"go", "build"}
cmd = append(cmd, build.Flags...)
flags, err := processFlags(ctx, build.Flags, "")
if err != nil {
return err
}
cmd = append(cmd, flags...)
asmflags, err := processFlags(ctx, build.Asmflags, "-asmflags=")
if err != nil {

View File

@ -91,10 +91,12 @@ func TestBuild(t *testing.T) {
},
Asmflags: []string{".=", "all="},
Gcflags: []string{"all="},
Flags: []string{"{{.Env.GO_FLAGS}}"},
},
},
}
var ctx = context.New(config)
ctx.Env["GO_FLAGS"] = "-v"
ctx.Git.CurrentTag = "5.6.7"
var build = ctx.Config.Builds[0]
for _, target := range build.Targets {
@ -277,6 +279,28 @@ func TestRunInvalidLdflags(t *testing.T) {
assert.EqualError(t, err, `template: tmpl:1: unexpected "}" in operand`)
}
func TestRunInvalidFlags(t *testing.T) {
folder, back := testlib.Mktmp(t)
defer back()
writeGoodMain(t, folder)
var config = config.Project{
Builds: []config.Build{
{
Binary: "nametest",
Flags: []string{"{{.Env.GOOS}"},
Targets: []string{
runtimeTarget,
},
},
},
}
var ctx = context.New(config)
var err = Default.Build(ctx, ctx.Config.Builds[0], api.Options{
Target: runtimeTarget,
})
assert.EqualError(t, err, `template: tmpl:1: unexpected "}" in operand`)
}
func TestRunPipeWithoutMainFunc(t *testing.T) {
folder, back := testlib.Mktmp(t)
defer back()

View File

@ -25,10 +25,11 @@ builds:
# Default is the name of the project directory.
binary: program
# Set flags for custom build tags.
# Custom flags templates.
# Default is empty.
flags:
- -tags=dev
- -v
# Custom asmflags templates.
# Default is empty.