1
0
mirror of https://github.com/goreleaser/goreleaser.git synced 2025-01-24 04:16:27 +02:00

67 lines
1.2 KiB
Go
Raw Normal View History

2016-12-21 11:37:31 -02:00
package build
import (
"bytes"
2016-12-29 14:12:54 -02:00
"errors"
2016-12-30 09:27:35 -02:00
"log"
2016-12-21 14:42:23 -02:00
"os"
2016-12-21 11:37:31 -02:00
"os/exec"
"github.com/goreleaser/releaser/config"
2016-12-29 14:12:54 -02:00
"golang.org/x/sync/errgroup"
2016-12-21 11:37:31 -02:00
)
2016-12-30 12:41:59 -02:00
// Pipe for build
2016-12-30 09:27:35 -02:00
type Pipe struct{}
2016-12-30 12:41:59 -02:00
// Name of the pipe
2016-12-30 09:27:35 -02:00
func (Pipe) Name() string {
return "Build"
}
2016-12-30 12:41:59 -02:00
// Run the pipe
func (Pipe) Run(config config.ProjectConfig) error {
2016-12-29 14:12:54 -02:00
var g errgroup.Group
2016-12-30 10:01:40 -02:00
for _, system := range config.Build.Oses {
2016-12-21 11:37:31 -02:00
for _, arch := range config.Build.Arches {
2016-12-30 10:01:40 -02:00
system := system
2016-12-29 14:12:54 -02:00
arch := arch
g.Go(func() error {
2016-12-30 10:01:40 -02:00
return build(system, arch, config)
2016-12-29 14:12:54 -02:00
})
2016-12-21 11:37:31 -02:00
}
}
2016-12-29 14:12:54 -02:00
return g.Wait()
}
2016-12-30 10:01:40 -02:00
func build(system, arch string, config config.ProjectConfig) error {
2017-01-11 14:47:56 -02:00
name, err := config.ArchiveName(system, arch)
2017-01-04 10:13:49 -02:00
if err != nil {
return err
}
2017-01-11 20:27:13 -02:00
ldflags := config.Build.Ldflags + " -X main.version=" + config.Git.CurrentTag
2017-01-11 20:25:52 -02:00
output := "dist/" + name + "/" + config.BinaryName
log.Println("Building", output, "...")
2016-12-29 14:12:54 -02:00
cmd := exec.Command(
"go",
"build",
2017-01-11 20:25:52 -02:00
"-ldflags="+ldflags,
"-o", output,
2016-12-29 14:12:54 -02:00
config.Build.Main,
)
cmd.Env = append(
cmd.Env,
2016-12-30 10:01:40 -02:00
"GOOS="+system,
2016-12-29 14:12:54 -02:00
"GOARCH="+arch,
"GOROOT="+os.Getenv("GOROOT"),
"GOPATH="+os.Getenv("GOPATH"),
)
var stdout bytes.Buffer
cmd.Stdout = &stdout
cmd.Stderr = &stdout
2017-01-04 10:13:49 -02:00
if err := cmd.Run(); err != nil {
2016-12-29 14:12:54 -02:00
return errors.New(stdout.String())
}
2016-12-21 11:37:31 -02:00
return nil
}