From a4cd4cc2534d51e49d7c3edc81cc3dbe493767bc Mon Sep 17 00:00:00 2001 From: Jakob Borg Date: Fri, 15 Apr 2016 07:26:25 +0000 Subject: [PATCH] build: Clean up "go vet" and "go lint" steps GitHub-Pull-Request: https://github.com/syncthing/syncthing/pull/2972 --- build.go | 50 ++++++++++++++++++++++++++++++-------------------- 1 file changed, 30 insertions(+), 20 deletions(-) diff --git a/build.go b/build.go index 5ee3db37..997650ed 100644 --- a/build.go +++ b/build.go @@ -26,6 +26,7 @@ import ( "runtime" "strconv" "strings" + "syscall" "text/template" "time" ) @@ -161,9 +162,8 @@ func main() { } install(targets["all"], tags) - vet("./cmd/syncthing") - vet("./lib/...") - lint("./cmd/syncthing") + vet("cmd", "lib") + lint("./cmd/...") lint("./lib/...") return } @@ -230,11 +230,10 @@ func main() { clean() case "vet": - vet("./cmd/syncthing") - vet("./lib/...") + vet("cmd", "lib") case "lint": - lint("./cmd/syncthing") + lint("./cmd/...") lint("./lib/...") default: @@ -852,24 +851,25 @@ func zipFile(out string, files []archiveFile) { } } -func vet(pkg string) { - bs, err := runError("go", "vet", pkg) - if err != nil && err.Error() == "exit status 3" || bytes.Contains(bs, []byte("no such tool \"vet\"")) { - // Go said there is no go vet - log.Println(`- No go vet, no vetting. Try "go get -u golang.org/x/tools/cmd/vet".`) - return +func vet(dirs ...string) { + params := []string{"tool", "vet", "-all"} + params = append(params, dirs...) + bs, err := runError("go", params...) + + if len(bs) > 0 { + log.Printf("%s", bs) } - falseAlarmComposites := regexp.MustCompile("composite literal uses unkeyed fields") - exitStatus := regexp.MustCompile("exit status 1") - for _, line := range bytes.Split(bs, []byte("\n")) { - if falseAlarmComposites.Match(line) || exitStatus.Match(line) { - continue - } - if len(line) > 0 { - log.Printf("%s", line) + if err != nil { + if exitStatus(err) == 3 { + // Exit code 3, the "vet" tool is not installed + return } + + // A genuine error exit from the vet tool. + log.Fatal(err) } + } func lint(pkg string) { @@ -908,3 +908,13 @@ func macosCodesign(file string) { log.Println("Codesign: successfully signed", file) } } + +func exitStatus(err error) int { + if err, ok := err.(*exec.ExitError); ok { + if ws, ok := err.ProcessState.Sys().(syscall.WaitStatus); ok { + return ws.ExitStatus() + } + } + + return -1 +}