Makefile 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. GO ?= go
  2. GOFMT ?= gofmt "-s"
  3. PACKAGES ?= $(shell $(GO) list ./... | grep -v /vendor/)
  4. VETPACKAGES ?= $(shell $(GO) list ./... | grep -v /vendor/ | grep -v /examples/)
  5. GOFILES := $(shell find . -name "*.go" -type f -not -path "./vendor/*")
  6. TESTFOLDER := $(shell $(GO) list ./... | grep -E 'gin$$|binding$$|render$$' | grep -v examples)
  7. all: install
  8. install: deps
  9. govendor sync
  10. .PHONY: test
  11. test:
  12. echo "mode: count" > coverage.out
  13. for d in $(TESTFOLDER); do \
  14. $(GO) test -v -covermode=count -coverprofile=profile.out $$d > tmp.out; \
  15. cat tmp.out; \
  16. if grep -q "^--- FAIL" tmp.out; then \
  17. rm tmp.out; \
  18. exit 1; \
  19. elif grep -q "build failed" tmp.out; then \
  20. rm tmp.out; \
  21. exit 1; \
  22. elif grep -q "setup failed" tmp.out; then \
  23. rm tmp.out; \
  24. exit 1; \
  25. fi; \
  26. if [ -f profile.out ]; then \
  27. cat profile.out | grep -v "mode:" >> coverage.out; \
  28. rm profile.out; \
  29. fi; \
  30. done
  31. .PHONY: fmt
  32. fmt:
  33. $(GOFMT) -w $(GOFILES)
  34. .PHONY: fmt-check
  35. fmt-check:
  36. @diff=$$($(GOFMT) -d $(GOFILES)); \
  37. if [ -n "$$diff" ]; then \
  38. echo "Please run 'make fmt' and commit the result:"; \
  39. echo "$${diff}"; \
  40. exit 1; \
  41. fi;
  42. vet:
  43. $(GO) vet $(VETPACKAGES)
  44. deps:
  45. @hash govendor > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
  46. $(GO) get -u github.com/kardianos/govendor; \
  47. fi
  48. .PHONY: lint
  49. lint:
  50. @hash golint > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
  51. $(GO) get -u golang.org/x/lint/golint; \
  52. fi
  53. for PKG in $(PACKAGES); do golint -set_exit_status $$PKG || exit 1; done;
  54. .PHONY: misspell-check
  55. misspell-check:
  56. @hash misspell > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
  57. $(GO) get -u github.com/client9/misspell/cmd/misspell; \
  58. fi
  59. misspell -error $(GOFILES)
  60. .PHONY: misspell
  61. misspell:
  62. @hash misspell > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
  63. $(GO) get -u github.com/client9/misspell/cmd/misspell; \
  64. fi
  65. misspell -w $(GOFILES)
  66. .PHONY: tools
  67. tools:
  68. go install golang.org/x/lint/golint; \
  69. go install github.com/client9/misspell/cmd/misspell;