Makefile 2.0 KB

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