1
0
mirror of https://github.com/goreleaser/goreleaser.git synced 2024-12-27 01:33:39 +02:00

moving targets to buildtarget package as well

This commit is contained in:
Carlos Alexandro Becker 2017-07-09 13:14:35 -03:00
parent 61930182c6
commit 485f71b51a
No known key found for this signature in database
GPG Key ID: E61E2F7DC14AB940
5 changed files with 107 additions and 109 deletions

View File

@ -0,0 +1,93 @@
package buildtarget
import (
"github.com/apex/log"
"github.com/goreleaser/goreleaser/config"
)
// All returns all valid build targets for a given build
func All(build config.Build) (targets []Target) {
for _, target := range allBuildTargets(build) {
if !valid(target) {
log.WithField("target", target.String()).
Warn("skipped invalid build")
continue
}
if ignored(build, target) {
log.WithField("target", target.String()).
Warn("skipped ignored build")
continue
}
targets = append(targets, target)
}
return
}
func allBuildTargets(build config.Build) (targets []Target) {
for _, goos := range build.Goos {
for _, goarch := range build.Goarch {
if goarch == "arm" {
for _, goarm := range build.Goarm {
targets = append(targets, New(goos, goarch, goarm))
}
continue
}
targets = append(targets, New(goos, goarch, ""))
}
}
return
}
func ignored(build config.Build, target Target) bool {
for _, ig := range build.Ignore {
var ignored = New(ig.Goos, ig.Goarch, ig.Goarm)
if ignored == target {
return true
}
}
return false
}
func valid(target Target) bool {
var s = target.OS + target.Arch
for _, a := range validTargets {
if a == s {
return true
}
}
return false
}
// list from https://golang.org/doc/install/source#environment
var validTargets = []string{
"androidarm",
"darwin386",
"darwinamd64",
// "darwinarm", - requires admin rights and other ios stuff
// "darwinarm64", - requires admin rights and other ios stuff
"dragonflyamd64",
"freebsd386",
"freebsdamd64",
"freebsdarm",
"linux386",
"linuxamd64",
"linuxarm",
"linuxarm64",
"linuxppc64",
"linuxppc64le",
"linuxmips",
"linuxmipsle",
"linuxmips64",
"linuxmips64le",
"netbsd386",
"netbsdamd64",
"netbsdarm",
"openbsd386",
"openbsdamd64",
"openbsdarm",
"plan9386",
"plan9amd64",
"solarisamd64",
"windows386",
"windowsamd64",
}

View File

@ -1,11 +1,10 @@
package build
package buildtarget
import (
"fmt"
"testing"
"github.com/goreleaser/goreleaser/config"
"github.com/goreleaser/goreleaser/internal/buildtarget"
"github.com/stretchr/testify/assert"
)
@ -38,17 +37,17 @@ func TestAllBuildTargets(t *testing.T) {
},
},
}
assert.Equal([]buildtarget.Target{
buildtarget.New("linux", "386", ""),
buildtarget.New("linux", "amd64", ""),
buildtarget.New("linux", "arm", "6"),
buildtarget.New("linux", "arm64", ""),
buildtarget.New("darwin", "amd64", ""),
buildtarget.New("freebsd", "386", ""),
buildtarget.New("freebsd", "amd64", ""),
buildtarget.New("freebsd", "arm", "6"),
buildtarget.New("freebsd", "arm", "7"),
}, buildTargets(build))
assert.Equal([]Target{
New("linux", "386", ""),
New("linux", "amd64", ""),
New("linux", "arm", "6"),
New("linux", "arm64", ""),
New("darwin", "amd64", ""),
New("freebsd", "386", ""),
New("freebsd", "amd64", ""),
New("freebsd", "arm", "6"),
New("freebsd", "arm", "7"),
}, All(build))
}
func TestGoosGoarchCombos(t *testing.T) {
@ -94,7 +93,7 @@ func TestGoosGoarchCombos(t *testing.T) {
}
for _, p := range platforms {
t.Run(fmt.Sprintf("%v %v valid=%v", p.os, p.arch, p.valid), func(t *testing.T) {
assert.Equal(t, p.valid, valid(buildtarget.New(p.os, p.arch, "")))
assert.Equal(t, p.valid, valid(New(p.os, p.arch, "")))
})
}
}

View File

@ -43,7 +43,7 @@ func runPipeOnBuild(ctx *context.Context, build config.Build) error {
}
sem := make(chan bool, 4)
var g errgroup.Group
for _, target := range buildTargets(build) {
for _, target := range buildtarget.All(build) {
sem <- true
target := target
build := build

View File

@ -1,59 +0,0 @@
package build
import (
"github.com/apex/log"
"github.com/goreleaser/goreleaser/config"
"github.com/goreleaser/goreleaser/internal/buildtarget"
)
func buildTargets(build config.Build) (targets []buildtarget.Target) {
for _, target := range allBuildTargets(build) {
if !valid(target) {
log.WithField("target", target.String()).
Warn("skipped invalid build")
continue
}
if ignored(build, target) {
log.WithField("target", target.String()).
Warn("skipped ignored build")
continue
}
targets = append(targets, target)
}
return
}
func allBuildTargets(build config.Build) (targets []buildtarget.Target) {
for _, goos := range build.Goos {
for _, goarch := range build.Goarch {
if goarch == "arm" {
for _, goarm := range build.Goarm {
targets = append(targets, buildtarget.New(goos, goarch, goarm))
}
continue
}
targets = append(targets, buildtarget.New(goos, goarch, ""))
}
}
return
}
func ignored(build config.Build, target buildtarget.Target) bool {
for _, ig := range build.Ignore {
var ignored = buildtarget.New(ig.Goos, ig.Goarch, ig.Goarm)
if ignored == target {
return true
}
}
return false
}
func valid(target buildtarget.Target) bool {
var s = target.OS + target.Arch
for _, a := range valids {
if a == s {
return true
}
}
return false
}

View File

@ -1,35 +0,0 @@
package build
// list from https://golang.org/doc/install/source#environment
var valids = []string{
"androidarm",
"darwin386",
"darwinamd64",
// "darwinarm", - requires admin rights and other ios stuff
// "darwinarm64", - requires admin rights and other ios stuff
"dragonflyamd64",
"freebsd386",
"freebsdamd64",
"freebsdarm",
"linux386",
"linuxamd64",
"linuxarm",
"linuxarm64",
"linuxppc64",
"linuxppc64le",
"linuxmips",
"linuxmipsle",
"linuxmips64",
"linuxmips64le",
"netbsd386",
"netbsdamd64",
"netbsdarm",
"openbsd386",
"openbsdamd64",
"openbsdarm",
"plan9386",
"plan9amd64",
"solarisamd64",
"windows386",
"windowsamd64",
}