mirror of
https://github.com/octoleo/syncthing.git
synced 2025-01-22 22:58:25 +00:00
build: Clean up "go vet" and "go lint" steps
GitHub-Pull-Request: https://github.com/syncthing/syncthing/pull/2972
This commit is contained in:
parent
c49453c519
commit
a4cd4cc253
50
build.go
50
build.go
@ -26,6 +26,7 @@ import (
|
|||||||
"runtime"
|
"runtime"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
"syscall"
|
||||||
"text/template"
|
"text/template"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
@ -161,9 +162,8 @@ func main() {
|
|||||||
}
|
}
|
||||||
install(targets["all"], tags)
|
install(targets["all"], tags)
|
||||||
|
|
||||||
vet("./cmd/syncthing")
|
vet("cmd", "lib")
|
||||||
vet("./lib/...")
|
lint("./cmd/...")
|
||||||
lint("./cmd/syncthing")
|
|
||||||
lint("./lib/...")
|
lint("./lib/...")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -230,11 +230,10 @@ func main() {
|
|||||||
clean()
|
clean()
|
||||||
|
|
||||||
case "vet":
|
case "vet":
|
||||||
vet("./cmd/syncthing")
|
vet("cmd", "lib")
|
||||||
vet("./lib/...")
|
|
||||||
|
|
||||||
case "lint":
|
case "lint":
|
||||||
lint("./cmd/syncthing")
|
lint("./cmd/...")
|
||||||
lint("./lib/...")
|
lint("./lib/...")
|
||||||
|
|
||||||
default:
|
default:
|
||||||
@ -852,24 +851,25 @@ func zipFile(out string, files []archiveFile) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func vet(pkg string) {
|
func vet(dirs ...string) {
|
||||||
bs, err := runError("go", "vet", pkg)
|
params := []string{"tool", "vet", "-all"}
|
||||||
if err != nil && err.Error() == "exit status 3" || bytes.Contains(bs, []byte("no such tool \"vet\"")) {
|
params = append(params, dirs...)
|
||||||
// Go said there is no go vet
|
bs, err := runError("go", params...)
|
||||||
log.Println(`- No go vet, no vetting. Try "go get -u golang.org/x/tools/cmd/vet".`)
|
|
||||||
return
|
if len(bs) > 0 {
|
||||||
|
log.Printf("%s", bs)
|
||||||
}
|
}
|
||||||
|
|
||||||
falseAlarmComposites := regexp.MustCompile("composite literal uses unkeyed fields")
|
if err != nil {
|
||||||
exitStatus := regexp.MustCompile("exit status 1")
|
if exitStatus(err) == 3 {
|
||||||
for _, line := range bytes.Split(bs, []byte("\n")) {
|
// Exit code 3, the "vet" tool is not installed
|
||||||
if falseAlarmComposites.Match(line) || exitStatus.Match(line) {
|
return
|
||||||
continue
|
|
||||||
}
|
|
||||||
if len(line) > 0 {
|
|
||||||
log.Printf("%s", line)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// A genuine error exit from the vet tool.
|
||||||
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func lint(pkg string) {
|
func lint(pkg string) {
|
||||||
@ -908,3 +908,13 @@ func macosCodesign(file string) {
|
|||||||
log.Println("Codesign: successfully signed", file)
|
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
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user