aboutsummaryrefslogtreecommitdiff
path: root/platforms.go
diff options
context:
space:
mode:
authorLibravatar Terin Stock <terinjokes@gmail.com>2018-01-13 13:23:39 -0800
committerLibravatar Terin Stock <terinjokes@gmail.com>2018-01-17 13:42:24 -0800
commit8e0f32eb5421d71846700ffe4f11d2958a33f1b1 (patch)
tree33603cfe7125d0b142565b590afdfd9ea4420919 /platforms.go
parentfeat(main): implement []string flag valuer (diff)
downloadbakelite-8e0f32eb5421d71846700ffe4f11d2958a33f1b1.tar.xz
feat(main): support modifying built platformsv0.1.0
Bakelite now accepts a platform modification string vita the -platform flag. This string format for adding and removing the built platforms, including removing the default platforms entirely. It is processed left to right. bakelite -platform '-windows +linux/s390x' [packages] Would now build [packages] for all of the default platforms, except for Windows, and also build for the linux/s390x platform. bakelite -platform '- +linux +darwin' [packages] Would now build [packages] for the default platforms of only the Linux and Darwin operating systems. The platform modification string is parsed and turned into calls to a structure following the builder pattern. As the user can now modify the built platforms, Bakelite now exits with a non-zero exit code if any of the platforms fail to build. Change-Id: Iade51e17bbfda4e916394343a5f8cb3208f2b160
Diffstat (limited to 'platforms.go')
-rw-r--r--platforms.go179
1 files changed, 179 insertions, 0 deletions
diff --git a/platforms.go b/platforms.go
new file mode 100644
index 0000000..9c0a572
--- /dev/null
+++ b/platforms.go
@@ -0,0 +1,179 @@
+package main
+
+// Arch represents a Go Arch.
+type Arch string
+
+const (
+ ARCH_AMD64 Arch = "amd64"
+ ARCH_386 Arch = "386"
+ ARCH_ARM Arch = "arm"
+ ARCH_ARM64 Arch = "arm64"
+ ARCH_PPC64 Arch = "ppc64"
+ ARCH_PPC64LE Arch = "ppc64le"
+ ARCH_MIPS Arch = "mips"
+ ARCH_MIPSLE Arch = "mipsle"
+ ARCH_MIPS64 Arch = "mips64"
+ ARCH_MIPS64LE Arch = "mips64le"
+)
+
+// OS represents a Go OS.
+type OS string
+
+const (
+ OS_ANDROID OS = "android"
+ OS_DARWIN OS = "darwin"
+ OS_DRAGONFLY OS = "dragonfly"
+ OS_FREEBSD OS = "freebsd"
+ OS_LINUX OS = "linux"
+ OS_NETBSD OS = "netbsd"
+ OS_OPENBSD OS = "openbsd"
+ OS_PLAN9 OS = "plan9"
+ OS_SOLARIS OS = "solaris"
+ OS_WINDOWS OS = "windows"
+)
+
+// Platform represents an OS/Arch combination.
+type Platform struct {
+ OS OS
+ Arch Arch
+}
+
+// PlatformBuilder provides a fluent way to build up (or tear down) a list of
+// Go platforms. The built list of platforms can be retrieved from the Build method
+// of a returned builder.
+type PlatformBuilder struct {
+ platforms map[Platform]bool
+}
+
+// NewPlatformBuilder returns a PlatformBuilder with no platforms configured.
+func NewPlatformBuilder() (*PlatformBuilder, error) {
+ return &PlatformBuilder{
+ platforms: make(map[Platform]bool),
+ }, nil
+}
+
+// WithoutPlatform returns a new PlatformBuilder with platform removed.
+func (p *PlatformBuilder) WithoutPlatform(platform Platform) *PlatformBuilder {
+ pm := make(map[Platform]bool)
+
+ for k, v := range p.platforms {
+ if k != platform {
+ pm[k] = v
+ }
+ }
+
+ return &PlatformBuilder{
+ platforms: pm,
+ }
+}
+
+// WithoutOS returns a new PlatformBuilder with all platforms of the OS's
+// platforms removed.
+func (p *PlatformBuilder) WithoutOS(os OS) *PlatformBuilder {
+ pm := make(map[Platform]bool)
+
+ for k, v := range p.platforms {
+ if k.OS != os {
+ pm[k] = v
+ }
+ }
+
+ return &PlatformBuilder{
+ platforms: pm,
+ }
+}
+
+// WithPlatform returns a new PlatformBuilder with the platform added.
+func (p *PlatformBuilder) WithPlatform(platform Platform) *PlatformBuilder {
+ pm := make(map[Platform]bool)
+
+ for k, v := range p.platforms {
+ pm[k] = v
+ }
+
+ pm[platform] = true
+
+ return &PlatformBuilder{
+ platforms: pm,
+ }
+}
+
+// WithOS returns a new PlatformBuilder with the OS's default platforms added.
+func (p *PlatformBuilder) WithOS(os OS) *PlatformBuilder {
+ pm := make(map[Platform]bool)
+
+ for k, v := range p.platforms {
+ pm[k] = v
+ }
+
+ var pl []Platform
+ switch os {
+ case OS_DARWIN:
+ pl = defaultDarwin()
+ case OS_DRAGONFLY:
+ pl = defaultDragonfly()
+ case OS_FREEBSD:
+ pl = defaultFreeBSD()
+ case OS_LINUX:
+ pl = defaultLinux()
+ case OS_NETBSD:
+ pl = defaultNetBSD()
+ case OS_OPENBSD:
+ pl = defaultOpenBSD()
+ case OS_PLAN9:
+ pl = defaultPlan9()
+ case OS_SOLARIS:
+ pl = defaultSolaris()
+ case OS_WINDOWS:
+ pl = defaultWindows()
+ default:
+ pl = []Platform{}
+ }
+
+ for _, k := range pl {
+ pm[k] = true
+ }
+
+ return &PlatformBuilder{
+ platforms: pm,
+ }
+}
+
+// WithDefaults returns a new PlatformBuilder with just Bakelite's default
+// platforms.
+func (p *PlatformBuilder) WithDefaults() *PlatformBuilder {
+ pm := make(map[Platform]bool)
+
+ pls := []Platform{
+ //{OS_ANDROID, ARCH_ARM},
+ }
+
+ pls = append(pls, defaultDarwin()...)
+ pls = append(pls, defaultDragonfly()...)
+ pls = append(pls, defaultFreeBSD()...)
+ pls = append(pls, defaultLinux()...)
+ pls = append(pls, defaultNetBSD()...)
+ pls = append(pls, defaultOpenBSD()...)
+ pls = append(pls, defaultPlan9()...)
+ pls = append(pls, defaultSolaris()...)
+ pls = append(pls, defaultWindows()...)
+
+ for _, k := range pls {
+ pm[k] = true
+ }
+
+ return &PlatformBuilder{
+ platforms: pm,
+ }
+}
+
+// Build returns a new list of Platforms.
+func (p *PlatformBuilder) Build() []Platform {
+ pl := []Platform{}
+
+ for k, _ := range p.platforms {
+ pl = append(pl, k)
+ }
+
+ return pl
+}