1
mirror of https://github.com/rclone/rclone synced 2024-12-22 13:03:02 +01:00

Add -include, -exclude -cgo to cross-compile.go

This commit is contained in:
Nick Craig-Wood 2017-05-13 09:55:29 +01:00
parent ecedcd0e7f
commit 64d7489fd2

View File

@ -10,6 +10,7 @@ import (
"os" "os"
"os/exec" "os/exec"
"path/filepath" "path/filepath"
"regexp"
"runtime" "runtime"
"strings" "strings"
"sync" "sync"
@ -22,6 +23,9 @@ var (
parallel = flag.Int("parallel", runtime.NumCPU(), "Number of commands to run in parallel.") parallel = flag.Int("parallel", runtime.NumCPU(), "Number of commands to run in parallel.")
copyAs = flag.String("release", "", "Make copies of the releases with this name") copyAs = flag.String("release", "", "Make copies of the releases with this name")
gitLog = flag.String("git-log", "", "git log to include as well") gitLog = flag.String("git-log", "", "git log to include as well")
include = flag.String("include", "^.*$", "os/arch regexp to include")
exclude = flag.String("exclude", "^$", "os/arch regexp to exclude")
cgo = flag.Bool("cgo", false, "Use cgo for the build")
) )
// GOOS/GOARCH pairs we build for // GOOS/GOARCH pairs we build for
@ -100,7 +104,11 @@ func compileArch(version, goos, goarch, dir string) {
env := []string{ env := []string{
"GOOS=" + goos, "GOOS=" + goos,
"GOARCH=" + goarch, "GOARCH=" + goarch,
"CGO_ENABLED=0", }
if !*cgo {
env = append(env, "CGO_ENABLED=0")
} else {
env = append(env, "CGO_ENABLED=1")
} }
if flags, ok := archFlags[goarch]; ok { if flags, ok := archFlags[goarch]; ok {
env = append(env, flags...) env = append(env, flags...)
@ -136,7 +144,19 @@ func compile(version string) {
} }
}() }()
} }
includeRe, err := regexp.Compile(*include)
if err != nil {
log.Fatalf("Bad -include regexp: %v", err)
}
excludeRe, err := regexp.Compile(*exclude)
if err != nil {
log.Fatalf("Bad -exclude regexp: %v", err)
}
compiled := 0
for _, osarch := range osarches { for _, osarch := range osarches {
if excludeRe.MatchString(osarch) || !includeRe.MatchString(osarch) {
continue
}
parts := strings.Split(osarch, "/") parts := strings.Split(osarch, "/")
if len(parts) != 2 { if len(parts) != 2 {
log.Fatalf("Bad osarch %q", osarch) log.Fatalf("Bad osarch %q", osarch)
@ -150,10 +170,11 @@ func compile(version string) {
run <- func() { run <- func() {
compileArch(version, goos, goarch, dir) compileArch(version, goos, goarch, dir)
} }
compiled++
} }
close(run) close(run)
wg.Wait() wg.Wait()
log.Printf("Compiled %d arches in %v", len(osarches), time.Since(start)) log.Printf("Compiled %d arches in %v", compiled, time.Since(start))
} }
func main() { func main() {