forked from cockroachdb/cockroach
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
181 lines (157 loc) · 6.46 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
# 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 :=
# The cockroach image to be used for starting Docker containers
# during acceptance tests. Usually cockroachdb/cockroach{,-dev}
# depending on the context.
COCKROACH_IMAGE :=
RUN := run
# Variables to be overridden on the command line, e.g.
# make test PKG=./storage TESTFLAGS=--vmodule=multiraft=1
PKG := ./...
TAGS :=
TESTS := ".*"
TESTTIMEOUT := 1m10s
CPUS := 1
RACETIMEOUT := 5m
BENCHTIMEOUT := 5m
TESTFLAGS :=
ifeq ($(STATIC),1)
# The netgo build tag instructs the net package to try to build a
# Go-only resolver.
TAGS += netgo
# The installsuffix makes sure we actually get the netgo build, see
# https://github.com/golang/go/issues/9369#issuecomment-69864440
GOFLAGS += -installsuffix netgo
LDFLAGS += -extldflags "-static"
endif
.PHONY: all
all: build test check
# On a release build, rebuild everything (except stdlib)
# 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)' -v -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)' -v
# 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) -cpu $(CPUS) $(PKG) -timeout $(TESTTIMEOUT) $(TESTFLAGS)
.PHONY: testslow
testslow: TESTFLAGS += -v
testslow:
$(GO) test -tags '$(TAGS)' $(GOFLAGS) -i $(PKG)
$(GO) test -tags '$(TAGS)' $(GOFLAGS) -run $(TESTS) -cpu $(CPUS) $(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) -cpu $(CPUS) $(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) -cpu $(CPUS) $(PKG) -timeout $(RACETIMEOUT) $(TESTFLAGS)
.PHONY: bench
bench:
$(GO) test -tags '$(TAGS)' $(GOFLAGS) -i $(PKG)
$(GO) test -tags '$(TAGS)' $(GOFLAGS) -run $(TESTS) -cpu $(CPUS) -bench $(TESTS) $(PKG) -timeout $(BENCHTIMEOUT) $(TESTFLAGS)
.PHONY: coverage
coverage:
$(GO) test -tags '$(TAGS)' $(GOFLAGS) -i $(PKG)
$(GO) test -tags '$(TAGS)' $(GOFLAGS) -cover -run $(TESTS) -cpu $(CPUS) $(PKG) $(TESTFLAGS)
.PHONY: acceptance
acceptance:
@acceptance/run.sh
.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|stop)): log$$'
@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 '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
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