You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Makefile 2.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. # Directory to place `go install`ed binaries into.
  2. export GOBIN ?= $(shell pwd)/bin
  3. GOLINT = $(GOBIN)/golint
  4. GEN_ATOMICINT = $(GOBIN)/gen-atomicint
  5. GEN_ATOMICWRAPPER = $(GOBIN)/gen-atomicwrapper
  6. STATICCHECK = $(GOBIN)/staticcheck
  7. GO_FILES ?= $(shell find . '(' -path .git -o -path vendor ')' -prune -o -name '*.go' -print)
  8. # Also update ignore section in .codecov.yml.
  9. COVER_IGNORE_PKGS = \
  10. go.uber.org/atomic/internal/gen-atomicint \
  11. go.uber.org/atomic/internal/gen-atomicwrapper
  12. .PHONY: build
  13. build:
  14. go build ./...
  15. .PHONY: test
  16. test:
  17. go test -race ./...
  18. .PHONY: gofmt
  19. gofmt:
  20. $(eval FMT_LOG := $(shell mktemp -t gofmt.XXXXX))
  21. gofmt -e -s -l $(GO_FILES) > $(FMT_LOG) || true
  22. @[ ! -s "$(FMT_LOG)" ] || (echo "gofmt failed:" && cat $(FMT_LOG) && false)
  23. $(GOLINT):
  24. cd tools && go install golang.org/x/lint/golint
  25. $(STATICCHECK):
  26. cd tools && go install honnef.co/go/tools/cmd/staticcheck
  27. $(GEN_ATOMICWRAPPER): $(wildcard ./internal/gen-atomicwrapper/*)
  28. go build -o $@ ./internal/gen-atomicwrapper
  29. $(GEN_ATOMICINT): $(wildcard ./internal/gen-atomicint/*)
  30. go build -o $@ ./internal/gen-atomicint
  31. .PHONY: golint
  32. golint: $(GOLINT)
  33. $(GOLINT) ./...
  34. .PHONY: staticcheck
  35. staticcheck: $(STATICCHECK)
  36. $(STATICCHECK) ./...
  37. .PHONY: lint
  38. lint: gofmt golint staticcheck generatenodirty
  39. # comma separated list of packages to consider for code coverage.
  40. COVER_PKG = $(shell \
  41. go list -find ./... | \
  42. grep -v $(foreach pkg,$(COVER_IGNORE_PKGS),-e "^$(pkg)$$") | \
  43. paste -sd, -)
  44. .PHONY: cover
  45. cover:
  46. go test -coverprofile=cover.out -coverpkg $(COVER_PKG) -v ./...
  47. go tool cover -html=cover.out -o cover.html
  48. .PHONY: generate
  49. generate: $(GEN_ATOMICINT) $(GEN_ATOMICWRAPPER)
  50. go generate ./...
  51. .PHONY: generatenodirty
  52. generatenodirty:
  53. @[ -z "$$(git status --porcelain)" ] || ( \
  54. echo "Working tree is dirty. Commit your changes first."; \
  55. exit 1 )
  56. @make generate
  57. @status=$$(git status --porcelain); \
  58. [ -z "$$status" ] || ( \
  59. echo "Working tree is dirty after `make generate`:"; \
  60. echo "$$status"; \
  61. echo "Please ensure that the generated code is up-to-date." )