Makefile 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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 $(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. .PHONY: vet
  42. vet:
  43. $(GO) vet $(VETPACKAGES)
  44. .PHONY: lint
  45. lint:
  46. @hash golint > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
  47. $(GO) get -u golang.org/x/lint/golint; \
  48. fi
  49. for PKG in $(PACKAGES); do golint -set_exit_status $$PKG || exit 1; done;
  50. .PHONY: misspell-check
  51. misspell-check:
  52. @hash misspell > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
  53. $(GO) get -u github.com/client9/misspell/cmd/misspell; \
  54. fi
  55. misspell -error $(GOFILES)
  56. .PHONY: misspell
  57. misspell:
  58. @hash misspell > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
  59. $(GO) get -u github.com/client9/misspell/cmd/misspell; \
  60. fi
  61. misspell -w $(GOFILES)
  62. .PHONY: tools
  63. tools:
  64. @if [ $(GO_VERSION) -gt 15 ]; then \
  65. $(GO) install golang.org/x/lint/golint@latest; \
  66. $(GO) install github.com/client9/misspell/cmd/misspell@latest; \
  67. elif [ $(GO_VERSION) -lt 16 ]; then \
  68. $(GO) install golang.org/x/lint/golint; \
  69. $(GO) install github.com/client9/misspell/cmd/misspell; \
  70. fi