cloudflare/pint
Publicmirrored from https://github.com/cloudflare/pintAvailable
Makefile
99lines · modecode
| 1 | PINT_BIN := pint |
| 2 | PINT_GO_DIRS := cmd internal |
| 3 | PINT_SRC := $(shell find $(PINT_GO_DIRS) -type f -name '*.go') |
| 4 | PINT_VERSION ?= $(shell git describe --tags --always --dirty='-dev') |
| 5 | PINT_COMMIT ?= $(shell git rev-parse HEAD) |
| 6 | |
| 7 | GOBIN := $(shell go env GOBIN) |
| 8 | ifeq ($(GOBIN),) |
| 9 | GOBIN = $(shell go env GOPATH)/bin |
| 10 | endif |
| 11 | |
| 12 | GOFLAGS := -tags stringlabels |
| 13 | |
| 14 | COVER_DIR = .cover |
| 15 | COVER_PROFILE = $(COVER_DIR)/coverage.out |
| 16 | |
| 17 | .PHONY: build |
| 18 | build: $(PINT_BIN) |
| 19 | |
| 20 | $(PINT_BIN): $(PINT_SRC) go.mod go.sum |
| 21 | CGO_ENABLED=0 go build \ |
| 22 | $(GOFLAGS) \ |
| 23 | -trimpath \ |
| 24 | -ldflags='-X main.version=$(PINT_VERSION) -X main.commit=$(PINT_COMMIT) -s -w' \ |
| 25 | ./cmd/pint |
| 26 | |
| 27 | $(GOBIN)/golangci-lint: tools/golangci-lint/go.mod tools/golangci-lint/go.sum |
| 28 | go install -modfile=tools/golangci-lint/go.mod github.com/golangci/golangci-lint/cmd/golangci-lint |
| 29 | .PHONY: lint |
| 30 | lint: $(GOBIN)/golangci-lint |
| 31 | $(GOBIN)/golangci-lint run |
| 32 | |
| 33 | $(GOBIN)/gofumpt: tools/gofumpt/go.mod tools/gofumpt/go.sum |
| 34 | go install -modfile=tools/gofumpt/go.mod mvdan.cc/gofumpt |
| 35 | $(GOBIN)/goimports: tools/goimports/go.mod tools/goimports/go.sum |
| 36 | go install -modfile=tools/goimports/go.mod golang.org/x/tools/cmd/goimports |
| 37 | $(GOBIN)/betteralign: tools/betteralign/go.mod tools/betteralign/go.sum |
| 38 | go install -modfile=tools/betteralign/go.mod github.com/dkorunic/betteralign/cmd/betteralign |
| 39 | .PHONY: format |
| 40 | format: $(GOBIN)/betteralign $(GOBIN)/gofumpt $(GOBIN)/goimports |
| 41 | $(GOBIN)/betteralign -test_files -apply ./... |
| 42 | $(GOBIN)/gofumpt -extra -l -w . |
| 43 | $(GOBIN)/goimports -local github.com/cloudflare/pint -w . |
| 44 | |
| 45 | tidy: |
| 46 | go mod tidy |
| 47 | @for f in $(wildcard tools/*/go.mod) ; do echo ">>> $$f" && cd $(CURDIR)/`dirname "$$f"` && go mod tidy && cd $(CURDIR) ; done |
| 48 | |
| 49 | |
| 50 | .PHONY: test |
| 51 | test: |
| 52 | mkdir -p $(COVER_DIR) |
| 53 | echo 'mode: atomic' > $(COVER_PROFILE) |
| 54 | go test \ |
| 55 | $(GOFLAGS) \ |
| 56 | -covermode=atomic \ |
| 57 | -coverprofile=$(COVER_PROFILE) \ |
| 58 | -coverpkg=./... \ |
| 59 | -race \ |
| 60 | -count=3 \ |
| 61 | -timeout=15m \ |
| 62 | ./... |
| 63 | |
| 64 | .PHONY: debug-testscript |
| 65 | debug-testscript: |
| 66 | for I in ./cmd/pint/tests/*.txt ; do T=`basename "$${I}" | cut -d. -f1`; echo ">>> $${T}" ; go test -count=1 -timeout=30s -v -run=TestScript/$${T} ./cmd/pint || exit 1 ; done |
| 67 | |
| 68 | .PHONY: update-snapshots |
| 69 | update-snapshots: |
| 70 | UPDATE_SNAPS=true UPDATE_SNAPSHOTS=1 go test -count=1 ./... |
| 71 | $(MAKE) test |
| 72 | |
| 73 | .PHONY: cover |
| 74 | cover: test |
| 75 | go tool cover -func=$(COVER_PROFILE) |
| 76 | |
| 77 | .PHONY: coverhtml |
| 78 | coverhtml: test |
| 79 | go tool cover -html=$(COVER_PROFILE) |
| 80 | |
| 81 | .PHONY: benchmark |
| 82 | benchmark: |
| 83 | go test \ |
| 84 | $(GOFLAGS) \ |
| 85 | -count=10 \ |
| 86 | -run=none \ |
| 87 | -bench=. \ |
| 88 | -benchmem \ |
| 89 | ./cmd/pint |
| 90 | |
| 91 | $(GOBIN)/benchstat: tools/benchstat/go.mod tools/benchstat/go.sum |
| 92 | go install -modfile=tools/benchstat/go.mod golang.org/x/perf/cmd/benchstat |
| 93 | .PHONY: benchmark-diff |
| 94 | benchmark-diff: $(GOBIN)/benchstat |
| 95 | echo "Benchmark diff:" | tee benchstat.txt |
| 96 | echo "" | tee -a benchstat.txt |
| 97 | echo '```' | tee -a benchstat.txt |
| 98 | $(GOBIN)/benchstat old.txt new.txt | tee -a benchstat.txt |
| 99 | echo '```' | tee -a benchstat.txt |