1
0
mirror of https://github.com/goreleaser/goreleaser.git synced 2025-02-09 13:36:56 +02:00

Merge pull request #219 from goreleaser/ignore-builds2

allow ignoring specific builds
This commit is contained in:
Carlos Alexandro Becker 2017-05-02 19:08:04 -03:00 committed by GitHub
commit f392430f59
7 changed files with 119 additions and 27 deletions

View File

@ -223,6 +223,15 @@ build:
- 6
- 7
# List of combinations of GOOS + GOARCH + GOARM to ignore.
# Default is empty.
ignore:
- goos: darwin
goarch: 386
- goos: linux
goarch: arm
goarm: 7
# Hooks can be used to customize the final binary, for example, to run
# generator or whatever you want.
# Default is both hooks empty.

View File

@ -38,16 +38,22 @@ type Hooks struct {
Post string `yaml:",omitempty"`
}
// IgnoredBuild represents a build ignored by the user
type IgnoredBuild struct {
Goos, Goarch, Goarm string
}
// Build contains the build configuration section
type Build struct {
Goos []string `yaml:",omitempty"`
Goarch []string `yaml:",omitempty"`
Goarm []string `yaml:",omitempty"`
Main string `yaml:",omitempty"`
Ldflags string `yaml:",omitempty"`
Flags string `yaml:",omitempty"`
Binary string `yaml:",omitempty"`
Hooks Hooks `yaml:",omitempty"`
Goos []string `yaml:",omitempty"`
Goarch []string `yaml:",omitempty"`
Goarm []string `yaml:",omitempty"`
Ignore []IgnoredBuild `yaml:",omitempty"`
Main string `yaml:",omitempty"`
Ldflags string `yaml:",omitempty"`
Flags string `yaml:",omitempty"`
Binary string `yaml:",omitempty"`
Hooks Hooks `yaml:",omitempty"`
}
// FormatOverride is used to specify a custom format for a specific GOOS.

View File

@ -10,6 +10,14 @@ build:
- amd64
- arm
- arm64
goarm:
- 6
- 7
ignore:
- goos: darwin
goarch: 386
- goos: windows
goarch: 386
archive:
format_overrides:
- goos: windows

View File

@ -29,7 +29,7 @@ func (Pipe) Run(ctx *context.Context) error {
}
sem := make(chan bool, 4)
var g errgroup.Group
for _, target := range allBuildTargets(ctx) {
for _, target := range buildTargets(ctx) {
name, err := nameFor(ctx, target)
if err != nil {
return err

View File

@ -19,13 +19,24 @@ func (t buildTarget) String() string {
return fmt.Sprintf("%v%v%v", t.goos, t.goarch, t.goarm)
}
func buildTargets(ctx *context.Context) (targets []buildTarget) {
for _, target := range allBuildTargets(ctx) {
if !valid(target) {
log.Println("Skipped invalid build target:", target)
continue
}
if ignored(ctx, target) {
log.Println("Skipped ignored build target:", target)
continue
}
targets = append(targets, target)
}
return
}
func allBuildTargets(ctx *context.Context) (targets []buildTarget) {
for _, goos := range ctx.Config.Build.Goos {
for _, goarch := range ctx.Config.Build.Goarch {
if !valid(goos, goarch) {
log.Printf("Skipped build for %v/%v\n", goos, goarch)
continue
}
if goarch == "arm" {
for _, goarm := range ctx.Config.Build.Goarm {
targets = append(targets, buildTarget{goos, goarch, goarm})
@ -37,3 +48,23 @@ func allBuildTargets(ctx *context.Context) (targets []buildTarget) {
}
return
}
func ignored(ctx *context.Context, target buildTarget) bool {
for _, ig := range ctx.Config.Build.Ignore {
var ignored = buildTarget{ig.Goos, ig.Goarch, ig.Goarm}
if ignored == target {
return true
}
}
return false
}
func valid(target buildTarget) bool {
var s = target.goos + target.goarch
for _, a := range valids {
if a == s {
return true
}
}
return false
}

View File

@ -4,10 +4,58 @@ import (
"fmt"
"testing"
"github.com/goreleaser/goreleaser/config"
"github.com/goreleaser/goreleaser/context"
"github.com/stretchr/testify/assert"
)
func TestValid(t *testing.T) {
func TestAllBuildTargets(t *testing.T) {
var assert = assert.New(t)
var ctx = &context.Context{
Config: config.Project{
Build: config.Build{
Goos: []string{
"linux",
"darwin",
"freebsd",
},
Goarch: []string{
"386",
"amd64",
"arm",
"arm64",
},
Goarm: []string{
"6",
"7",
},
Ignore: []config.IgnoredBuild{
{
Goos: "darwin",
Goarch: "386",
}, {
Goos: "linux",
Goarch: "arm",
Goarm: "7",
},
},
},
},
}
assert.Equal([]buildTarget{
{"linux", "386", ""},
{"linux", "amd64", ""},
{"linux", "arm", "6"},
{"linux", "arm64", ""},
{"darwin", "amd64", ""},
{"freebsd", "386", ""},
{"freebsd", "amd64", ""},
{"freebsd", "arm", "6"},
{"freebsd", "arm", "7"},
}, buildTargets(ctx))
}
func TestValidGoosGoarchCombos(t *testing.T) {
var platforms = []struct {
os, arch string
}{
@ -39,12 +87,12 @@ func TestValid(t *testing.T) {
}
for _, p := range platforms {
t.Run(fmt.Sprintf("%v %v is valid", p.os, p.arch), func(t *testing.T) {
assert.True(t, valid(p.os, p.arch))
assert.True(t, valid(buildTarget{p.os, p.arch, ""}))
})
}
}
func TestInvalid(t *testing.T) {
func TestInvalidGoosGoarchCombos(t *testing.T) {
var platforms = []struct {
os, arch string
}{
@ -58,7 +106,7 @@ func TestInvalid(t *testing.T) {
}
for _, p := range platforms {
t.Run(fmt.Sprintf("%v %v is invalid", p.os, p.arch), func(t *testing.T) {
assert.False(t, valid(p.os, p.arch))
assert.False(t, valid(buildTarget{p.os, p.arch, ""}))
})
}
}

View File

@ -33,13 +33,3 @@ var valids = []string{
"windows386",
"windowsamd64",
}
func valid(goos, goarch string) bool {
var s = goos + goarch
for _, a := range valids {
if a == s {
return true
}
}
return false
}