From 485f71b51a0ca71dab3a7f4e3a31e3ad8cdf1ade Mon Sep 17 00:00:00 2001 From: Carlos Alexandro Becker Date: Sun, 9 Jul 2017 13:14:35 -0300 Subject: [PATCH] moving targets to buildtarget package as well --- internal/buildtarget/targets.go | 93 +++++++++++++++++++ .../buildtarget/targets_test.go | 27 +++--- pipeline/build/build.go | 2 +- pipeline/build/target.go | 59 ------------ pipeline/build/valid_os.go | 35 ------- 5 files changed, 107 insertions(+), 109 deletions(-) create mode 100644 internal/buildtarget/targets.go rename pipeline/build/target_test.go => internal/buildtarget/targets_test.go (75%) delete mode 100644 pipeline/build/target.go delete mode 100644 pipeline/build/valid_os.go diff --git a/internal/buildtarget/targets.go b/internal/buildtarget/targets.go new file mode 100644 index 000000000..c969b0ee3 --- /dev/null +++ b/internal/buildtarget/targets.go @@ -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", +} diff --git a/pipeline/build/target_test.go b/internal/buildtarget/targets_test.go similarity index 75% rename from pipeline/build/target_test.go rename to internal/buildtarget/targets_test.go index 640d92985..1cad7c469 100644 --- a/pipeline/build/target_test.go +++ b/internal/buildtarget/targets_test.go @@ -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, ""))) }) } } diff --git a/pipeline/build/build.go b/pipeline/build/build.go index f09e3268f..ebbed5497 100644 --- a/pipeline/build/build.go +++ b/pipeline/build/build.go @@ -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 diff --git a/pipeline/build/target.go b/pipeline/build/target.go deleted file mode 100644 index 2de830683..000000000 --- a/pipeline/build/target.go +++ /dev/null @@ -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 -} diff --git a/pipeline/build/valid_os.go b/pipeline/build/valid_os.go deleted file mode 100644 index 15668e334..000000000 --- a/pipeline/build/valid_os.go +++ /dev/null @@ -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", -}