parallel builds

This commit is contained in:
cupcakearmy 2021-04-26 13:29:26 +02:00
parent f3c038c716
commit bbc32568ad
No known key found for this signature in database
GPG Key ID: D28129AE5654D9D9

View File

@ -9,6 +9,7 @@ import (
"os/exec" "os/exec"
"path" "path"
"path/filepath" "path/filepath"
"sync"
"github.com/cupcakearmy/autorestic/internal" "github.com/cupcakearmy/autorestic/internal"
) )
@ -27,7 +28,7 @@ type buildOptions struct {
Target, Arch, Version string Target, Arch, Version string
} }
func build(options buildOptions) error { func build(options buildOptions, wg *sync.WaitGroup) {
fmt.Printf("Building %s %s\n", options.Target, options.Arch) fmt.Printf("Building %s %s\n", options.Target, options.Arch)
out := fmt.Sprintf("autorestic_%s_%s_%s", options.Version, options.Target, options.Arch) out := fmt.Sprintf("autorestic_%s_%s_%s", options.Version, options.Target, options.Arch)
out = path.Join(DIR, out) out = path.Join(DIR, out)
@ -46,7 +47,7 @@ func build(options buildOptions) error {
) )
err := c.Run() err := c.Run()
if err != nil { if err != nil {
return err panic(err)
} }
} }
@ -58,26 +59,25 @@ func build(options buildOptions) error {
c.Stderr = os.Stderr c.Stderr = os.Stderr
err := c.Run() err := c.Run()
if err != nil { if err != nil {
return err panic(err)
} }
} }
wg.Done()
return nil
} }
func main() { func main() {
os.RemoveAll(DIR) os.RemoveAll(DIR)
v := internal.VERSION v := internal.VERSION
var wg sync.WaitGroup
for target, archs := range targets { for target, archs := range targets {
for _, arch := range archs { for _, arch := range archs {
err := build(buildOptions{ wg.Add(1)
build(buildOptions{
Target: target, Target: target,
Arch: arch, Arch: arch,
Version: v, Version: v,
}) }, &wg)
if err != nil {
panic(err)
}
} }
} }
wg.Wait()
} }