build: Extract runCommand from main
GitHub-Pull-Request: https://github.com/syncthing/syncthing/pull/3160
This commit is contained in:
parent
5aacfd1639
commit
343dc486e0
60
build.go
60
build.go
|
@ -167,44 +167,42 @@ func main() {
|
||||||
|
|
||||||
parseFlags()
|
parseFlags()
|
||||||
|
|
||||||
|
checkArchitecture()
|
||||||
|
goVersion, _ = checkRequiredGoVersion()
|
||||||
|
|
||||||
|
// Invoking build.go with no parameters at all builds everything (incrementally),
|
||||||
|
// which is what you want for maximum error checking during development.
|
||||||
|
if flag.NArg() == 0 {
|
||||||
|
runCommand("install", targets["all"])
|
||||||
|
runCommand("vet", target{})
|
||||||
|
runCommand("lint", target{})
|
||||||
|
} else {
|
||||||
|
// 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" etc.
|
||||||
|
targetName := "syncthing"
|
||||||
|
if flag.NArg() > 1 {
|
||||||
|
targetName = flag.Arg(1)
|
||||||
|
}
|
||||||
|
target, ok := targets[targetName]
|
||||||
|
if !ok {
|
||||||
|
log.Fatalln("Unknown target", target)
|
||||||
|
}
|
||||||
|
|
||||||
|
runCommand(flag.Arg(0), target)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func checkArchitecture() {
|
||||||
switch goarch {
|
switch goarch {
|
||||||
case "386", "amd64", "arm", "arm64", "ppc64", "ppc64le":
|
case "386", "amd64", "arm", "arm64", "ppc64", "ppc64le":
|
||||||
break
|
break
|
||||||
default:
|
default:
|
||||||
log.Printf("Unknown goarch %q; proceed with caution!", goarch)
|
log.Printf("Unknown goarch %q; proceed with caution!", goarch)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
goVersion, _ = checkRequiredGoVersion()
|
func runCommand(cmd string, target target) {
|
||||||
|
|
||||||
// Invoking build.go with no parameters at all is equivalent to "go run
|
|
||||||
// build.go install all" as that builds everything (incrementally),
|
|
||||||
// which is what you want for maximum error checking during development.
|
|
||||||
if flag.NArg() == 0 {
|
|
||||||
var tags []string
|
|
||||||
if noupgrade {
|
|
||||||
tags = []string{"noupgrade"}
|
|
||||||
}
|
|
||||||
install(targets["all"], tags)
|
|
||||||
|
|
||||||
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" etc.
|
|
||||||
targetName := "syncthing"
|
|
||||||
if flag.NArg() > 1 {
|
|
||||||
targetName = flag.Arg(1)
|
|
||||||
}
|
|
||||||
target, ok := targets[targetName]
|
|
||||||
if !ok {
|
|
||||||
log.Fatalln("Unknown target", target)
|
|
||||||
}
|
|
||||||
|
|
||||||
cmd := flag.Arg(0)
|
|
||||||
switch cmd {
|
switch cmd {
|
||||||
case "setup":
|
case "setup":
|
||||||
setup()
|
setup()
|
||||||
|
|
Loading…
Reference in New Issue