khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame^] | 1 | # Directory to place `go install`ed binaries into. |
| 2 | export GOBIN ?= $(shell pwd)/bin |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 3 | |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame^] | 4 | GOLINT = $(GOBIN)/golint |
| 5 | GEN_ATOMICINT = $(GOBIN)/gen-atomicint |
| 6 | GEN_ATOMICWRAPPER = $(GOBIN)/gen-atomicwrapper |
| 7 | STATICCHECK = $(GOBIN)/staticcheck |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 8 | |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame^] | 9 | GO_FILES ?= $(shell find . '(' -path .git -o -path vendor ')' -prune -o -name '*.go' -print) |
| 10 | |
| 11 | # Also update ignore section in .codecov.yml. |
| 12 | COVER_IGNORE_PKGS = \ |
| 13 | go.uber.org/atomic/internal/gen-atomicint \ |
| 14 | go.uber.org/atomic/internal/gen-atomicwrapper |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 15 | |
| 16 | .PHONY: build |
| 17 | build: |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame^] | 18 | go build ./... |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 19 | |
| 20 | .PHONY: test |
| 21 | test: |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame^] | 22 | go test -race ./... |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 23 | |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame^] | 24 | .PHONY: gofmt |
| 25 | gofmt: |
| 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) |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 29 | |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame^] | 30 | $(GOLINT): |
| 31 | cd tools && go install golang.org/x/lint/golint |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 32 | |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame^] | 33 | $(STATICCHECK): |
| 34 | cd tools && go install honnef.co/go/tools/cmd/staticcheck |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 35 | |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame^] | 36 | $(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 |
| 43 | golint: $(GOLINT) |
| 44 | $(GOLINT) ./... |
| 45 | |
| 46 | .PHONY: staticcheck |
| 47 | staticcheck: $(STATICCHECK) |
| 48 | $(STATICCHECK) ./... |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 49 | |
| 50 | .PHONY: lint |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame^] | 51 | lint: gofmt golint staticcheck generatenodirty |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 52 | |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame^] | 53 | # comma separated list of packages to consider for code coverage. |
| 54 | COVER_PKG = $(shell \ |
| 55 | go list -find ./... | \ |
| 56 | grep -v $(foreach pkg,$(COVER_IGNORE_PKGS),-e "^$(pkg)$$") | \ |
| 57 | paste -sd, -) |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 58 | |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame^] | 59 | .PHONY: cover |
| 60 | cover: |
| 61 | go test -coverprofile=cover.out -coverpkg $(COVER_PKG) -v ./... |
| 62 | go tool cover -html=cover.out -o cover.html |
| 63 | |
| 64 | .PHONY: generate |
| 65 | generate: $(GEN_ATOMICINT) $(GEN_ATOMICWRAPPER) |
| 66 | go generate ./... |
| 67 | |
| 68 | .PHONY: generatenodirty |
| 69 | generatenodirty: |
| 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." ) |