mirror of https://github.com/sirupsen/logrus.git
migrate cross build target from bash script to mage
This commit is contained in:
parent
8ae478eb8a
commit
4b818a50d4
|
@ -9,7 +9,7 @@ os: linux
|
||||||
install:
|
install:
|
||||||
- ./travis/install.sh
|
- ./travis/install.sh
|
||||||
script:
|
script:
|
||||||
- ./travis/cross_build.sh
|
- go run mage.go -v crossBuild
|
||||||
- ./travis/lint.sh
|
- ./travis/lint.sh
|
||||||
- export GOMAXPROCS=4
|
- export GOMAXPROCS=4
|
||||||
- export GORACE=halt_on_error=1
|
- export GORACE=halt_on_error=1
|
||||||
|
|
1
go.mod
1
go.mod
|
@ -2,6 +2,7 @@ module github.com/sirupsen/logrus
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/davecgh/go-spew v1.1.1 // indirect
|
github.com/davecgh/go-spew v1.1.1 // indirect
|
||||||
|
github.com/magefile/mage v1.10.0
|
||||||
github.com/pmezard/go-difflib v1.0.0 // indirect
|
github.com/pmezard/go-difflib v1.0.0 // indirect
|
||||||
github.com/stretchr/testify v1.2.2
|
github.com/stretchr/testify v1.2.2
|
||||||
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037
|
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037
|
||||||
|
|
2
go.sum
2
go.sum
|
@ -1,5 +1,7 @@
|
||||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
|
github.com/magefile/mage v1.10.0 h1:3HiXzCUY12kh9bIuyXShaVe529fJfyqoVM42o/uom2g=
|
||||||
|
github.com/magefile/mage v1.10.0/go.mod h1:z5UZb/iS3GoOSn0JgWuiw7dxlurVYTu+/jHXqQg881A=
|
||||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||||
github.com/stretchr/testify v1.2.2 h1:bSDNvY7ZPG5RlJ8otE/7V6gMiyenm9RtJ7IUVIAoJ1w=
|
github.com/stretchr/testify v1.2.2 h1:bSDNvY7ZPG5RlJ8otE/7V6gMiyenm9RtJ7IUVIAoJ1w=
|
||||||
|
|
|
@ -0,0 +1,10 @@
|
||||||
|
// +build ignore
|
||||||
|
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/magefile/mage/mage"
|
||||||
|
"os"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() { os.Exit(mage.Main()) }
|
|
@ -0,0 +1,60 @@
|
||||||
|
// +build mage
|
||||||
|
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/magefile/mage/mg"
|
||||||
|
"github.com/magefile/mage/sh"
|
||||||
|
)
|
||||||
|
|
||||||
|
// GenBuildMatrix regenerates the build matrix from the current version of the go compiler
|
||||||
|
func getBuildMatrix() (map[string][]string, error) {
|
||||||
|
jsonData, err := sh.Output("go", "tool", "dist", "list", "-json")
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
var data []struct {
|
||||||
|
Goos string
|
||||||
|
Goarch string
|
||||||
|
}
|
||||||
|
if err := json.Unmarshal([]byte(jsonData), &data); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
matrix := map[string][]string{}
|
||||||
|
for _, v := range data {
|
||||||
|
if val, ok := matrix[v.Goos]; ok {
|
||||||
|
matrix[v.Goos] = append(val, v.Goarch)
|
||||||
|
} else {
|
||||||
|
matrix[v.Goos] = []string{v.Goarch}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return matrix, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func CrossBuild() error {
|
||||||
|
matrix, err := getBuildMatrix()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
for os, arches := range matrix {
|
||||||
|
for _, arch := range arches {
|
||||||
|
env := map[string]string{
|
||||||
|
"GOOS": os,
|
||||||
|
"GOARCH": arch,
|
||||||
|
}
|
||||||
|
if mg.Verbose() {
|
||||||
|
fmt.Printf("Building for GOOS=%s GOARCH=%s\n", os, arch)
|
||||||
|
}
|
||||||
|
if err := sh.RunWith(env, "go", "build", "./..."); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
Loading…
Reference in New Issue