Makefile 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. export GO15VENDOREXPERIMENT=1
  2. BENCH_FLAGS ?= -cpuprofile=cpu.pprof -memprofile=mem.pprof -benchmem
  3. PKGS ?= $(shell glide novendor)
  4. # Many Go tools take file globs or directories as arguments instead of packages.
  5. PKG_FILES ?= *.go zapcore benchmarks buffer zapgrpc zaptest zaptest/observer internal/bufferpool internal/exit internal/color internal/ztest
  6. # The linting tools evolve with each Go version, so run them only on the latest
  7. # stable release.
  8. GO_VERSION := $(shell go version | cut -d " " -f 3)
  9. GO_MINOR_VERSION := $(word 2,$(subst ., ,$(GO_VERSION)))
  10. LINTABLE_MINOR_VERSIONS := 10
  11. ifneq ($(filter $(LINTABLE_MINOR_VERSIONS),$(GO_MINOR_VERSION)),)
  12. SHOULD_LINT := true
  13. endif
  14. .PHONY: all
  15. all: lint test
  16. .PHONY: dependencies
  17. dependencies:
  18. @echo "Installing Glide and locked dependencies..."
  19. glide --version || go get -u -f github.com/Masterminds/glide
  20. glide install
  21. @echo "Installing test dependencies..."
  22. go install ./vendor/github.com/axw/gocov/gocov
  23. go install ./vendor/github.com/mattn/goveralls
  24. ifdef SHOULD_LINT
  25. @echo "Installing golint..."
  26. go install ./vendor/github.com/golang/lint/golint
  27. else
  28. @echo "Not installing golint, since we don't expect to lint on" $(GO_VERSION)
  29. endif
  30. # Disable printf-like invocation checking due to testify.assert.Error()
  31. VET_RULES := -printf=false
  32. .PHONY: lint
  33. lint:
  34. ifdef SHOULD_LINT
  35. @rm -rf lint.log
  36. @echo "Checking formatting..."
  37. @gofmt -d -s $(PKG_FILES) 2>&1 | tee lint.log
  38. @echo "Installing test dependencies for vet..."
  39. @go test -i $(PKGS)
  40. @echo "Checking vet..."
  41. @$(foreach dir,$(PKG_FILES),go tool vet $(VET_RULES) $(dir) 2>&1 | tee -a lint.log;)
  42. @echo "Checking lint..."
  43. @$(foreach dir,$(PKGS),golint $(dir) 2>&1 | tee -a lint.log;)
  44. @echo "Checking for unresolved FIXMEs..."
  45. @git grep -i fixme | grep -v -e vendor -e Makefile | tee -a lint.log
  46. @echo "Checking for license headers..."
  47. @./check_license.sh | tee -a lint.log
  48. @[ ! -s lint.log ]
  49. else
  50. @echo "Skipping linters on" $(GO_VERSION)
  51. endif
  52. .PHONY: test
  53. test:
  54. go test -race $(PKGS)
  55. .PHONY: cover
  56. cover:
  57. ./scripts/cover.sh $(PKGS)
  58. .PHONY: bench
  59. BENCH ?= .
  60. bench:
  61. @$(foreach pkg,$(PKGS),go test -bench=$(BENCH) -run="^$$" $(BENCH_FLAGS) $(pkg);)
  62. .PHONY: updatereadme
  63. updatereadme:
  64. rm -f README.md
  65. cat .readme.tmpl | go run internal/readme/readme.go > README.md