1
0
mirror of https://github.com/goreleaser/goreleaser.git synced 2025-01-08 03:31:59 +02:00
goreleaser/internal/builders/golang/targets.go

126 lines
2.4 KiB
Go
Raw Normal View History

package golang
import (
2018-01-22 02:44:06 +02:00
"fmt"
"github.com/apex/log"
"github.com/goreleaser/goreleaser/config"
)
2018-01-22 02:44:06 +02:00
type target struct {
os, arch, arm string
}
func (t target) String() string {
if t.arm != "" {
return fmt.Sprintf("%s_%s_%s", t.os, t.arch, t.arm)
}
return fmt.Sprintf("%s_%s", t.os, t.arch)
}
func matrix(build config.Build) (result []string) {
2018-01-22 02:44:06 +02:00
var targets []target
for _, target := range allBuildTargets(build) {
if !valid(target) {
2018-01-22 02:44:06 +02:00
log.WithField("target", target).
2017-08-20 22:46:30 +02:00
Debug("skipped invalid build")
continue
}
if ignored(build, target) {
2018-01-22 02:44:06 +02:00
log.WithField("target", target).
2017-08-20 22:46:30 +02:00
Debug("skipped ignored build")
continue
}
targets = append(targets, target)
}
2018-01-22 02:44:06 +02:00
for _, target := range targets {
result = append(result, target.String())
}
return
}
2018-01-22 02:44:06 +02:00
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 {
2018-06-19 20:53:14 +02:00
targets = append(targets, target{
os: goos,
arch: goarch,
arm: goarm,
})
}
continue
}
2018-06-19 20:53:14 +02:00
targets = append(targets, target{
os: goos,
arch: goarch,
})
}
}
return
}
2018-01-28 15:46:16 +02:00
// TODO: this could be improved by using a map
// https://github.com/goreleaser/goreleaser/pull/522#discussion_r164245014
2018-01-22 02:44:06 +02:00
func ignored(build config.Build, target target) bool {
for _, ig := range build.Ignore {
2018-01-22 02:44:06 +02:00
if ig.Goos != "" && ig.Goos != target.os {
continue
}
2018-01-22 02:44:06 +02:00
if ig.Goarch != "" && ig.Goarch != target.arch {
continue
}
2018-01-22 02:44:06 +02:00
if ig.Goarm != "" && ig.Goarm != target.arm {
continue
}
return true
}
return false
}
2018-01-22 02:44:06 +02:00
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",
2017-07-26 09:04:03 +02:00
"linuxs390x",
"netbsd386",
"netbsdamd64",
"netbsdarm",
"openbsd386",
"openbsdamd64",
"openbsdarm",
"plan9386",
"plan9amd64",
"solarisamd64",
"windows386",
"windowsamd64",
}