-
Notifications
You must be signed in to change notification settings - Fork 21
/
Makefile
92 lines (74 loc) · 2.91 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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
export CGO_ENABLED := 1
include Makefile.Inc
# Set the correct extension for the executable based on the OS
# and set the correct ulimit command for the OS
ifeq ($(OS),Windows_NT)
EXE := .exe
else
ULIMIT := ulimit -n 4096;
endif
GOLANGCI_LINT_VERSION := v1.61.0
GOTESTSUM_VERSION := v1.12.0
MOCKGEN_VERSION := v0.5.0
build: postcli
.PHONY: build
test: get-postrs-lib
@$(ULIMIT) CGO_LDFLAGS="$(CGO_TEST_LDFLAGS)" gotestsum -- -timeout 5m -p 1 -race -short ./...
.PHONY: test
compile-test: get-postrs-lib
CGO_LDFLAGS="$(CGO_TEST_LDFLAGS)" go test -v -c -o $(BIN_DIR)test$(EXE) ./...
.PHONY: compile-test
ifeq ($(HOST_OS),$(filter $(HOST_OS),linux darwin))
compile-windows-test:
CC=x86_64-w64-mingw32-gcc $(MAKE) GOOS=windows GOARCH=amd64 BIN_DIR=$(PROJ_DIR)build/ compile-test
endif
.PHONY: compile-windows-test
install: get-postrs-lib
go mod download
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s $(GOLANGCI_LINT_VERSION)
go install gotest.tools/gotestsum@$(GOTESTSUM_VERSION)
go install go.uber.org/mock/mockgen@$(MOCKGEN_VERSION)
.PHONY: install
tidy:
go mod tidy
.PHONY: tidy
test-tidy:
# Working directory must be clean, or this test would be destructive
git diff --quiet || (echo "\033[0;31mWorking directory not clean!\033[0m" && git --no-pager diff && exit 1)
# We expect `go mod tidy` not to change anything, the test should fail otherwise
make tidy
git diff --exit-code || (git --no-pager diff && git checkout . && exit 1)
.PHONY: test-tidy
test-fmt:
git diff --quiet || (echo "\033[0;31mWorking directory not clean!\033[0m" && git --no-pager diff && exit 1)
# We expect `go fmt` not to change anything, the test should fail otherwise
go fmt ./...
git diff --exit-code || (git --no-pager diff && git checkout . && exit 1)
.PHONY: test-fmt
clear-test-cache:
go clean -testcache
.PHONY: clear-test-cache
lint: get-postrs-lib
./bin/golangci-lint run --config .golangci.yml
.PHONY: lint
# Auto-fixes golangci-lint issues where possible.
lint-fix: get-postrs-lib
./bin/golangci-lint run --config .golangci.yml --fix
.PHONY: lint-fix
cover: get-postrs-lib
@$(ULIMIT) CGO_LDFLAGS="$(CGO_TEST_LDFLAGS)" go test -coverprofile=cover.out -timeout 0 -p 1 -coverpkg=./... ./...
.PHONY: cover
generate: get-postrs-lib
@$(ULIMIT) CGO_LDFLAGS="$(CGO_TEST_LDFLAGS)" go generate ./...
.PHONY: generate
test-generate:
@git diff --quiet || (echo "\033[0;31mWorking directory not clean!\033[0m" && git --no-pager diff && exit 1)
@make generate
@git diff --name-only --diff-filter=AM --exit-code . || { echo "\nPlease rerun 'make generate' and commit changes.\n"; exit 1; }
.PHONY: test-generate
postcli: get-postrs-lib
go build -o $(BIN_DIR)$@$(EXE) ./cmd/postcli
.PHONY: postcli
bench:
@$(ULIMIT) CGO_LDFLAGS="$(CGO_TEST_LDFLAGS)" go test -benchmem -run='^$$' -bench 'BenchmarkVerifying|BenchmarkProving' github.com/spacemeshos/post/proving github.com/spacemeshos/post/verifying
.PHONY: bench