Makefile 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. .PHONY: default install build test quicktest fmt vet lint
  2. GO_VERSION := $(shell go version | cut -d' ' -f3 | cut -d. -f2)
  3. # Only use the `-race` flag on newer versions of Go
  4. IS_OLD_GO := $(shell test $(GO_VERSION) -le 2 && echo true)
  5. ifeq ($(IS_OLD_GO),true)
  6. RACE_FLAG :=
  7. else
  8. RACE_FLAG := -race -cpu 1,2,4
  9. endif
  10. default: fmt vet lint build quicktest
  11. install:
  12. go get -t -v ./...
  13. build:
  14. go build -v ./...
  15. test:
  16. go test -v $(RACE_FLAG) -cover ./...
  17. quicktest:
  18. go test ./...
  19. # Capture output and force failure when there is non-empty output
  20. fmt:
  21. @echo gofmt -l .
  22. @OUTPUT=`gofmt -l . 2>&1`; \
  23. if [ "$$OUTPUT" ]; then \
  24. echo "gofmt must be run on the following files:"; \
  25. echo "$$OUTPUT"; \
  26. exit 1; \
  27. fi
  28. # Only run on go1.5+
  29. vet:
  30. go tool vet -atomic -bool -copylocks -nilfunc -printf -shadow -rangeloops -unreachable -unsafeptr -unusedresult .
  31. # https://github.com/golang/lint
  32. # go get github.com/golang/lint/golint
  33. # Capture output and force failure when there is non-empty output
  34. # Only run on go1.5+
  35. lint:
  36. @echo golint ./...
  37. @OUTPUT=`golint ./... 2>&1`; \
  38. if [ "$$OUTPUT" ]; then \
  39. echo "golint errors:"; \
  40. echo "$$OUTPUT"; \
  41. exit 1; \
  42. fi