forked from cockroachdb/cockroach
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
148 lines (128 loc) · 5.12 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
# 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 := 15s
RACETIMEOUT := 5m
BENCHTIMEOUT := 5m
# STANDARDTESTFLAGS contains flags that you probably don't want to override;
# TESTFLAGS defaults to empty so setting it doesn't clobber anything standard.
STANDARDTESTFLAGS := -logtostderr
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
# 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
# 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) $(STANDARDTESTFLAGS) -timeout $(TESTTIMEOUT) $(TESTFLAGS)
# "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) $(STANDARDTESTFLAGS) -timeout $(RACETIMEOUT) $(TESTFLAGS)
.PHONY: bench
bench:
$(GO) test -tags '$(TAGS)' $(GOFLAGS) -run $(TESTS) -bench $(TESTS) $(PKG) $(STANDARDTESTFLAGS) -timeout $(BENCHTIMEOUT) $(TESTFLAGS)
# Build, but do not run the tests. This is used to verify the deployable
# Docker image which comes without the build environment. See ./build/deploy
# for details.
.PHONY: testbuild
testbuild:
for p in $(shell $(GO) list $(PKG)); do \
$(GO) test -tags '$(TAGS)' $(GOFLAGS) -c -i $$p || exit $?; \
done
.PHONY: coverage
coverage: build
$(GO) test -tags '$(TAGS)' $(GOFLAGS) -cover -run $(TESTS) $(PKG) $(TESTFLAGS)
.PHONY: acceptance
acceptance:
# The first `stop` stops and cleans up any containers from previous runs.
(cd $(RUN) && export COCKROACH_IMAGE="$(COCKROACH_IMAGE)" && \
../build/build-docker-dev.sh && \
./local-cluster.sh stop && \
./local-cluster.sh start && \
./local-cluster.sh stop)
.PHONY: check
check:
errcheck -ignore 'bytes:Write.*,compress/gzip:Close,io:(Close|Write),net:Close,net/http:(Close|Write),net/rpc:Close,os:Close,github.com/spf13/cobra:Usage' $(PKG)
.PHONY: clean
clean:
$(GO) clean -tags '$(TAGS)' $(GOFLAGS) -i github.com/cockroachdb/...
find . -name '*.test' -type f -exec rm -f {} \;
rm -rf build/deploy/build
# List all of the dependencies which are not part of the standard
# library or cockroachdb/cockroach.
.PHONY: listdeps
listdeps:
@go list -f '{{range .Deps}}{{printf "%s\n" .}}{{end}}' ./... | \
sort | uniq | egrep '[^/]+\.[^/]+/' | \
egrep -v 'github.com/cockroachdb/cockroach'
GITHOOKS := $(subst githooks/,.git/hooks/,$(wildcard githooks/*))
.git/hooks/%: githooks/%
@echo installing $<
@rm -f $@
@mkdir -p $(dir $@)
@ln -s ../../$(basename $<) $(dir $@)
# Update the git hooks and run the bootstrap script whenever either
# one changes.
.bootstrap: $(GITHOOKS) build/devbase/godeps.sh
@build/devbase/godeps.sh
@touch $@
-include .bootstrap