-
Notifications
You must be signed in to change notification settings - Fork 13
/
Makefile
67 lines (53 loc) · 1.74 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
SHELL := /bin/bash
PROJECT_ROOT = $(dir $(abspath $(lastword $(MAKEFILE_LIST))))
# 'go install' into the project's bin directory
# and add it to the PATH.
export GOBIN ?= $(PROJECT_ROOT)/bin
export PATH := $(GOBIN):$(PATH)
ERRTRACE = $(GOBIN)/errtrace
# Packages to instrument with errtrace relative to the project root.
ERRTRACE_PKGS = ./cmd/errtrace/...
# only use -race if NO_RACE is unset.
RACE=$(if $(NO_RACE),,-race)
GOLANGCI_LINT_ARGS ?=
.PHONY: test
test:
go test $(RACE) ./...
go test $(RACE) -tags safe ./...
go test -gcflags='-l -N' ./... # disable optimizations/inlining
.PHONY: cover
cover:
go test -coverprofile cover.unsafe.out -coverpkg ./... $(RACE) ./...
go test -coverprofile cover.safe.out -coverpkg ./... $(RACE) -tags safe ./...
go test ./... -gcflags='-l -N' ./... # disable optimizations/inlining
.PHONY: bench
bench:
go test -run NONE -bench . -cpu 1
.PHONY: bench-parallel
bench-parallel:
go test -run NONE -bench . -cpu 1,2,4,8
.PHONY: lint
lint: golangci-lint errtrace-lint
.PHONY: golangci-lint
golangci-lint:
@if ! command -v golangci-lint >/dev/null; then \
echo "golangci-lint not found. Installing..."; \
mkdir -p $(GOBIN); \
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(GOBIN); \
fi; \
echo "Running golangci-lint"; \
golangci-lint run $(GOLANGCI_LINT_ARGS) ./...
.PHONY: errtrace
errtrace: $(ERRTRACE)
$(ERRTRACE) -w $(ERRTRACE_PKGS)
.PHONY: errtrace-lint
errtrace-lint: $(ERRTRACE)
@echo "Running errtrace"; \
changed=$$($(ERRTRACE) -l $(ERRTRACE_PKGS)); \
if [[ -n "$$changed" ]]; then \
echo "Found uninstrumented files. Please run 'make errtrace'"; \
echo "$$changed"; \
exit 1; \
fi
$(ERRTRACE):
go install braces.dev/errtrace/cmd/errtrace