build: Extract runCommand from main

GitHub-Pull-Request: https://github.com/syncthing/syncthing/pull/3160
This commit is contained in:
Lars K.W. Gohlke 2016-06-07 07:12:10 +00:00 committed by Jakob Borg
parent 5aacfd1639
commit 343dc486e0

View File

@ -167,32 +167,17 @@ func main() {
parseFlags() parseFlags()
switch goarch { checkArchitecture()
case "386", "amd64", "arm", "arm64", "ppc64", "ppc64le":
break
default:
log.Printf("Unknown goarch %q; proceed with caution!", goarch)
}
goVersion, _ = checkRequiredGoVersion() goVersion, _ = checkRequiredGoVersion()
// Invoking build.go with no parameters at all is equivalent to "go run // Invoking build.go with no parameters at all builds everything (incrementally),
// build.go install all" as that builds everything (incrementally),
// which is what you want for maximum error checking during development. // which is what you want for maximum error checking during development.
if flag.NArg() == 0 { if flag.NArg() == 0 {
var tags []string runCommand("install", targets["all"])
if noupgrade { runCommand("vet", target{})
tags = []string{"noupgrade"} runCommand("lint", target{})
} } else {
install(targets["all"], tags) // with any command given but not a target, the target is
vet("cmd", "lib")
lint("./cmd/...")
lint("./lib/...")
return
}
// Otherwise, with any command given but not a target, the target is
// "syncthing". So "go run build.go install" is "go run build.go install // "syncthing". So "go run build.go install" is "go run build.go install
// syncthing" etc. // syncthing" etc.
targetName := "syncthing" targetName := "syncthing"
@ -204,7 +189,20 @@ func main() {
log.Fatalln("Unknown target", target) log.Fatalln("Unknown target", target)
} }
cmd := flag.Arg(0) runCommand(flag.Arg(0), target)
}
}
func checkArchitecture() {
switch goarch {
case "386", "amd64", "arm", "arm64", "ppc64", "ppc64le":
break
default:
log.Printf("Unknown goarch %q; proceed with caution!", goarch)
}
}
func runCommand(cmd string, target target) {
switch cmd { switch cmd {
case "setup": case "setup":
setup() setup()