diff options
author | Lars K.W. Gohlke <lkwg82@gmx.de> | 2016-06-07 07:12:10 +0000 |
---|---|---|
committer | Jakob Borg <jakob@nym.se> | 2016-06-07 07:12:10 +0000 |
commit | 343dc486e0c030434011ac98376a572c4e50221a (patch) | |
tree | b85095fcd49bfab55a467a0450f129bdee48f6c1 | |
parent | 5aacfd16395efc6a375e21113ded6cb3b0d5783e (diff) |
build: Extract runCommand from main
GitHub-Pull-Request: https://github.com/syncthing/syncthing/pull/3160
-rw-r--r-- | build.go | 54 |
1 files changed, 26 insertions, 28 deletions
@@ -167,44 +167,42 @@ func main() { parseFlags() - switch goarch { - case "386", "amd64", "arm", "arm64", "ppc64", "ppc64le": - break - default: - log.Printf("Unknown goarch %q; proceed with caution!", goarch) - } - + checkArchitecture() goVersion, _ = checkRequiredGoVersion() - // Invoking build.go with no parameters at all is equivalent to "go run - // build.go install all" as that builds everything (incrementally), + // 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 { - var tags []string - if noupgrade { - tags = []string{"noupgrade"} + 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) } - install(targets["all"], tags) - vet("cmd", "lib") - lint("./cmd/...") - lint("./lib/...") - return + runCommand(flag.Arg(0), target) } +} - // 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) +func checkArchitecture() { + switch goarch { + case "386", "amd64", "arm", "arm64", "ppc64", "ppc64le": + break + default: + log.Printf("Unknown goarch %q; proceed with caution!", goarch) } +} - cmd := flag.Arg(0) +func runCommand(cmd string, target target) { switch cmd { case "setup": setup() |