forked from cockroachdb/cockroach
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Makefile
231 lines (202 loc) · 8.28 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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
# Copyright 2014 The Cockroach Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
# implied. See the License for the specific language governing
# permissions and limitations under the License. See the AUTHORS file
# for names of contributors.
#
# Author: Andrew Bonventre (andybons@gmail.com)
# Author: Shawn Morel (shawnmorel@gmail.com)
# Author: Spencer Kimball (spencer.kimball@gmail.com)
# Cockroach build rules.
GO ?= go
# Allow setting of go build flags from the command line.
GOFLAGS :=
# Set to 1 to use static linking for all builds (including tests).
STATIC :=
# Variables to be overridden on the command line, e.g.
# make test PKG=./storage TESTFLAGS=--vmodule=multiraft=1
PKG := ./...
TAGS :=
TESTS := .
TESTTIMEOUT := 1m10s
RACETIMEOUT := 5m
BENCHTIMEOUT := 5m
TESTFLAGS :=
STRESSFLAGS :=
DUPLFLAGS := -t 100
ifeq ($(STATIC),1)
# Static linking with glibc is a bad time; see
# https://github.com/golang/go/issues/13470. If a static build is
# requested, only link libgcc and libstdc++ statically.
# `-v` so warnings from the linker aren't suppressed.
GOFLAGS += -v
# TODO(peter): Allow this only when `go env CC` reports "gcc".
LDFLAGS += -extldflags "-static-libgcc -static-libstdc++"
endif
.PHONY: all
all: build test check
# On a release build, rebuild everything to make sure that the
# 'release' build tag is taken into account.
.PHONY: release
release: TAGS += release
release: GOFLAGS += -a
release: build
.PHONY: build
build: LDFLAGS += -X "github.com/cockroachdb/cockroach/util.buildTag=$(shell git describe --dirty)"
build: LDFLAGS += -X "github.com/cockroachdb/cockroach/util.buildTime=$(shell date -u '+%Y/%m/%d %H:%M:%S')"
build: LDFLAGS += -X "github.com/cockroachdb/cockroach/util.buildDeps=$(shell GOPATH=${GOPATH} build/depvers.sh)"
build:
$(GO) build -tags '$(TAGS)' $(GOFLAGS) -ldflags '$(LDFLAGS)' -i -o cockroach
.PHONY: install
install: LDFLAGS += -X "github.com/cockroachdb/cockroach/util.buildTag=$(shell git describe --dirty)"
install: LDFLAGS += -X "github.com/cockroachdb/cockroach/util.buildTime=$(shell date -u '+%Y/%m/%d %H:%M:%S')"
install: LDFLAGS += -X "github.com/cockroachdb/cockroach/util.buildDeps=$(shell GOPATH=${GOPATH} build/depvers.sh)"
install:
$(GO) install -tags '$(TAGS)' $(GOFLAGS) -ldflags '$(LDFLAGS)'
# Build, but do not run the tests.
# PKG is expanded and all packages are built and moved to their directory.
# If STATIC=1, tests are statically linked.
# eg: to statically build the sql tests, run:
# make testbuild PKG=./sql STATIC=1
.PHONY: testbuild
testbuild: TESTS := $(shell $(GO) list -tags '$(TAGS)' $(PKG))
testbuild: GOFLAGS += -c
testbuild:
for p in $(TESTS); do \
NAME=$$(basename "$$p"); \
OUT="$$NAME.test"; \
DIR=$$($(GO) list -f {{.Dir}} -tags '$(TAGS)' $$p); \
$(GO) test $(GOFLAGS) -tags '$(TAGS)' -o "$$DIR"/"$$OUT" -ldflags '$(LDFLAGS)' "$$p" $(TESTFLAGS) || exit 1; \
done
# Build all tests into DIR and strips each.
# DIR is required.
.PHONY: testbuildall
testbuildall: TESTS := $(shell $(GO) list $(PKG))
testbuildall: GOFLAGS += -c
testbuildall:
ifndef DIR
$(error DIR is undefined)
endif
for p in $(TESTS); do \
NAME=$$(basename "$$p"); \
PKGDIR=$$($(GO) list -f {{.ImportPath}} $$p); \
OUTPUT_FILE="$(DIR)/$${PKGDIR}/$${NAME}.test"; \
$(GO) test $(GOFLAGS) -o $${OUTPUT_FILE} -ldflags '$(LDFLAGS)' "$$p" $(TESTFLAGS) || exit 1; \
if [ -s $${OUTPUT_FILE} ]; then strip -S $${OUTPUT_FILE}; fi \
done
# Similar to "testrace", we want to cache the build before running the
# tests.
.PHONY: test
test:
$(GO) test -tags '$(TAGS)' $(GOFLAGS) -i $(PKG)
$(GO) test -tags '$(TAGS)' $(GOFLAGS) -run $(TESTS) $(PKG) -timeout $(TESTTIMEOUT) $(TESTFLAGS)
.PHONY: testslow
testslow: TESTFLAGS += -v
testslow:
$(GO) test -tags '$(TAGS)' $(GOFLAGS) -i $(PKG)
$(GO) test -tags '$(TAGS)' $(GOFLAGS) -run $(TESTS) $(PKG) -timeout $(TESTTIMEOUT) $(TESTFLAGS) | grep -F ': Test' | sed -E 's/(--- PASS: |\(|\))//g' | awk '{ print $$2, $$1 }' | sort -rn | head -n 10
.PHONY: testraceslow
testraceslow: TESTFLAGS += -v
testraceslow:
$(GO) test -tags '$(TAGS)' $(GOFLAGS) -i $(PKG)
$(GO) test -tags '$(TAGS)' $(GOFLAGS) -race -run $(TESTS) $(PKG) -timeout $(RACETIMEOUT) $(TESTFLAGS) | grep -F ': Test' | sed -E 's/(--- PASS: |\(|\))//g' | awk '{ print $$2, $$1 }' | sort -rn | head -n 10
# "go test -i" builds dependencies and installs them into GOPATH/pkg, but does not run the
# tests. Run it as a part of "testrace" since race-enabled builds are not covered by
# "make build", and so they would be built from scratch every time (including the
# slow-to-compile cgo packages).
.PHONY: testrace
testrace:
$(GO) test -tags '$(TAGS)' $(GOFLAGS) -race -i $(PKG)
$(GO) test -tags '$(TAGS)' $(GOFLAGS) -race -run $(TESTS) $(PKG) -timeout $(RACETIMEOUT) $(TESTFLAGS)
.PHONY: bench
bench:
$(GO) test -tags '$(TAGS)' $(GOFLAGS) -i $(PKG)
$(GO) test -tags '$(TAGS)' $(GOFLAGS) -run - -bench $(TESTS) $(PKG) -timeout $(BENCHTIMEOUT) $(TESTFLAGS)
.PHONY: coverage
coverage:
$(GO) test -tags '$(TAGS)' $(GOFLAGS) -i $(PKG)
$(GO) test -tags '$(TAGS)' $(GOFLAGS) -cover -run $(TESTS) $(PKG) $(TESTFLAGS)
# "make stress PKG=./storage TESTS=TestBlah" will build the given test
# and run it in a loop (the PKG argument is required; if TESTS is not
# given all tests in the package will be run).
.PHONY: stress
stress:
$(GO) test -tags '$(TAGS)' $(GOFLAGS) -i -c $(PKG) -o stress.test
stress $(STRESSFLAGS) ./stress.test -test.run $(TESTS) -test.timeout $(TESTTIMEOUT) $(TESTFLAGS)
.PHONY: stressrace
stressrace:
$(GO) test -tags '$(TAGS)' $(GOFLAGS) -race -i -c $(PKG) -o stress.test
stress $(STRESSFLAGS) ./stress.test -test.run $(TESTS) -test.timeout $(TESTTIMEOUT) $(TESTFLAGS)
.PHONY: acceptance
acceptance:
@acceptance/run.sh
.PHONY: dupl
dupl:
find . -name '*.go' -not -name '*.pb.go' -not -name 'embedded.go' -not -name '*_string.go' -not -name 'sql.go' | dupl -files $(DUPLFLAGS)
.PHONY: check
check:
@echo "checking for tabs in shell scripts"
@! git grep -F ' ' -- '*.sh'
@echo "checking for forbidden imports"
@! $(GO) list -f '{{ $$ip := .ImportPath }}{{ range .Imports}}{{ $$ip }}: {{ println . }}{{end}}' $(PKG) | \
grep -E ' (golang/protobuf/proto|log|path)$$' | \
grep -Ev '(base|security|sql/driver|util(/(log|randutil|stop))?): log$$'
@echo "ineffassign"
@! ineffassign . | grep -vF gossip/gossip.pb.go
@echo "errcheck"
@errcheck -ignore 'bytes:Write.*,io:Close,net:Close,net/http:Close,net/rpc:Close,os:Close,database/sql:Close' $(PKG)
@echo "vet"
@! $(GO) tool vet . 2>&1 | \
grep -vE '^vet: cannot process directory .git'
@echo "vet --shadow"
@! $(GO) tool vet --shadow . 2>&1 | \
grep -vE '(declaration of err shadows|^vet: cannot process directory \.git)'
@echo "golint"
@! golint $(PKG) | \
grep -vE '(\.pb\.go|embedded\.go|_string\.go|LastInsertId|sql/parser/(yaccpar|sql\.y):)' \
# https://golang.org/pkg/database/sql/driver/#Result :(
@echo "varcheck"
@! varcheck -e $(PKG) | \
grep -vE '(_string.go|sql/parser/(yacctab|sql\.y))'
@echo "gofmt (simplify)"
@! gofmt -s -d -l . 2>&1 | grep -vE '^\.git/'
@echo "goimports"
@! goimports -l . | grep -vF 'No Exceptions'
.PHONY: clean
clean:
$(GO) clean -tags '$(TAGS)' $(GOFLAGS) -i github.com/cockroachdb/...
find . -name '*.test' -type f -exec rm -f {} \;
rm -f .bootstrap
.PHONY: protobuf
protobuf:
$(MAKE) -C .. -f cockroach/build/protobuf.mk
ifneq ($(SKIP_BOOTSTRAP),1)
GITHOOKS := $(subst githooks/,.git/hooks/,$(wildcard githooks/*))
.git/hooks/%: githooks/%
@echo installing $<
@rm -f $@
@mkdir -p $(dir $@)
@ln -s ../../$(basename $<) $(dir $@)
GLOCK := ../../../../bin/glock
# ^ ^ ^ ^~ GOPATH
# | | |~ GOPATH/src
# | |~ GOPATH/src/github.com
# |~ GOPATH/src/github.com/cockroachdb
$(GLOCK):
$(GO) get github.com/robfig/glock
# Update the git hooks and run the bootstrap script whenever any
# of them (or their dependencies) change.
.bootstrap: $(GITHOOKS) $(GLOCK) GLOCKFILE
@$(GLOCK) sync github.com/cockroachdb/cockroach
touch $@
-include .bootstrap
endif