summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLars K.W. Gohlke <lkwg82@gmx.de>2016-06-07 07:12:10 +0000
committerJakob Borg <jakob@nym.se>2016-06-07 07:12:10 +0000
commit343dc486e0c030434011ac98376a572c4e50221a (patch)
treeb85095fcd49bfab55a467a0450f129bdee48f6c1
parent5aacfd16395efc6a375e21113ded6cb3b0d5783e (diff)
build: Extract runCommand from main
GitHub-Pull-Request: https://github.com/syncthing/syncthing/pull/3160
-rw-r--r--build.go54
1 files changed, 26 insertions, 28 deletions
diff --git a/build.go b/build.go
index 76e900fee..920e713fd 100644
--- a/build.go
+++ b/build.go
@@ -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()