-
Notifications
You must be signed in to change notification settings - Fork 6
/
Makefile
159 lines (115 loc) · 3.72 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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
SHELL = /bin/sh
NW_TEST_RUNNERS = 12
GO := go
M := $(shell printf "\033[34;1m▶\033[0m")
BIN := $(CURDIR)/bin
# APPVERSION can be used by an app's build target. It uses the git sha of HEAD.
APPVERSION := $(or $(shell git rev-parse HEAD 2>/dev/null),"unknown")
# Add items to this variable to add to the `clean` target:
CLEAN :=
# Generic Go binaries
GO_BINARIES := \
$(BIN)/spokes-receive-pack-wrapper \
$(BIN)/spokes-receive-pack-networked-wrapper
EXECUTABLES := \
$(BIN)/spokes-receive-pack
CLEAN += $(EXECUTABLES)
.PHONY: FORCE
.PHONY: all
all: info
all: $(EXECUTABLES)
.PHONY: info
info:
$(GO) version
git --version
$(BIN):
mkdir -p $(BIN)
###########################################################################
# Build binaries
#
# We need to compile using `go build` rather than `go install`,
# because the latter doesn't work for cross-compiling.
# Build the main service app:
$(BIN)/spokes-receive-pack: FORCE | $(BIN)
$(GO) build -ldflags '-X main.BuildVersion=$(APPVERSION)' -o $@ .
# Build other generic Go binaries:
.PHONY: go-binaries
go-binaries: $(GO_BINARIES)
$(GO_BINARIES): $(BIN)/%: cmd/% FORCE | $(BIN)
$(GO) build $(BUILDTAGS) -o $@ ./$<
###########################################################################
# Testing
FAILPOINT_ENABLE := tools/bin/failpoint-ctl enable
FAILPOINT_DISABLE := tools/bin/failpoint-ctl disable
tools/bin/failpoint-ctl:
GOBIN=$(shell pwd)/tools/bin $(GO) install github.com/pingcap/failpoint/[email protected]
failpoint-enable: tools/bin/failpoint-ctl
@echo "$(M) enabling failpoints..."
@$(FAILPOINT_ENABLE)
failpoint-disable: tools/bin/failpoint-ctl
@echo "$(M) disabling failpoints..."
@$(FAILPOINT_DISABLE)
.PHONY: test
test: go-test
test-integration: BUILDTAGS=-tags integration
test-integration: failpoint-enable all go-binaries go-test-integration
TESTFLAGS := -race -timeout 60s
TESTINTEGRATIONFLAGS := $(TESTFLAGS) --tags=integration
TESTSUITE := ./...
.PHONY: go-test
go-test:
@echo "$(M) running tests..."
$(GO) test $(TESTFLAGS) $(TESTSUITE) 2>&1
go-test-integration:
@echo "$(M) running integration tests..."
# Add our compiled `spokes-receive-pack` to the PATH while running tests:
PATH="$(CURDIR)/bin:$(PATH)" \
$(GO) test $(TESTINTEGRATIONFLAGS) $(TESTSUITE) 2>&1
@echo "$(M) disabling failpoints ..."
@$(FAILPOINT_DISABLE)
CLEAN += log/*.log
###########################################################################
# Benchmarks
BENCHFLAGS :=
bench:
@echo "$(M) running benchmarks..."
$(GO) test -bench=. $(BENCHFLAGS) $(TESTSUITE) 2>&1
###########################################################################
# Miscellaneous
.PHONY: coverage
coverage:
@echo "$(M) running code coverage..."
$(GO) test $(TESTFLAGS) $(TESTSUITE) -coverprofile coverage.out 2>&1
$(GO) tool cover -html=coverage.out
rm -f coverage.out
# Profiling
PPROF := $(BIN)/pprof
$(PPROF):
$(GO) get -u github.com/google/pprof
.PHONY: pprof
pprof: | $(PPROF) ## Build the pprof binary
# Formatting
GOFMT := $(BIN)/goimports
$(BIN)/goimports:
GOBIN=$(BIN) $(GO) install golang.org/x/tools/cmd/goimports
# Run goimports on all source files:
.PHONY: fmt
fmt: | $(GOFMT)
@echo "$(M) running goimports..."
@ret=0 && for d in $$($(GO) list -f '{{.Dir}}' ./...); do \
$(GOFMT) -l -w $$d/*.go || ret=$$? ; \
done ; exit $$ret
# Run golang-ci lint on all source files:
GOLANGCILINT := $(BIN)/golangci-lint
$(BIN)/golangci-lint:
GOBIN=$(BIN) $(GO) install github.com/golangci/golangci-lint/cmd/golangci-lint@latest
.PHONY: fmt
lint: | $(GOLANGCILINT)
@echo "$(M) running golangci-lint"
$(GOLANGCILINT) run
###########################################################################
# Cleanup
.PHONY: clean
clean:
@echo "$(M) cleaning..."
rm -f $(CLEAN)