2016-12-21 15:37:31 +02:00
|
|
|
package build
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"fmt"
|
2016-12-21 18:42:23 +02:00
|
|
|
"os"
|
2016-12-21 15:37:31 +02:00
|
|
|
"os/exec"
|
|
|
|
|
|
|
|
"github.com/goreleaser/releaser/config"
|
2016-12-29 02:53:56 +02:00
|
|
|
"github.com/goreleaser/releaser/uname"
|
2016-12-21 15:37:31 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
func Build(version string, config config.ProjectConfig) error {
|
2016-12-21 18:42:23 +02:00
|
|
|
for _, bos := range config.Build.Oses {
|
2016-12-21 15:37:31 +02:00
|
|
|
for _, arch := range config.Build.Arches {
|
2016-12-29 13:04:56 +02:00
|
|
|
fmt.Println("Building", bos+"/"+arch, "...")
|
2016-12-21 15:37:31 +02:00
|
|
|
cmd := exec.Command(
|
2016-12-21 18:42:23 +02:00
|
|
|
"go",
|
|
|
|
"build",
|
|
|
|
"-ldflags=-s -w -X main.version="+version,
|
|
|
|
"-o", target(bos, arch, config.BinaryName),
|
2016-12-29 16:37:11 +02:00
|
|
|
config.Build.Main,
|
2016-12-21 15:37:31 +02:00
|
|
|
)
|
|
|
|
cmd.Env = append(
|
|
|
|
cmd.Env,
|
2016-12-21 18:42:23 +02:00
|
|
|
"GOOS="+bos,
|
2016-12-21 15:37:31 +02:00
|
|
|
"GOARCH="+arch,
|
2016-12-21 18:42:23 +02:00
|
|
|
"GOROOT="+os.Getenv("GOROOT"),
|
|
|
|
"GOPATH="+os.Getenv("GOPATH"),
|
2016-12-21 15:37:31 +02:00
|
|
|
)
|
|
|
|
var stdout bytes.Buffer
|
|
|
|
cmd.Stdout = &stdout
|
|
|
|
cmd.Stderr = &stdout
|
|
|
|
err := cmd.Run()
|
|
|
|
if err != nil {
|
2016-12-29 02:53:56 +02:00
|
|
|
fmt.Println(stdout.String())
|
2016-12-21 15:37:31 +02:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func target(os, arch, binary string) string {
|
2016-12-29 02:53:56 +02:00
|
|
|
return "dist/" + binary + "_" + uname.FromGo(os) + "_" + uname.FromGo(arch) + "/" + binary
|
2016-12-21 15:37:31 +02:00
|
|
|
}
|