blob: 1b1376d42533e20a475796849cb0029d8bcb4fc6 [file] [log] [blame]
Girish Gowdra390f12f2021-07-01 15:53:49 -07001# Directory to place `go install`ed binaries into.
2export GOBIN ?= $(shell pwd)/bin
Girish Gowdra64503432020-01-07 10:59:10 +05303
Girish Gowdra390f12f2021-07-01 15:53:49 -07004GOLINT = $(GOBIN)/golint
5GEN_ATOMICINT = $(GOBIN)/gen-atomicint
6GEN_ATOMICWRAPPER = $(GOBIN)/gen-atomicwrapper
7STATICCHECK = $(GOBIN)/staticcheck
Girish Gowdra64503432020-01-07 10:59:10 +05308
Girish Gowdra390f12f2021-07-01 15:53:49 -07009GO_FILES ?= $(shell find . '(' -path .git -o -path vendor ')' -prune -o -name '*.go' -print)
10
11# Also update ignore section in .codecov.yml.
12COVER_IGNORE_PKGS = \
13 go.uber.org/atomic/internal/gen-atomicint \
14 go.uber.org/atomic/internal/gen-atomicwrapper
Girish Gowdra64503432020-01-07 10:59:10 +053015
16.PHONY: build
17build:
Girish Gowdra390f12f2021-07-01 15:53:49 -070018 go build ./...
Girish Gowdra64503432020-01-07 10:59:10 +053019
20.PHONY: test
21test:
Girish Gowdra390f12f2021-07-01 15:53:49 -070022 go test -race ./...
Girish Gowdra64503432020-01-07 10:59:10 +053023
Girish Gowdra390f12f2021-07-01 15:53:49 -070024.PHONY: gofmt
25gofmt:
26 $(eval FMT_LOG := $(shell mktemp -t gofmt.XXXXX))
27 gofmt -e -s -l $(GO_FILES) > $(FMT_LOG) || true
28 @[ ! -s "$(FMT_LOG)" ] || (echo "gofmt failed:" && cat $(FMT_LOG) && false)
Girish Gowdra64503432020-01-07 10:59:10 +053029
Girish Gowdra390f12f2021-07-01 15:53:49 -070030$(GOLINT):
31 cd tools && go install golang.org/x/lint/golint
Girish Gowdra64503432020-01-07 10:59:10 +053032
Girish Gowdra390f12f2021-07-01 15:53:49 -070033$(STATICCHECK):
34 cd tools && go install honnef.co/go/tools/cmd/staticcheck
Girish Gowdra64503432020-01-07 10:59:10 +053035
Girish Gowdra390f12f2021-07-01 15:53:49 -070036$(GEN_ATOMICWRAPPER): $(wildcard ./internal/gen-atomicwrapper/*)
37 go build -o $@ ./internal/gen-atomicwrapper
38
39$(GEN_ATOMICINT): $(wildcard ./internal/gen-atomicint/*)
40 go build -o $@ ./internal/gen-atomicint
41
42.PHONY: golint
43golint: $(GOLINT)
44 $(GOLINT) ./...
45
46.PHONY: staticcheck
47staticcheck: $(STATICCHECK)
48 $(STATICCHECK) ./...
Girish Gowdra64503432020-01-07 10:59:10 +053049
50.PHONY: lint
Girish Gowdra390f12f2021-07-01 15:53:49 -070051lint: gofmt golint staticcheck generatenodirty
Girish Gowdra64503432020-01-07 10:59:10 +053052
Girish Gowdra390f12f2021-07-01 15:53:49 -070053# comma separated list of packages to consider for code coverage.
54COVER_PKG = $(shell \
55 go list -find ./... | \
56 grep -v $(foreach pkg,$(COVER_IGNORE_PKGS),-e "^$(pkg)$$") | \
57 paste -sd, -)
Girish Gowdra64503432020-01-07 10:59:10 +053058
Girish Gowdra390f12f2021-07-01 15:53:49 -070059.PHONY: cover
60cover:
61 go test -coverprofile=cover.out -coverpkg $(COVER_PKG) -v ./...
62 go tool cover -html=cover.out -o cover.html
63
64.PHONY: generate
65generate: $(GEN_ATOMICINT) $(GEN_ATOMICWRAPPER)
66 go generate ./...
67
68.PHONY: generatenodirty
69generatenodirty:
70 @[ -z "$$(git status --porcelain)" ] || ( \
71 echo "Working tree is dirty. Commit your changes first."; \
72 exit 1 )
73 @make generate
74 @status=$$(git status --porcelain); \
75 [ -z "$$status" ] || ( \
76 echo "Working tree is dirty after `make generate`:"; \
77 echo "$$status"; \
78 echo "Please ensure that the generated code is up-to-date." )