Makefile 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. export GOBIN ?= $(shell pwd)/bin
  2. GOLINT = $(GOBIN)/golint
  3. STATICCHECK = $(GOBIN)/staticcheck
  4. BENCH_FLAGS ?= -cpuprofile=cpu.pprof -memprofile=mem.pprof -benchmem
  5. # Directories containing independent Go modules.
  6. #
  7. # We track coverage only for the main module.
  8. MODULE_DIRS = . ./benchmarks
  9. # Many Go tools take file globs or directories as arguments instead of packages.
  10. GO_FILES := $(shell \
  11. find . '(' -path '*/.*' -o -path './vendor' ')' -prune \
  12. -o -name '*.go' -print | cut -b3-)
  13. .PHONY: all
  14. all: lint test
  15. .PHONY: lint
  16. lint: $(GOLINT) $(STATICCHECK)
  17. @rm -rf lint.log
  18. @echo "Checking formatting..."
  19. @gofmt -d -s $(GO_FILES) 2>&1 | tee lint.log
  20. @echo "Checking vet..."
  21. @$(foreach dir,$(MODULE_DIRS),(cd $(dir) && go vet ./... 2>&1) &&) true | tee -a lint.log
  22. @echo "Checking lint..."
  23. @$(foreach dir,$(MODULE_DIRS),(cd $(dir) && $(GOLINT) ./... 2>&1) &&) true | tee -a lint.log
  24. @echo "Checking staticcheck..."
  25. @$(foreach dir,$(MODULE_DIRS),(cd $(dir) && $(STATICCHECK) ./... 2>&1) &&) true | tee -a lint.log
  26. @echo "Checking for unresolved FIXMEs..."
  27. @git grep -i fixme | grep -v -e Makefile | tee -a lint.log
  28. @echo "Checking for license headers..."
  29. @./checklicense.sh | tee -a lint.log
  30. @[ ! -s lint.log ]
  31. $(GOLINT):
  32. go install golang.org/x/lint/golint
  33. $(STATICCHECK):
  34. go install honnef.co/go/tools/cmd/staticcheck
  35. .PHONY: test
  36. test:
  37. @$(foreach dir,$(MODULE_DIRS),(cd $(dir) && go test -race ./...) &&) true
  38. .PHONY: cover
  39. cover:
  40. go test -race -coverprofile=cover.out -coverpkg=./... ./...
  41. go tool cover -html=cover.out -o cover.html
  42. .PHONY: bench
  43. BENCH ?= .
  44. bench:
  45. @$(foreach dir,$(MODULE_DIRS), ( \
  46. cd $(dir) && \
  47. go list ./... | xargs -n1 go test -bench=$(BENCH) -run="^$$" $(BENCH_FLAGS) \
  48. ) &&) true
  49. .PHONY: updatereadme
  50. updatereadme:
  51. rm -f README.md
  52. cat .readme.tmpl | go run internal/readme/readme.go > README.md