Permalink
Newer
Older
100644 1439 lines (1209 sloc) 62 KB
1
# Copyright 2014 The Cockroach Authors.
2
#
3
# Licensed under the Apache License, Version 2.0 (the "License");
4
# you may not use this file except in compliance with the License.
5
# You may obtain a copy of the License at
6
#
7
# http://www.apache.org/licenses/LICENSE-2.0
8
#
9
# Unless required by applicable law or agreed to in writing, software
10
# distributed under the License is distributed on an "AS IS" BASIS,
11
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
12
# implied. See the License for the specific language governing
13
# permissions and limitations under the License.
15
# WARNING: This Makefile is not easily understood. If you're here looking for
16
# typical Make invocations to build the project and run tests, you'll be better
17
# served by running `make help`.
18
#
19
# Maintainers: the output of `make help` is automatically generated from the
20
# double-hash (##) comments throughout this Makefile. Please submit
21
# improvements!
22
23
-include build/defs.mk
24
25
ifeq "$(findstring bench,$(MAKECMDGOALS))" "bench"
26
$(if $(TESTS),$(error TESTS cannot be specified with `make bench` (did you mean BENCHES?)))
27
else
28
$(if $(BENCHES),$(error BENCHES can only be specified with `make bench`))
29
endif
30
31
# Prevent invoking make with a specific test name without a constraining
32
# package.
33
ifneq "$(filter bench% test% stress%,$(MAKECMDGOALS))" ""
34
ifeq "$(PKG)" ""
35
$(if $(subst -,,$(TESTS)),$(error TESTS must be specified with PKG (e.g. PKG=./pkg/sql)))
36
$(if $(subst -,,$(BENCHES)),$(error BENCHES must be specified with PKG (e.g. PKG=./pkg/sql)))
37
endif
38
endif
40
TYPE :=
41
ifneq "$(TYPE)" ""
42
$(error Make no longer understands TYPE. Use 'build/builder.sh mkrelease $(subst release-,,$(TYPE))' instead)
43
endif
44
45
## Which package to run tests against, e.g. "./pkg/storage".
46
PKG := ./pkg/...
47
48
## Tests to run for use with `make test` or `make check-libroach`.
49
TESTS := .
50
51
## Benchmarks to run for use with `make bench`.
52
BENCHES :=
53
54
## Space delimited list of logic test files to run, for make testlogic/testccllogic/testoptlogic/testplannerlogic.
57
## Name of a logic test configuration to run, for make testlogic/testccllogic/testoptlogic/testplannerlogic.
58
## (default: all configs. It's not possible yet to specify multiple configs in this way.)
59
TESTCONFIG :=
60
61
## Regex for matching logic test subtests. This is always matched after "FILES"
62
## if they are provided.
63
SUBTESTS :=
64
65
## Test timeout to use for regular tests.
66
TESTTIMEOUT := 8m
67
68
## Test timeout to use for race tests.
69
RACETIMEOUT := 25m
70
71
## Test timeout to use for acceptance tests.
72
ACCEPTANCETIMEOUT := 30m
73
74
## Test timeout to use for benchmarks.
75
BENCHTIMEOUT := 5m
76
77
## Extra flags to pass to the go test runner, e.g. "-v --vmodule=raft=1"
78
TESTFLAGS :=
79
80
## Extra flags to pass to `stress` during `make stress`.
81
STRESSFLAGS :=
82
83
## Cluster to use for `make roachprod-stress`
84
CLUSTER :=
85
86
DUPLFLAGS := -t 100
87
GOFLAGS :=
89
ARCHIVE := cockroach.src.tgz
90
STARTFLAGS := -s type=mem,size=1GiB --logtostderr
91
BUILDTARGET := ./pkg/cmd/cockroach
92
SUFFIX := $(GOEXE)
93
INSTALL := install
94
prefix := /usr/local
95
bindir := $(prefix)/bin
97
ifeq "$(findstring -j,$(shell ps -o args= $$PPID))" ""
98
ifdef NCPUS
99
MAKEFLAGS += -j$(NCPUS)
100
$(info Running make with -j$(NCPUS))
101
endif
102
endif
104
help: ## Print help for targets with comments.
105
@echo "Usage:"
106
@echo " make [target...] [VAR=foo VAR2=bar...]"
107
@echo ""
108
@echo "Useful commands:"
109
@grep -Eh '^[a-zA-Z._-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf " $(cyan)%-30s$(term-reset) %s\n", $$1, $$2}'
110
@echo ""
111
@echo "Useful variables:"
112
@awk 'BEGIN { FS = ":=" } /^## /{x = substr($$0, 4); getline; if (NF >= 2) printf " $(cyan)%-30s$(term-reset) %s\n", $$1, x}' $(MAKEFILE_LIST) | sort
113
@echo ""
114
@echo "Typical usage:"
115
@printf " $(cyan)%s$(term-reset)\n %s\n\n" \
116
"make test" "Run all unit tests." \
117
"make test PKG=./pkg/sql" "Run all unit tests in the ./pkg/sql package" \
118
"make test PKG=./pkg/sql/parser TESTS=TestParse" "Run the TestParse test in the ./pkg/sql/parser package." \
119
"make bench PKG=./pkg/sql/parser BENCHES=BenchmarkParse" "Run the BenchmarkParse benchmark in the ./pkg/sql/parser package." \
120
"make testlogic" "Run all OSS SQL logic tests." \
121
"make testccllogic" "Run all CCL SQL logic tests." \
122
"make testoptlogic" "Run all opt exec builder SQL logic tests." \
123
"make testbaselogic" "Run all the baseSQL SQL logic tests." \
124
"make testlogic FILES='prepare fk'" "Run the logic tests in the files named prepare and fk." \
125
"make testlogic FILES=fk SUBTESTS='20042|20045'" "Run the logic tests within subtests 20042 and 20045 in the file named fk." \
126
"make testlogic TESTCONFIG=local" "Run the logic tests for the cluster configuration 'local'." \
127
"make check-libroach TESTS=ccl" "Run the libroach tests matching .*ccl.*"
129
BUILDTYPE := development
131
# Build C/C++ with basic debugging information.
132
CFLAGS += -g1
133
CXXFLAGS += -g1
136
# TODO(benesch): remove filter-outs below when golang/go#26144 and
137
# golang/go#16651, respectively, are fixed.
138
CGO_CFLAGS = $(filter-out -g%,$(CFLAGS))
139
CGO_CXXFLAGS = $(CXXFLAGS)
140
CGO_LDFLAGS = $(filter-out -static,$(LDFLAGS))
142
export CFLAGS CXXFLAGS LDFLAGS CGO_CFLAGS CGO_CXXFLAGS CGO_LDFLAGS
143
144
# We intentionally use LINKFLAGS instead of the more traditional LDFLAGS
145
# because LDFLAGS has built-in semantics that don't make sense with the Go
146
# toolchain.
147
override LINKFLAGS = -X github.com/cockroachdb/cockroach/pkg/build.typ=$(BUILDTYPE) -extldflags "$(LDFLAGS)"
149
GO ?= go
150
GOFLAGS ?=
151
TAR ?= tar
152
153
# Ensure we have an unambiguous GOPATH.
154
GOPATH := $(shell $(GO) env GOPATH)
155
156
ifneq "$(or $(findstring :,$(GOPATH)),$(findstring ;,$(GOPATH)))" ""
157
$(error GOPATHs with multiple entries are not supported)
158
endif
159
160
GOPATH := $(realpath $(GOPATH))
161
ifeq "$(strip $(GOPATH))" ""
162
$(error GOPATH is not set and could not be automatically determined)
163
endif
164
165
ifeq "$(filter $(GOPATH)%,$(CURDIR))" ""
166
$(error Current directory "$(CURDIR)" is not within GOPATH "$(GOPATH)")
167
endif
168
169
ifeq "$(GOPATH)" "/"
170
$(error GOPATH=/ is not supported)
171
endif
172
173
$(info GOPATH set to $(GOPATH))
174
175
# We install our vendored tools to a directory within this repository to avoid
176
# overwriting any user-installed binaries of the same name in the default GOBIN.
177
GO_INSTALL := GOBIN='$(abspath bin)' $(GO) install
178
179
# Prefer tools we've installed with go install and Yarn to those elsewhere on
180
# the PATH.
181
export PATH := $(abspath bin):$(PATH)
182
183
# HACK: Make has a fast path and a slow path for command execution,
184
# but the fast path uses the PATH variable from when make was started,
185
# not the one we set on the previous line. In order for the above
186
# line to have any effect, we must force make to always take the slow path.
187
# Setting the SHELL variable to a value other than the default (/bin/sh)
188
# is one way to do this globally.
189
# http://stackoverflow.com/questions/8941110/how-i-could-add-dir-to-path-in-makefile/13468229#13468229
190
#
191
# We also force the PWD environment variable to $(CURDIR), which ensures that
192
# any programs invoked by Make see a physical CWD without any symlinks. The Go
193
# toolchain does not support symlinks well (for one example, see
194
# https://github.com/golang/go/issues/24359). This may be fixed when GOPATH is
195
# deprecated, so revisit whether this workaround is necessary then.
196
export SHELL := env PWD=$(CURDIR) bash
197
ifeq ($(SHELL),)
198
$(error bash is required)
199
endif
200
201
# Invocation of any NodeJS script should be prefixed by NODE_RUN. See the
202
# comments within node-run.sh for rationale.
203
NODE_RUN := build/node-run.sh
204
205
# make-lazy converts a recursive variable, which is evaluated every time it's
206
# referenced, to a lazy variable, which is evaluated only the first time it's
207
# used. See: http://blog.jgc.org/2016/07/lazy-gnu-make-variables.html
208
override make-lazy = $(eval $1 = $$(eval $1 := $(value $1))$$($1))
209
210
# GNU tar and BSD tar both support transforming filenames according to a regular
211
# expression, but have different flags to do so.
212
TAR_XFORM_FLAG = $(shell $(TAR) --version | grep -q GNU && echo "--xform='flags=r;s'" || echo "-s")
213
$(call make-lazy,TAR_XFORM_FLAG)
214
215
# To edit in-place without creating a backup file, GNU sed requires a bare -i,
216
# while BSD sed requires an empty string as the following argument.
217
SED_INPLACE = sed $(shell sed --version 2>&1 | grep -q GNU && echo -i || echo "-i ''")
218
$(call make-lazy,SED_INPLACE)
219
220
# MAKE_TERMERR is set automatically in Make v4.1+, but macOS is still shipping
221
# v3.81.
222
MAKE_TERMERR ?= $(shell [[ -t 2 ]] && echo true)
223
224
# This is how you get a literal space into a Makefile.
225
space := $(eval) $(eval)
226
227
# Color support.
228
yellow = $(shell { tput setaf 3 || tput AF 3; } 2>/dev/null)
229
cyan = $(shell { tput setaf 6 || tput AF 6; } 2>/dev/null)
230
term-reset = $(shell { tput sgr0 || tput me; } 2>/dev/null)
231
$(call make-lazy,yellow)
232
$(call make-lazy,cyan)
233
$(call make-lazy,term-reset)
234
235
# Print an error if the user specified any variables on the command line that
236
# don't appear in this Makefile. The list of valid variables is automatically
237
# rebuilt on the first successful `make` invocation after the Makefile changes.
238
include build/variables.mk
239
$(foreach v,$(filter-out $(strip $(VALID_VARS)),$(.VARIABLES)),\
240
$(if $(findstring command line,$(origin $v)),$(error Variable '$v' is not recognized by this Makefile)))
241
-include customenv.mk
242
243
# Tell Make to delete the target if its recipe fails. Otherwise, if a recipe
244
# modifies its target before failing, the target's timestamp will make it appear
245
# up-to-date on the next invocation of Make, even though it is likely corrupt.
246
# See: https://www.gnu.org/software/make/manual/html_node/Errors.html#Errors
247
.DELETE_ON_ERROR:
248
249
# Targets that name a real file that must be rebuilt on every Make invocation
250
# should depend on .ALWAYS_REBUILD. (.PHONY should only be used on targets that
251
# don't name a real file because .DELETE_ON_ERROR does not apply to .PHONY
252
# targets.)
253
.ALWAYS_REBUILD:
254
.PHONY: .ALWAYS_REBUILD
255
256
ifneq ($(GIT_DIR),)
257
# If we're in a git worktree, the git hooks directory may not be in our root,
258
# so we ask git for the location.
259
#
260
# Note that `git rev-parse --git-path hooks` requires git 2.5+.
261
GITHOOKS := $(subst githooks/,$(GITHOOKSDIR)/,$(wildcard githooks/*))
262
$(GITHOOKSDIR)/%: githooks/%
263
@echo installing $<
264
@rm -f $@
265
@mkdir -p $(dir $@)
266
@ln -s ../../$(basename $<) $(dir $@)
267
endif
268
269
.SECONDARY: pkg/ui/yarn.installed
270
pkg/ui/yarn.installed: pkg/ui/package.json pkg/ui/yarn.lock pkg/ui/yarn.protobufjs-cli.lock | bin/.submodules-initialized
271
$(NODE_RUN) -C pkg/ui yarn install --offline
272
# Prevent ProtobufJS from trying to install its own packages because a) the
273
# the feature is buggy, and b) it introduces an unnecessary dependency on NPM.
274
# See: https://github.com/dcodeIO/protobuf.js/issues/716.
275
# We additionally pin the dependencies by linking in a lock file for
276
# reproducable builds.
277
$(NODE_RUN) pkg/ui/bin/gen-protobuf-cli-deps.js > pkg/ui/node_modules/protobufjs/cli/package.json
278
ln -sf ../../../yarn.protobufjs-cli.lock pkg/ui/node_modules/protobufjs/cli/yarn.lock
279
$(NODE_RUN) -C pkg/ui/node_modules/protobufjs/cli yarn install --offline
280
@# We remove this broken dependency again in pkg/ui/webpack.config.js.
281
@# See the comment there for details.
282
rm -rf pkg/ui/node_modules/@types/node
283
touch $@
284
285
# Update the git hooks and install commands from dependencies whenever they
286
# change.
287
bin/.bootstrap: $(GITHOOKS) Gopkg.lock | bin/.submodules-initialized
288
@$(GO_INSTALL) -v \
289
./vendor/github.com/client9/misspell/cmd/misspell \
290
./vendor/github.com/cockroachdb/crlfmt \
291
./vendor/github.com/cockroachdb/gostdlib/cmd/gofmt \
292
./vendor/github.com/cockroachdb/gostdlib/x/tools/cmd/goimports \
293
./vendor/github.com/cockroachdb/stress \
294
./vendor/github.com/golang/dep/cmd/dep \
295
./vendor/github.com/golang/lint/golint \
296
./vendor/github.com/grpc-ecosystem/grpc-gateway/protoc-gen-grpc-gateway \
297
./vendor/github.com/jteeuwen/go-bindata/go-bindata \
298
./vendor/github.com/kisielk/errcheck \
299
./vendor/github.com/mattn/goveralls \
300
./vendor/github.com/mibk/dupl \
301
./vendor/github.com/wadey/gocovmerge \
302
./vendor/golang.org/x/perf/cmd/benchstat \
303
./vendor/golang.org/x/tools/cmd/goyacc \
304
./vendor/golang.org/x/tools/cmd/stringer
305
touch $@
306
307
.SECONDARY: bin/.submodules-initialized
308
bin/.submodules-initialized:
309
ifneq ($(GIT_DIR),)
310
git submodule update --init --recursive
311
endif
312
mkdir -p $(@D)
313
touch $@
314
315
IGNORE_GOVERS :=
316
317
# Make doesn't expose a list of the variables declared in a given file, so we
318
# resort to sed magic. Roughly, this sed command prints VARIABLE in lines of the
319
# following forms:
320
#
321
# [export] VARIABLE [:+?]=
322
# TARGET-NAME: [export] VARIABLE [:+?]=
323
#
324
# The additional complexity below handles whitespace and comments.
325
#
326
# The special comments at the beginning are for Github/Go/Reviewable:
327
# https://github.com/golang/go/issues/13560#issuecomment-277804473
328
# https://github.com/Reviewable/Reviewable/wiki/FAQ#how-do-i-tell-reviewable-that-a-file-is-generated-and-should-not-be-reviewed
329
build/variables.mk: Makefile build/archive/contents/Makefile pkg/ui/Makefile build/defs.mk
330
@echo '# Code generated by Make. DO NOT EDIT.' > $@
331
@echo '# GENERATED FILE DO NOT EDIT' >> $@
332
@echo 'define VALID_VARS' >> $@
333
@sed -nE -e '/^ /d' -e 's/([^#]*)#.*/\1/' \
334
-e 's/(^|^[^:]+:)[ ]*(export)?[ ]*([^ ]+)[ ]*[:?+]?=.*/ \3/p' $^ \
335
| sort -u >> $@
336
@echo 'endef' >> $@
337
338
# The following section handles building our C/C++ dependencies. These are
339
# common because both the root Makefile and protobuf.mk have C dependencies.
340
341
host-is-macos := $(findstring Darwin,$(UNAME))
342
host-is-mingw := $(findstring MINGW,$(UNAME))
343
344
ifdef host-is-macos
345
# On macOS 10.11, XCode SDK v8.1 (and possibly others) indicate the presence of
346
# symbols that don't exist until macOS 10.12. Setting MACOSX_DEPLOYMENT_TARGET
347
# to the host machine's actual macOS version works around this. See:
348
# https://github.com/jemalloc/jemalloc/issues/494.
349
export MACOSX_DEPLOYMENT_TARGET ?= $(macos-version)
350
endif
351
352
# Cross-compilation occurs when you set TARGET_TRIPLE to something other than
353
# HOST_TRIPLE. You'll need to ensure the cross-compiling toolchain is on your
354
# path and override the rest of the variables that immediately follow as
355
# necessary. For an example, see build/builder/cmd/mkrelease, which sets these
356
# variables appropriately for the toolchains baked into the builder image.
357
TARGET_TRIPLE := $(HOST_TRIPLE)
358
XCMAKE_SYSTEM_NAME :=
359
XGOOS :=
360
XGOARCH :=
361
XCC := $(TARGET_TRIPLE)-cc
362
XCXX := $(TARGET_TRIPLE)-c++
363
EXTRA_XCMAKE_FLAGS :=
364
EXTRA_XCONFIGURE_FLAGS :=
365
366
ifneq ($(HOST_TRIPLE),$(TARGET_TRIPLE))
367
is-cross-compile := 1
368
endif
369
370
# CMAKE_TARGET_MESSAGES=OFF prevents CMake from printing progress messages
371
# whenever a target is fully built to prevent spammy output from make when
372
# c-deps are all already built. Progress messages are still printed when actual
373
# compilation is being performed.
374
cmake-flags := -DCMAKE_TARGET_MESSAGES=OFF $(if $(host-is-mingw),-G 'MSYS Makefiles')
375
configure-flags :=
376
377
# Use xcmake-flags when invoking CMake on libraries/binaries for the target
378
# platform (i.e., the cross-compiled platform, if specified); use plain
379
# cmake-flags when invoking CMake on libraries/binaries for the host platform.
380
# Similarly for xconfigure-flags and configure-flags, and xgo and GO.
381
xcmake-flags := $(cmake-flags) $(EXTRA_XCMAKE_FLAGS)
382
xconfigure-flags := $(configure-flags) $(EXTRA_XCONFIGURE_FLAGS)
383
xgo := $(GO)
384
385
# If we're cross-compiling, inform Autotools and CMake.
386
ifdef is-cross-compile
387
xconfigure-flags += --host=$(TARGET_TRIPLE) CC=$(XCC) CXX=$(XCXX)
388
xcmake-flags += -DCMAKE_SYSTEM_NAME=$(XCMAKE_SYSTEM_NAME) -DCMAKE_C_COMPILER=$(XCC) -DCMAKE_CXX_COMPILER=$(XCXX)
389
xgo := GOOS=$(XGOOS) GOARCH=$(XGOARCH) CC=$(XCC) CXX=$(XCXX) $(xgo)
390
endif
391
392
C_DEPS_DIR := $(abspath c-deps)
393
CRYPTOPP_SRC_DIR := $(C_DEPS_DIR)/cryptopp
394
JEMALLOC_SRC_DIR := $(C_DEPS_DIR)/jemalloc
395
PROTOBUF_SRC_DIR := $(C_DEPS_DIR)/protobuf
396
ROCKSDB_SRC_DIR := $(C_DEPS_DIR)/rocksdb
397
SNAPPY_SRC_DIR := $(C_DEPS_DIR)/snappy
398
LIBROACH_SRC_DIR := $(C_DEPS_DIR)/libroach
399
400
# Derived build variants.
401
use-stdmalloc := $(findstring stdmalloc,$(TAGS))
402
use-msan := $(findstring msan,$(GOFLAGS))
404
# User-requested build variants.
405
USE_ROCKSDB_ASSERTIONS :=
407
BUILD_DIR := $(GOPATH)/native/$(TARGET_TRIPLE)
408
409
# In MinGW, cgo flags don't handle Unix-style paths, so convert our base path to
410
# a Windows-style path.
411
#
412
# TODO(benesch): Figure out why. MinGW transparently converts Unix-style paths
413
# everywhere else.
414
ifdef host-is-mingw
415
BUILD_DIR := $(shell cygpath -m $(BUILD_DIR))
416
endif
417
418
CRYPTOPP_DIR := $(BUILD_DIR)/cryptopp$(if $(use-msan),_msan)
419
JEMALLOC_DIR := $(BUILD_DIR)/jemalloc$(if $(use-msan),_msan)
420
PROTOBUF_DIR := $(BUILD_DIR)/protobuf$(if $(use-msan),_msan)
421
ROCKSDB_DIR := $(BUILD_DIR)/rocksdb$(if $(use-msan),_msan)$(if $(use-stdmalloc),_stdmalloc)$(if $(USE_ROCKSDB_ASSERTIONS),_assert)
422
SNAPPY_DIR := $(BUILD_DIR)/snappy$(if $(use-msan),_msan)
423
LIBROACH_DIR := $(BUILD_DIR)/libroach$(if $(use-msan),_msan)
424
# Can't share with protobuf because protoc is always built for the host.
425
PROTOC_DIR := $(GOPATH)/native/$(HOST_TRIPLE)/protobuf
426
427
LIBCRYPTOPP := $(CRYPTOPP_DIR)/libcryptopp.a
428
LIBJEMALLOC := $(JEMALLOC_DIR)/lib/libjemalloc.a
429
LIBPROTOBUF := $(PROTOBUF_DIR)/libprotobuf.a
430
LIBROCKSDB := $(ROCKSDB_DIR)/librocksdb.a
431
LIBSNAPPY := $(SNAPPY_DIR)/libsnappy.a
432
LIBROACH := $(LIBROACH_DIR)/libroach.a
433
LIBROACHCCL := $(LIBROACH_DIR)/libroachccl.a
434
PROTOC := $(PROTOC_DIR)/protoc
435
436
C_LIBS_COMMON = $(if $(use-stdmalloc),,$(LIBJEMALLOC)) $(LIBPROTOBUF) $(LIBSNAPPY) $(LIBROCKSDB)
437
C_LIBS_OSS = $(C_LIBS_COMMON) $(LIBROACH)
438
C_LIBS_CCL = $(C_LIBS_COMMON) $(LIBCRYPTOPP) $(LIBROACHCCL)
440
# Go does not permit dashes in build tags. This is undocumented.
441
native-tag := $(subst -,_,$(TARGET_TRIPLE))$(if $(use-stdmalloc),_stdmalloc)$(if $(use-msan),_msan)
443
# In each package that uses cgo, we inject include and library search paths into
444
# files named zcgo_flags_{native-tag}.go. The logic for this is complicated so
445
# that Make-driven builds can cache the state of builds for multiple
446
# configurations at once, while still allowing the use of `go build` and `go
447
# test` for the configuration most recently built with Make.
449
# Building with Make always adds the `make` and {native-tag} tags to the build.
451
# Unsuffixed flags files (zcgo_flags.cgo) have the build constraint `!make` and
452
# are only compiled when invoking the Go toolchain directly on a package-- i.e.,
453
# when the `make` build tag is not specified. These files are rebuilt whenever
454
# the build signature changes (see build/defs.mk.sig), and so reflect the target
455
# triple that Make was most recently invoked with.
457
# Suffixed flags files (e.g. zcgo_flags_{native-tag}.go) have the build
458
# constraint `{native-tag}` and are built the first time a Make-driven build
459
# encounters a given native tag. These tags are unset when building with the Go
460
# toolchain directly, so these files are only compiled when building with Make.
461
CGO_PKGS := cli server/status storage/engine ccl/storageccl/engineccl
462
CGO_UNSUFFIXED_FLAGS_FILES := $(addprefix ./pkg/,$(addsuffix /zcgo_flags.go,$(CGO_PKGS)))
463
CGO_SUFFIXED_FLAGS_FILES := $(addprefix ./pkg/,$(addsuffix /zcgo_flags_$(native-tag).go,$(CGO_PKGS)))
464
CGO_FLAGS_FILES := $(CGO_UNSUFFIXED_FLAGS_FILES) $(CGO_SUFFIXED_FLAGS_FILES)
465
466
$(CGO_UNSUFFIXED_FLAGS_FILES): build/defs.mk.sig
467
468
$(CGO_FLAGS_FILES): Makefile
469
@echo '// GENERATED FILE DO NOT EDIT' > $@
470
@echo >> $@
471
@echo '// +build $(if $(findstring $(native-tag),$@),$(native-tag),!make)' >> $@
472
@echo >> $@
473
@echo 'package $(notdir $(@D))' >> $@
474
@echo >> $@
475
@echo '// #cgo CPPFLAGS: -I$(JEMALLOC_DIR)/include' >> $@
476
@echo '// #cgo LDFLAGS: $(addprefix -L,$(CRYPTOPP_DIR) $(PROTOBUF_DIR) $(JEMALLOC_DIR)/lib $(SNAPPY_DIR) $(ROCKSDB_DIR) $(LIBROACH_DIR))' >> $@
477
@echo 'import "C"' >> $@
478
479
# BUILD ARTIFACT CACHING
480
#
481
# We need to ensure that changes to a dependency's configure or CMake flags
482
# below cause the corresponding dependency to be rebuilt. It would be correct to
483
# have the dependencies list this file itself as a prerequisite, but *all*
484
# dependencies would be rebuilt, likely unnecessarily, whenever this file
485
# changed. Instead, we give each dependency its own marker file, DEP-rebuild, as
486
# a prerequisite.
487
#
488
# It's not important *what* goes in the marker file, so long as its contents
489
# change in the same commit as the configure flags. This causes Git to touch the
490
# marker file when switching between revisions that span the change. For
491
# simplicity, just sequentially bump the version number within.
492
#
493
# NB: the recipes below nuke *all* build artifacts when a dependency's configure
494
# flags change. In theory, we could rely on the dependency's build system to
495
# only rebuild the affected objects, but in practice dependencies on configure
496
# flags are not tracked correctly, and these stale artifacts can cause
497
# particularly hard-to-debug errors.
498
#
499
# Flags needed to make cryptopp to runtime detection of AES cpu instruction sets.
500
# pclmul and ssse3 need to be defined for the overall AES switch but are only used
501
# in GCM mode (not currently in use by cockroach).
502
$(CRYPTOPP_DIR)/Makefile: aes := $(if $(findstring x86_64,$(TARGET_TRIPLE)),-maes -mpclmul -mssse3)
503
$(CRYPTOPP_DIR)/Makefile: $(C_DEPS_DIR)/cryptopp-rebuild | bin/.submodules-initialized
504
rm -rf $(CRYPTOPP_DIR)
505
mkdir -p $(CRYPTOPP_DIR)
506
@# NOTE: If you change the CMake flags below, bump the version in
507
@# $(C_DEPS_DIR)/cryptopp-rebuild. See above for rationale.
508
cd $(CRYPTOPP_DIR) && CFLAGS+=" $(aes)" && CXXFLAGS+=" $(aes)" cmake $(xcmake-flags) $(CRYPTOPP_SRC_DIR) \
509
-DCMAKE_BUILD_TYPE=Release
511
$(JEMALLOC_SRC_DIR)/configure.ac: | bin/.submodules-initialized
512
513
$(JEMALLOC_SRC_DIR)/configure: $(JEMALLOC_SRC_DIR)/configure.ac
514
cd $(JEMALLOC_SRC_DIR) && autoconf
515
516
$(JEMALLOC_DIR)/Makefile: $(C_DEPS_DIR)/jemalloc-rebuild $(JEMALLOC_SRC_DIR)/configure
517
rm -rf $(JEMALLOC_DIR)
518
mkdir -p $(JEMALLOC_DIR)
519
@# NOTE: If you change the configure flags below, bump the version in
520
@# $(C_DEPS_DIR)/jemalloc-rebuild. See above for rationale.
521
@#
522
@# jemalloc profiling deadlocks when built against musl. See
523
@# https://github.com/jemalloc/jemalloc/issues/585.
524
cd $(JEMALLOC_DIR) && $(JEMALLOC_SRC_DIR)/configure $(xconfigure-flags) $(if $(findstring musl,$(TARGET_TRIPLE)),,--enable-prof)
526
$(PROTOBUF_DIR)/Makefile: $(C_DEPS_DIR)/protobuf-rebuild | bin/.submodules-initialized
527
rm -rf $(PROTOBUF_DIR)
528
mkdir -p $(PROTOBUF_DIR)
529
@# NOTE: If you change the CMake flags below, bump the version in
530
@# $(C_DEPS_DIR)/protobuf-rebuild. See above for rationale.
531
cd $(PROTOBUF_DIR) && cmake $(xcmake-flags) -Dprotobuf_BUILD_TESTS=OFF $(PROTOBUF_SRC_DIR)/cmake \
532
-DCMAKE_BUILD_TYPE=Release
533
534
ifneq ($(PROTOC_DIR),$(PROTOBUF_DIR))
535
$(PROTOC_DIR)/Makefile: $(C_DEPS_DIR)/protobuf-rebuild | bin/.submodules-initialized
536
rm -rf $(PROTOC_DIR)
537
mkdir -p $(PROTOC_DIR)
538
@# NOTE: If you change the CMake flags below, bump the version in
539
@# $(C_DEPS_DIR)/protobuf-rebuild. See above for rationale.
540
cd $(PROTOC_DIR) && cmake $(CMAKE_FLAGS) -Dprotobuf_BUILD_TESTS=OFF $(PROTOBUF_SRC_DIR)/cmake \
541
-DCMAKE_BUILD_TYPE=Release
542
endif
543
544
$(ROCKSDB_DIR)/Makefile: sse := $(if $(findstring x86_64,$(TARGET_TRIPLE)),-msse3)
545
$(ROCKSDB_DIR)/Makefile: $(C_DEPS_DIR)/rocksdb-rebuild | bin/.submodules-initialized $(LIBSNAPPY) $(if $(use-stdmalloc),,$(LIBJEMALLOC))
546
rm -rf $(ROCKSDB_DIR)
547
mkdir -p $(ROCKSDB_DIR)
548
@# NOTE: If you change the CMake flags below, bump the version in
549
@# $(C_DEPS_DIR)/rocksdb-rebuild. See above for rationale.
550
cd $(ROCKSDB_DIR) && CFLAGS+=" $(sse)" && CXXFLAGS+=" $(sse)" && cmake $(xcmake-flags) $(ROCKSDB_SRC_DIR) \
551
$(if $(findstring release,$(BUILDTYPE)),-DPORTABLE=ON) -DWITH_GFLAGS=OFF \
552
-DSNAPPY_LIBRARIES=$(LIBSNAPPY) -DSNAPPY_INCLUDE_DIR="$(SNAPPY_SRC_DIR);$(SNAPPY_DIR)" -DWITH_SNAPPY=ON \
553
$(if $(use-stdmalloc),,-DJEMALLOC_LIBRARIES=$(LIBJEMALLOC) -DJEMALLOC_INCLUDE_DIR=$(JEMALLOC_DIR)/include -DWITH_JEMALLOC=ON) \
554
-DCMAKE_BUILD_TYPE=$(if $(ENABLE_ROCKSDB_ASSERTIONS),Debug,Release)
556
$(SNAPPY_DIR)/Makefile: $(C_DEPS_DIR)/snappy-rebuild | bin/.submodules-initialized
557
rm -rf $(SNAPPY_DIR)
558
mkdir -p $(SNAPPY_DIR)
559
@# NOTE: If you change the CMake flags below, bump the version in
560
@# $(C_DEPS_DIR)/snappy-rebuild. See above for rationale.
561
cd $(SNAPPY_DIR) && cmake $(xcmake-flags) $(SNAPPY_SRC_DIR) \
562
-DCMAKE_BUILD_TYPE=Release
564
# TODO(benesch): make it possible to build libroach without CCL code. Because
565
# libroach and libroachccl are defined in the same CMake project, CMake requires
566
# that the CCL code be present even if only the OSS target will be built.
567
$(LIBROACH_DIR)/Makefile: $(C_DEPS_DIR)/libroach-rebuild | bin/.submodules-initialized bin/.cpp_protobuf_sources bin/.cpp_ccl_protobuf_sources
568
rm -rf $(LIBROACH_DIR)
569
mkdir -p $(LIBROACH_DIR)
570
@# NOTE: If you change the CMake flags below, bump the version in
571
@# $(C_DEPS_DIR)/libroach-rebuild. See above for rationale.
572
cd $(LIBROACH_DIR) && cmake $(xcmake-flags) $(LIBROACH_SRC_DIR) -DCMAKE_BUILD_TYPE=Release \
573
-DPROTOBUF_LIB=$(LIBPROTOBUF) -DROCKSDB_LIB=$(LIBROCKSDB) \
574
-DJEMALLOC_LIB=$(LIBJEMALLOC) -DSNAPPY_LIB=$(LIBSNAPPY) \
575
-DCRYPTOPP_LIB=$(LIBCRYPTOPP)
576
577
# Most of our C and C++ dependencies use Makefiles that are generated by CMake,
578
# which are rather slow, taking upwards of 500ms to determine that nothing has
579
# changed. The no-op case is the common case, as C and C++ code is modified
580
# rarely relative to Go code.
581
#
582
# So, for speed, we want to avoid invoking our C and C++ dependencies' build
583
# systems when nothing has changed. We apply a very coarse heuristic that works
584
# well in practice: if every file in a given library's source tree is older than
585
# the compiled library, then the compiled library must be up-to-date.
586
#
587
# Normally, you'd accomplish this in Make itself by declaring a prerequisite for
588
# every file in the library's source tree. For example, you'd have a rule like
589
# this for protoc:
590
#
591
# $(PROTOC): $(PROTOC_DIR)/Makefile $(shell find c-deps/protobuf)
592
# $(MAKE) -C $(PROTOC_DIR) protoc
593
#
594
# Note the prerequisite that shells out to the 'find' command. Unfortunately,
595
# this winds up being as slow as unconditionally invoking the child build
596
# system! The cost of repeated find invocations, one per command, adds up, plus
597
# Make needs to stat all of the resulting files, and it seems to do so
598
# sequentially.
599
#
600
# Instead, we unconditionally run the recipe for each C and C++ dependency, via
601
# .ALWAYS_REBUILD, but condition the execution of the dependency's build system
602
# on the output of uptodate, a Go binary of our own design. uptodate walks and
603
# stats the directory tree in parallel, and can make the up-to-date
604
# determination in under 20ms.
606
$(PROTOC): $(PROTOC_DIR)/Makefile bin/uptodate .ALWAYS_REBUILD | $(LIBPROTOBUF)
607
@uptodate $@ $(PROTOBUF_SRC_DIR) || $(MAKE) --no-print-directory -C $(PROTOC_DIR) protoc
609
$(LIBCRYPTOPP): $(CRYPTOPP_DIR)/Makefile bin/uptodate .ALWAYS_REBUILD
610
@uptodate $@ $(CRYPTOPP_SRC_DIR) || $(MAKE) --no-print-directory -C $(CRYPTOPP_DIR) static
612
$(LIBJEMALLOC): $(JEMALLOC_DIR)/Makefile bin/uptodate .ALWAYS_REBUILD
613
@uptodate $@ $(JEMALLOC_SRC_DIR) || $(MAKE) --no-print-directory -C $(JEMALLOC_DIR) build_lib_static
615
$(LIBPROTOBUF): $(PROTOBUF_DIR)/Makefile bin/uptodate .ALWAYS_REBUILD
616
@uptodate $@ $(PROTOBUF_SRC_DIR) || $(MAKE) --no-print-directory -C $(PROTOBUF_DIR) libprotobuf
618
$(LIBSNAPPY): $(SNAPPY_DIR)/Makefile bin/uptodate .ALWAYS_REBUILD
619
@uptodate $@ $(SNAPPY_SRC_DIR) || $(MAKE) --no-print-directory -C $(SNAPPY_DIR) snappy
621
$(LIBROCKSDB): $(ROCKSDB_DIR)/Makefile bin/uptodate .ALWAYS_REBUILD
622
@uptodate $@ $(ROCKSDB_SRC_DIR) || $(MAKE) --no-print-directory -C $(ROCKSDB_DIR) rocksdb
624
libroach-inputs := $(LIBROACH_SRC_DIR) $(ROCKSDB_SRC_DIR)/include $(PROTOBUF_SRC_DIR)/src
625
626
$(LIBROACH): $(LIBROACH_DIR)/Makefile bin/uptodate .ALWAYS_REBUILD
627
@uptodate $@ $(libroach-inputs) || $(MAKE) --no-print-directory -C $(LIBROACH_DIR) roach
629
$(LIBROACHCCL): $(LIBROACH_DIR)/Makefile bin/uptodate .ALWAYS_REBUILD
630
@uptodate $@ $(libroach-inputs) || $(MAKE) --no-print-directory -C $(LIBROACH_DIR) roachccl
632
# Convenient names for maintainers. Not used by other targets in the Makefile.
633
.PHONY: protoc libcryptopp libjemalloc libprotobuf libsnappy librocksdb libroach libroachccl
634
protoc: $(PROTOC)
635
libcryptopp: $(LIBCRYPTOPP)
636
libjemalloc: $(LIBJEMALLOC)
637
libprotobuf: $(LIBPROTOBUF)
638
libsnappy: $(LIBSNAPPY)
639
librocksdb: $(LIBROCKSDB)
640
libroach: $(LIBROACH)
641
libroachccl: $(LIBROACHCCL)
643
PHONY: check-libroach
644
check-libroach: ## Run libroach tests.
645
check-libroach: $(LIBROACH_DIR)/Makefile $(LIBJEMALLOC) $(LIBPROTOBUF) $(LIBSNAPPY) $(LIBROCKSDB) $(LIBCRYPTOPP)
646
@$(MAKE) --no-print-directory -C $(LIBROACH_DIR)
647
cd $(LIBROACH_DIR) && ctest -V -R $(TESTS)
649
override TAGS += make $(native-tag)
Oct 25, 2017
651
# Some targets (protobuf) produce different results depending on the sort order;
652
# set LC_ALL so this is consistent across systems.
653
export LC_ALL=C
Oct 25, 2017
654
655
# defs.mk stores cached values of shell commands to avoid recomputing them on
656
# every Make invocation. This has a small but noticeable effect, especially on
657
# noop builds.
658
build/defs.mk: Makefile build/defs.mk.sig
659
ifndef IGNORE_GOVERS
660
@build/go-version-check.sh $(GO) || { echo "Disable this check with IGNORE_GOVERS=1." >&2; exit 1; }
661
endif
662
@echo "macos-version = $$(sw_vers -productVersion 2>/dev/null | grep -oE '[0-9]+\.[0-9]+')" > $@
663
@echo "GOEXE = $$($(xgo) env GOEXE)" >> $@
664
@echo "NCPUS = $$({ getconf _NPROCESSORS_ONLN || sysctl -n hw.ncpu || nproc; } 2>/dev/null)" >> $@
665
@echo "UNAME = $$(uname)" >> $@
666
@echo "HOST_TRIPLE = $$($$($(GO) env CC) -dumpmachine)" >> $@
667
@echo "GIT_DIR = $$(git rev-parse --git-dir 2>/dev/null)" >> $@
668
@echo "GITHOOKSDIR = $$(test -d .git && echo '.git/hooks' || git rev-parse --git-path hooks)" >> $@
669
@echo "have-defs = 1" >> $@
670
$(if $(have-defs),$(info Detected change in build system. Rebooting Make.))
671
672
# defs.mk.sig attempts to capture common cases where defs.mk needs to be
673
# recomputed, like when compiling for a different platform or using a different
674
# Go binary. It is not intended to be perfect. Upgrading the compiler toolchain
675
# in place will go unnoticed, for example. Similar problems exist in all Make-
676
# based build systems and are not worth solving.
677
build/defs.mk.sig: sig = $(PATH):$(CURDIR):$(GO):$(GOPATH):$(CC):$(CXX):$(TARGET_TRIPLE):$(BUILDTYPE):$(IGNORE_GOVERS)
678
build/defs.mk.sig: .ALWAYS_REBUILD
679
@echo '$(sig)' | cmp -s - $@ || echo '$(sig)' > $@
680
681
COCKROACH := ./cockroach$(SUFFIX)
682
COCKROACHOSS := ./cockroachoss$(SUFFIX)
683
COCKROACHSHORT := ./cockroachshort$(SUFFIX)
686
pkg/sql/parser/sql.go \
687
pkg/sql/parser/helpmap_test.go \
688
pkg/sql/parser/help_messages.go \
689
pkg/sql/lex/tokens.go \
690
pkg/sql/lex/keywords.go \
691
pkg/sql/lex/reserved_keywords.go
693
PROTOBUF_TARGETS := bin/.go_protobuf_sources bin/.gw_protobuf_sources bin/.cpp_protobuf_sources bin/.cpp_ccl_protobuf_sources
695
DOCGEN_TARGETS := bin/.docgen_bnfs bin/.docgen_functions
696
697
OPTGEN_TARGETS = \
698
pkg/sql/opt/memo/expr.og.go \
699
pkg/sql/opt/operator.og.go \
700
pkg/sql/opt/xform/explorer.og.go \
701
pkg/sql/opt/norm/factory.og.go \
702
pkg/sql/opt/rule_name.og.go \
703
pkg/sql/opt/rule_name_string.go
705
go-targets-ccl := \
706
$(COCKROACH) $(COCKROACHSHORT) go-install \
707
bench benchshort \
708
check test testshort testslow testrace testraceslow testbuild \
709
stress stressrace \
710
generate \
711
lint lintshort
712
713
go-targets := $(go-targets-ccl) $(COCKROACHOSS)
718
.PHONY: c-deps
719
c-deps: $(C_LIBS_CCL)
720
721
build-mode = build -o $@
723
go-install: build-mode = install
725
$(COCKROACH) go-install generate: pkg/ui/distccl/bindata.go
726
727
$(COCKROACHOSS): BUILDTARGET = ./pkg/cmd/cockroach-oss
728
$(COCKROACHOSS): $(C_LIBS_OSS) pkg/ui/distoss/bindata.go
729
730
$(COCKROACHSHORT): BUILDTARGET = ./pkg/cmd/cockroach-short
732
$(go-targets-ccl): $(C_LIBS_CCL)
734
BUILDINFO = .buildinfo/tag .buildinfo/rev
735
BUILD_TAGGED_RELEASE =
737
$(go-targets): bin/.bootstrap $(BUILDINFO) $(CGO_FLAGS_FILES) $(PROTOBUF_TARGETS)
738
$(go-targets): $(SQLPARSER_TARGETS) $(OPTGEN_TARGETS)
739
$(go-targets): override LINKFLAGS += \
740
-X "github.com/cockroachdb/cockroach/pkg/build.tag=$(shell cat .buildinfo/tag)" \
741
-X "github.com/cockroachdb/cockroach/pkg/build.rev=$(shell cat .buildinfo/rev)" \
742
-X "github.com/cockroachdb/cockroach/pkg/build.cgoTargetTriple=$(TARGET_TRIPLE)" \
743
$(if $(BUILDCHANNEL),-X "github.com/cockroachdb/cockroach/pkg/build.channel=$(BUILDCHANNEL)") \
744
$(if $(BUILD_TAGGED_RELEASE),-X "github.com/cockroachdb/cockroach/pkg/util/log.crashReportEnv=$(shell cat .buildinfo/tag)")
746
# The build.utcTime format must remain in sync with TimeFormat in
747
# pkg/build/info.go. It is not installed in tests to avoid busting the cache on
748
# every rebuild.
749
$(COCKROACH) $(COCKROACHOSS) $(COCKROACHSHORT) go-install: override LINKFLAGS += \
750
-X "github.com/cockroachdb/cockroach/pkg/build.utcTime=$(shell date -u '+%Y/%m/%d %H:%M:%S')"
751
752
SETTINGS_DOC_PAGE := docs/generated/settings/settings.html
753
754
# Note: We pass `-v` to `go build` and `go test -i` so that warnings
755
# from the linker aren't suppressed. The usage of `-v` also shows when
756
# dependencies are rebuilt which is useful when switching between
757
# normal and race test builds.
758
.PHONY: go-install
759
$(COCKROACH) $(COCKROACHOSS) $(COCKROACHSHORT) go-install:
760
$(xgo) $(build-mode) -v $(GOFLAGS) -tags '$(TAGS)' -ldflags '$(LINKFLAGS)' $(BUILDTARGET)
761
762
# The build targets, in addition to producing a Cockroach binary, silently
763
# regenerate SQL diagram BNFs and some other doc pages. Generating these docs
764
# doesn't really belong in the build target, but when they were only part of the
765
# generate target it was too easy to forget to regenerate them when necessary
766
# and burn a CI cycle.
767
#
768
# We check these docs into version control in the first place in the hope that
769
# the diff of the generated docs that shows up in Reviewable, 'git diff', etc.
770
# makes it obvious when a commit has broken the docs. For example, it's very
771
# easy for changes to the SQL parser to result in unintelligible railroad
772
# diagrams. When the generated files are not checked in, the breakage goes
773
# unnoticed until the docs team comes along, potentially months later. Much
774
# better to make the developer who introduces the breakage fix the breakage.
775
.PHONY: build buildoss buildshort
776
build: ## Build the CockroachDB binary.
777
buildoss: ## Build the CockroachDB binary without any CCL-licensed code.
778
buildshort: ## Build the CockroachDB binary without the admin UI.
779
build: $(COCKROACH)
780
buildoss: $(COCKROACHOSS)
781
buildshort: $(COCKROACHSHORT)
782
build buildoss buildshort: $(DOCGEN_TARGETS)
783
build buildshort: $(if $(is-cross-compile),,$(SETTINGS_DOC_PAGE))
784
785
# For historical reasons, symlink cockroach to cockroachshort.
786
# TODO(benesch): see if it would break anyone's workflow to remove this.
787
buildshort:
788
ln -sf $(COCKROACHSHORT) $(COCKROACH)
791
install: ## Install the CockroachDB binary.
792
install: $(COCKROACH)
793
$(INSTALL) -d -m 755 $(DESTDIR)$(bindir)
794
$(INSTALL) -m 755 $(COCKROACH) $(DESTDIR)$(bindir)/cockroach
795
798
start:
799
$(COCKROACH) start $(STARTFLAGS)
800
801
# Build, but do not run the tests.
802
# PKG is expanded and all packages are built and moved to their directory.
803
.PHONY: testbuild
804
testbuild:
805
$(xgo) list -tags '$(TAGS)' -f \
806
'$(xgo) test -v $(GOFLAGS) -tags '\''$(TAGS)'\'' -ldflags '\''$(LINKFLAGS)'\'' -c {{.ImportPath}} -o {{.Dir}}/{{.Name}}.test' $(PKG) | \
809
testshort: override TESTFLAGS += -short
810
811
testrace: ## Run tests with the Go race detector enabled.
812
testrace stressrace roachprod-stressrace: override GOFLAGS += -race
813
testrace stressrace roachprod-stressrace: export GORACE := halt_on_error=1
814
testrace stressrace roachprod-stressrace: TESTTIMEOUT := $(RACETIMEOUT)
816
# Directory scans in the builder image are excruciatingly slow when running
817
# Docker for Mac, so we filter out the 20k+ UI dependencies that are
818
# guaranteed to be irrelevant to save nearly 10s on every Make invocation.
819
FIND_RELEVANT := find ./pkg -name node_modules -prune -o
821
bench: ## Run benchmarks.
822
bench benchshort: TESTS := -
823
bench benchshort: BENCHES := .
824
bench benchshort: TESTTIMEOUT := $(BENCHTIMEOUT)
826
# -benchtime=1ns runs one iteration of each benchmark. The -short flag is set so
827
# that longer running benchmarks can skip themselves.
828
benchshort: override TESTFLAGS += -benchtime=1ns -short
829
830
.PHONY: check test testshort testrace testlogic testbaselogic testplannerlogic testccllogic testoptlogic bench benchshort
831
test: ## Run tests.
832
check test testshort testrace bench benchshort:
833
$(xgo) test $(GOFLAGS) -tags '$(TAGS)' -ldflags '$(LINKFLAGS)' -run "$(TESTS)" $(if $(BENCHES),-bench "$(BENCHES)") -timeout $(TESTTIMEOUT) $(PKG) $(TESTFLAGS)
835
.PHONY: stress stressrace
836
stress: ## Run tests under stress.
837
stressrace: ## Run tests under stress with the race detector enabled.
838
stress stressrace:
839
$(xgo) test $(GOFLAGS) -exec 'stress $(STRESSFLAGS)' -tags '$(TAGS)' -ldflags '$(LINKFLAGS)' -run "$(TESTS)" -timeout 0 $(PKG) $(filter-out -v,$(TESTFLAGS)) -v -args -test.timeout $(TESTTIMEOUT)
841
.PHONE: roachprod-stress roachprod-stressrace
842
roachprod-stress roachprod-stressrace: bin/roachprod-stress
843
# The bootstrap target creates, among other things, ./bin/stress.
844
build/builder.sh make bin/.bootstrap
845
build/builder.sh make test GOFLAGS="$(GOFLAGS) -v -c -o $(notdir $(PKG)).test" PKG=$(PKG)
846
@if [ -z "$(CLUSTER)" ]; then \
847
echo "ERROR: missing or empty CLUSTER"; \
848
else \
849
bin/roachprod-stress $(CLUSTER) $(STRESSFLAGS) ./$(notdir $(PKG)).test \
850
-test.run "$(TESTS)" $(filter-out -v,$(TESTFLAGS)) -test.v -test.timeout $(TESTTIMEOUT); \
851
fi
852
853
testlogic: testbaselogic testplannerlogic testoptlogic
854
855
testbaselogic: ## Run SQL Logic Tests.
856
testbaselogic: bin/logictest
857
858
testplannerlogic: ## Run SQL Logic Tests for the heuristic planner.
859
testplannerlogic: bin/logictest
861
testccllogic: ## Run SQL CCL Logic Tests.
862
testccllogic: bin/logictestccl
864
testoptlogic: ## Run SQL Logic Tests from opt package.
865
testoptlogic: bin/logictestopt
866
867
logic-test-selector := $(if $(TESTCONFIG),^$(TESTCONFIG)$$)/$(if $(FILES),^$(subst $(space),$$|^,$(FILES))$$)/$(SUBTESTS)
868
testbaselogic testccllogic: TESTS := TestLogic/$(logic-test-selector)
869
testplannerlogic: TESTS := TestPlannerLogic/$(logic-test-selector)
870
testoptlogic: TESTS := TestExecBuild/$(logic-test-selector)
871
872
# Note: we specify -config here in addition to the filter on TESTS
873
# above. This is because if we only restrict in TESTS, this will
874
# merely cause Go to skip the sub-tests that match the pattern. It
875
# does not prevent loading and initializing every default config in
876
# turn (including setting up the test clusters, etc.). By specifying
877
# -config, the extra initialization overhead is averted.
878
testbaselogic testccllogic testplannerlogic testoptlogic: TESTFLAGS := -test.v $(if $(FILES),-show-sql) $(if $(TESTCONFIG),-config $(TESTCONFIG))
879
testbaselogic testccllogic testplannerlogic testoptlogic:
880
cd $($(<F)-package) && $(<F) -test.run "$(TESTS)" -test.timeout $(TESTTIMEOUT) $(TESTFLAGS)
882
testraceslow: override GOFLAGS += -race
883
testraceslow: TESTTIMEOUT := $(RACETIMEOUT)
884
885
.PHONY: testslow testraceslow
886
testslow testraceslow: override TESTFLAGS += -v
887
testslow testraceslow:
888
$(xgo) test $(GOFLAGS) -tags '$(TAGS)' -ldflags '$(LINKFLAGS)' -run "$(TESTS)" $(if $(BENCHES),-bench "$(BENCHES)") -timeout $(TESTTIMEOUT) $(PKG) $(TESTFLAGS) | grep -F ': Test' | sed -E 's/(--- PASS: |\(|\))//g' | awk '{ print $$2, $$1 }' | sort -rn | head -n 10
Oct 5, 2016
890
.PHONY: upload-coverage
891
upload-coverage: bin/.bootstrap
892
$(GO) install ./vendor/github.com/wadey/gocovmerge
893
$(GO) install ./vendor/github.com/mattn/goveralls
Oct 5, 2016
894
@build/upload-coverage.sh
897
acceptance: TESTTIMEOUT := $(ACCEPTANCETIMEOUT)
898
acceptance: export TESTTIMEOUT := $(TESTTIMEOUT)
899
acceptance: ## Run acceptance tests.
902
.PHONY: dupl
903
dupl: bin/.bootstrap
904
$(FIND_RELEVANT) \
905
-name '*.go' \
906
-not -name '*.pb.go' \
907
-not -name '*.pb.gw.go' \
908
-not -name 'bindata.go' \
909
-not -name '*_string.go' \
910
-not -name 'sql.go' \
911
-not -name 'irgen.go' \
912
-not -name '*.ir.go' \
913
| dupl -files $(DUPLFLAGS)
915
.PHONY: generate
916
generate: ## Regenerate generated code.
917
generate: protobuf $(DOCGEN_TARGETS) $(OPTGEN_TARGETS) $(SQLPARSER_TARGETS) $(SETTINGS_DOC_PAGE) bin/langgen
918
$(GO) generate $(GOFLAGS) -tags '$(TAGS)' -ldflags '$(LINKFLAGS)' $(PKG)
920
.PHONY: lint
921
lint: override TAGS += lint
922
lint: ## Run all style checkers and linters.
924
@if [ -t 1 ]; then echo '$(yellow)NOTE: `make lint` is very slow! Perhaps `make lintshort`?$(term-reset)'; fi
925
@# Run 'go build -i' to ensure we have compiled object files available for all
926
@# packages. In Go 1.10, only 'go vet' recompiles on demand. For details:
927
@# https://groups.google.com/forum/#!msg/golang-dev/qfa3mHN4ZPA/X2UzjNV1BAAJ.
928
$(xgo) build -i -v $(GOFLAGS) -tags '$(TAGS)' -ldflags '$(LINKFLAGS)' $(PKG)
929
$(xgo) test ./pkg/testutils/lint -v $(GOFLAGS) -tags '$(TAGS)' -ldflags '$(LINKFLAGS)' -run 'Lint/$(TESTS)'
930
931
.PHONY: lintshort
932
lintshort: override TAGS += lint
933
lintshort: ## Run a fast subset of the style checkers and linters.
934
$(xgo) test ./pkg/testutils/lint -v $(GOFLAGS) -tags '$(TAGS)' -ldflags '$(LINKFLAGS)' -short -run 'TestLint/$(TESTS)'
936
.PHONY: protobuf
937
protobuf: $(PROTOBUF_TARGETS)
938
protobuf: ## Regenerate generated code for protobuf definitions.
940
# pre-push locally runs most of the checks CI will run. Notably, it doesn't run
941
# the acceptance tests.
942
.PHONY: pre-push
943
pre-push: ## Run generate, lint, and test.
944
pre-push: generate lint test ui-lint ui-test
945
! git status --porcelain | read || (git status; git --no-pager diff -a 1>&2; exit 1)
946
947
# archive builds a source tarball out of this repository. Files in the special
948
# directory build/archive/contents are inserted directly into $(ARCHIVE_BASE).
949
# All other files in the repository are inserted into the archive with prefix
950
# $(ARCHIVE_BASE)/src/github.com/cockroachdb/cockroach to allow the extracted
951
# archive to serve directly as a GOPATH root.
953
archive: ## Build a source tarball from this repository.
954
archive: $(ARCHIVE)
955
956
$(ARCHIVE): $(ARCHIVE).tmp
957
gzip -c $< > $@
958
959
# ARCHIVE_EXTRAS are hard-to-generate files and their prerequisites that are
960
# pre-generated and distributed in source archives to minimize the number of
961
# dependencies required for end-users to build from source.
962
ARCHIVE_EXTRAS = \
963
$(BUILDINFO) \
964
$(SQLPARSER_TARGETS) \
965
$(OPTGEN_TARGETS) \
966
pkg/ui/distccl/bindata.go pkg/ui/distoss/bindata.go
967
968
# TODO(benesch): Make this recipe use `git ls-files --recurse-submodules`
969
# instead of scripts/ls-files.sh once Git v2.11 is widely deployed.
970
.INTERMEDIATE: $(ARCHIVE).tmp
971
$(ARCHIVE).tmp: ARCHIVE_BASE = cockroach-$(shell cat .buildinfo/tag)
972
$(ARCHIVE).tmp: $(ARCHIVE_EXTRAS)
973
scripts/ls-files.sh | $(TAR) -cf $@ -T - $(TAR_XFORM_FLAG),^,$(ARCHIVE_BASE)/src/github.com/cockroachdb/cockroach/, $^
974
(cd build/archive/contents && $(TAR) -rf ../../../$@ $(TAR_XFORM_FLAG),^,$(ARCHIVE_BASE)/, *)
975
976
.buildinfo:
977
@mkdir -p $@
978
979
# Do not use plumbing commands, like git diff-index, in this target. Our build
980
# process modifies files quickly enough that plumbing commands report false
981
# positives on filesystems with only one second of resolution as a performance
982
# optimization. Porcelain commands, like git diff, exist to detect and remove
983
# these false positives.
984
#
985
# For details, see the "Possible timestamp problems with diff-files?" thread on
986
# the Git mailing list (http://marc.info/?l=git&m=131687596307197).
987
.buildinfo/tag: | .buildinfo
988
@{ git describe --tags --dirty 2> /dev/null || git rev-parse --short HEAD; } | tr -d \\n > $@
989
990
.buildinfo/rev: | .buildinfo
991
@git rev-parse HEAD > $@
992
993
ifneq ($(GIT_DIR),)
994
# If we're in a Git checkout, we update the buildinfo information on every build
995
# to keep it up-to-date.
996
.buildinfo/tag: .ALWAYS_REBUILD
997
.buildinfo/rev: .ALWAYS_REBUILD
998
endif
1000
CPP_PROTO_ROOT := $(LIBROACH_SRC_DIR)/protos
1001
CPP_PROTO_CCL_ROOT := $(LIBROACH_SRC_DIR)/protosccl
1003
GOGO_PROTOBUF_PATH := ./vendor/github.com/gogo/protobuf
1004
PROTOBUF_PATH := $(GOGO_PROTOBUF_PATH)/protobuf
1005
1006
GOGOPROTO_PROTO := $(GOGO_PROTOBUF_PATH)/gogoproto/gogo.proto
1007
1008
COREOS_PATH := ./vendor/go.etcd.io
1009
1010
GRPC_GATEWAY_GOOGLEAPIS_PACKAGE := github.com/grpc-ecosystem/grpc-gateway/third_party/googleapis
1011
GRPC_GATEWAY_GOOGLEAPIS_PATH := ./vendor/$(GRPC_GATEWAY_GOOGLEAPIS_PACKAGE)
1012
1013
# Map protobuf includes to the Go package containing the generated Go code.
1014
PROTO_MAPPINGS :=
1015
PROTO_MAPPINGS := $(PROTO_MAPPINGS)Mgoogle/api/annotations.proto=$(GRPC_GATEWAY_GOOGLEAPIS_PACKAGE)/google/api,
1016
PROTO_MAPPINGS := $(PROTO_MAPPINGS)Mgoogle/protobuf/timestamp.proto=github.com/gogo/protobuf/types,
1017
PROTO_MAPPINGS := $(PROTO_MAPPINGS)Mgoogle/protobuf/any.proto=github.com/gogo/protobuf/types,
1019
GW_SERVER_PROTOS := ./pkg/server/serverpb/admin.proto ./pkg/server/serverpb/status.proto ./pkg/server/serverpb/authentication.proto
1020
GW_TS_PROTOS := ./pkg/ts/tspb/timeseries.proto
1021
1022
GW_PROTOS := $(GW_SERVER_PROTOS) $(GW_TS_PROTOS)
1023
GW_SOURCES := $(GW_PROTOS:%.proto=%.pb.gw.go)
1024
1025
GO_PROTOS := $(sort $(shell $(FIND_RELEVANT) -type f -name '*.proto' -print))
1026
GO_SOURCES := $(GO_PROTOS:%.proto=%.pb.go)
1027
1028
PBJS := $(NODE_RUN) pkg/ui/node_modules/.bin/pbjs
1029
PBTS := $(NODE_RUN) pkg/ui/node_modules/.bin/pbts
1031
# Unlike the protobuf compiler for Go and C++, the protobuf compiler for
1032
# JavaScript only needs the entrypoint protobufs to be listed. It automatically
1033
# compiles any protobufs the entrypoints depend upon.
1034
JS_PROTOS_CCL := $(filter %/ccl/storageccl/engineccl/enginepbccl/stats.proto,$(GO_PROTOS))
1035
UI_JS_CCL := pkg/ui/ccl/src/js/protos.js
1036
UI_TS_CCL := pkg/ui/ccl/src/js/protos.d.ts
1037
UI_PROTOS_CCL := $(UI_JS_CCL) $(UI_TS_CCL)
1038
1039
UI_JS_OSS := pkg/ui/src/js/protos.js
1040
UI_TS_OSS := pkg/ui/src/js/protos.d.ts
1041
UI_PROTOS_OSS := $(UI_JS) $(UI_TS)
1043
CPP_PROTOS := $(filter %/roachpb/metadata.proto %/roachpb/data.proto %/roachpb/internal.proto %/engine/enginepb/mvcc.proto %/engine/enginepb/mvcc3.proto %/engine/enginepb/file_registry.proto %/engine/enginepb/rocksdb.proto %/hlc/legacy_timestamp.proto %/hlc/timestamp.proto %/unresolved_addr.proto,$(GO_PROTOS))
1044
CPP_HEADERS := $(subst ./pkg,$(CPP_PROTO_ROOT),$(CPP_PROTOS:%.proto=%.pb.h))
1045
CPP_SOURCES := $(subst ./pkg,$(CPP_PROTO_ROOT),$(CPP_PROTOS:%.proto=%.pb.cc))
1047
CPP_PROTOS_CCL := $(filter %/ccl/baseccl/encryption_options.proto %/ccl/storageccl/engineccl/enginepbccl/key_registry.proto %/ccl/storageccl/engineccl/enginepbccl/stats.proto,$(GO_PROTOS))
1048
CPP_HEADERS_CCL := $(subst ./pkg,$(CPP_PROTO_CCL_ROOT),$(CPP_PROTOS_CCL:%.proto=%.pb.h))
1049
CPP_SOURCES_CCL := $(subst ./pkg,$(CPP_PROTO_CCL_ROOT),$(CPP_PROTOS_CCL:%.proto=%.pb.cc))
1051
$(GOGOPROTO_PROTO): bin/.submodules-initialized
1053
bin/.go_protobuf_sources: $(PROTOC) $(GO_PROTOS) $(GOGOPROTO_PROTO) bin/.bootstrap bin/protoc-gen-gogoroach
1054
$(FIND_RELEVANT) -type f -name '*.pb.go' -exec rm {} +
1055
set -e; for dir in $(sort $(dir $(GO_PROTOS))); do \
1056
build/werror.sh $(PROTOC) -Ipkg:./vendor/github.com:$(GOGO_PROTOBUF_PATH):$(PROTOBUF_PATH):$(COREOS_PATH):$(GRPC_GATEWAY_GOOGLEAPIS_PATH) --gogoroach_out=$(PROTO_MAPPINGS),plugins=grpc,import_prefix=github.com/cockroachdb/cockroach/pkg/:./pkg $$dir/*.proto; \
1057
done
1058
$(SED_INPLACE) '/import _/d' $(GO_SOURCES)
1059
$(SED_INPLACE) -E 's!import (fmt|math) "github.com/cockroachdb/cockroach/pkg/(fmt|math)"! !g' $(GO_SOURCES)
1060
$(SED_INPLACE) -E 's!github\.com/cockroachdb/cockroach/pkg/(etcd)!go.etcd.io/\1!g' $(GO_SOURCES)
1061
$(SED_INPLACE) -E 's!cockroachdb/cockroach/pkg/(prometheus/client_model)!\1/go!g' $(GO_SOURCES)
1062
$(SED_INPLACE) -E 's!github.com/cockroachdb/cockroach/pkg/(bytes|encoding/binary|errors|fmt|io|math|github\.com|(google\.)?golang\.org)!\1!g' $(GO_SOURCES)
1063
@# TODO(benesch): Remove after https://github.com/grpc/grpc-go/issues/711.
1064
$(SED_INPLACE) -E 's!golang.org/x/net/context!context!g' $(GO_SOURCES)
1065
gofmt -s -w $(GO_SOURCES)
1066
touch $@
1067
1068
bin/.gw_protobuf_sources: $(PROTOC) $(GW_SERVER_PROTOS) $(GW_TS_PROTOS) $(GO_PROTOS) $(GOGOPROTO_PROTO) bin/.bootstrap
1069
$(FIND_RELEVANT) -type f -name '*.pb.gw.go' -exec rm {} +
1070
build/werror.sh $(PROTOC) -Ipkg:./vendor/github.com:$(GOGO_PROTOBUF_PATH):$(PROTOBUF_PATH):$(COREOS_PATH):$(GRPC_GATEWAY_GOOGLEAPIS_PATH) --grpc-gateway_out=logtostderr=true,request_context=true:./pkg $(GW_SERVER_PROTOS)
1071
build/werror.sh $(PROTOC) -Ipkg:./vendor/github.com:$(GOGO_PROTOBUF_PATH):$(PROTOBUF_PATH):$(COREOS_PATH):$(GRPC_GATEWAY_GOOGLEAPIS_PATH) --grpc-gateway_out=logtostderr=true,request_context=true:./pkg $(GW_TS_PROTOS)
1072
@# TODO(benesch): Remove after https://github.com/grpc/grpc-go/issues/711.
1073
$(SED_INPLACE) -E 's!golang.org/x/net/context!context!g' $(GW_SOURCES)
1074
gofmt -s -w $(GW_SOURCES)
1075
@# TODO(jordan,benesch) This can be removed along with the above TODO.
1076
goimports -w $(GW_SOURCES)
1079
bin/.cpp_protobuf_sources: $(PROTOC) $(CPP_PROTOS)
1080
rm -rf $(CPP_PROTO_ROOT)
1081
mkdir -p $(CPP_PROTO_ROOT)
1082
build/werror.sh $(PROTOC) -Ipkg:$(GOGO_PROTOBUF_PATH):$(PROTOBUF_PATH) --cpp_out=lite:$(CPP_PROTO_ROOT) $(CPP_PROTOS)
1083
$(SED_INPLACE) -E '/gogoproto/d' $(CPP_HEADERS) $(CPP_SOURCES)
1084
touch $@
1085
1086
bin/.cpp_ccl_protobuf_sources: $(PROTOC) $(CPP_PROTOS_CCL)
1087
rm -rf $(CPP_PROTO_CCL_ROOT)
1088
mkdir -p $(CPP_PROTO_CCL_ROOT)
1089
build/werror.sh $(PROTOC) -Ipkg:$(GOGO_PROTOBUF_PATH):$(PROTOBUF_PATH) --cpp_out=lite:$(CPP_PROTO_CCL_ROOT) $(CPP_PROTOS_CCL)
1090
$(SED_INPLACE) -E '/gogoproto/d' $(CPP_HEADERS_CCL) $(CPP_SOURCES_CCL)
1091
touch $@
1092
1093
.SECONDARY: $(UI_JS_OSS) $(UI_JS_CCL)
1094
$(UI_JS_CCL): $(JS_PROTOS_CCL)
1095
$(UI_JS_OSS) $(UI_JS_CCL): $(GW_PROTOS) pkg/ui/yarn.installed | bin/.submodules-initialized
1096
# Add comment recognized by reviewable.
1097
echo '// GENERATED FILE DO NOT EDIT' > $@
1098
$(PBJS) -t static-module -w es6 --strict-long --keep-case --path pkg --path ./vendor/github.com --path $(GOGO_PROTOBUF_PATH) --path $(COREOS_PATH) --path $(GRPC_GATEWAY_GOOGLEAPIS_PATH) $(filter %.proto,$^) >> $@
1100
.SECONDARY: $(UI_TS_OSS) $(UI_TS_CCL)
1101
protos%.d.ts: protos%.js pkg/ui/yarn.installed
1102
# Add comment recognized by reviewable.
1103
echo '// GENERATED FILE DO NOT EDIT' > $@
1106
STYLINT := ./node_modules/.bin/stylint
1107
TSLINT := ./node_modules/.bin/tslint
1108
TSC := ./node_modules/.bin/tsc
1109
KARMA := ./node_modules/.bin/karma
1110
WEBPACK := ./node_modules/.bin/webpack $(if $(MAKE_TERMERR),--progress)
1111
WEBPACK_DEV_SERVER := ./node_modules/.bin/webpack-dev-server
1112
WEBPACK_DASHBOARD := ./opt/node_modules/.bin/webpack-dashboard
1113
1114
.PHONY: ui-generate
1115
ui-generate: pkg/ui/distccl/bindata.go
1116
1117
.PHONY: ui-lint
1118
ui-lint: pkg/ui/yarn.installed $(UI_PROTOS_OSS) $(UI_PROTOS_CCL)
1119
$(NODE_RUN) -C pkg/ui $(STYLINT) -c .stylintrc styl
1120
$(NODE_RUN) -C pkg/ui $(TSLINT) -c tslint.json -p tsconfig.json
1121
@# TODO(benesch): Invoke tslint just once when palantir/tslint#2827 is fixed.
1122
$(NODE_RUN) -C pkg/ui $(TSLINT) -c tslint.json *.js
1123
$(NODE_RUN) -C pkg/ui $(TSC)
1124
@if $(NODE_RUN) -C pkg/ui yarn list | grep phantomjs; then echo ^ forbidden UI dependency >&2; exit 1; fi
1125
1126
# DLLs are Webpack bundles, not Windows shared libraries. See "DLLs for speedy
1127
# builds" in the UI README for details.
1128
UI_CCL_DLLS := pkg/ui/dist/protos.ccl.dll.js pkg/ui/dist/vendor.oss.dll.js
1129
UI_CCL_MANIFESTS := pkg/ui/protos.ccl.manifest.json pkg/ui/vendor.oss.manifest.json
1130
UI_OSS_DLLS := $(subst .ccl,.oss,$(UI_CCL_DLLS))
1131
UI_OSS_MANIFESTS := $(subst .ccl,.oss,$(UI_CCL_MANIFESTS))
1132
1133
# (Ab)use pattern rules to teach Make that this one Webpack command produces two
1134
# files. Normally, Make would run the recipe twice if dist/FOO.js and
1135
# FOO-manifest.js were both out-of-date. [0]
1137
# XXX: Ideally we'd scope the dependency on $(UI_PROTOS*) to the appropriate
1138
# protos DLLs, but Make v3.81 has a bug that causes the dependency to be ignored
1139
# [1]. We're stuck with this workaround until Apple decides to update the
1140
# version of Make they ship with macOS or we require a newer version of Make.
1141
# Such a requirement would need to be strictly enforced, as the way this fails
1142
# is extremely subtle and doesn't present until the web UI is loaded in the
1143
# browser.
1144
#
1145
# [0]: https://stackoverflow.com/a/3077254/1122351
1146
# [1]: http://savannah.gnu.org/bugs/?19108
1147
.SECONDARY: $(UI_CCL_DLLS) $(UI_CCL_MANIFESTS) $(UI_OSS_DLLS) $(UI_OSS_MANIFESTS)
1148
1149
pkg/ui/dist/%.oss.dll.js pkg/ui/%.oss.manifest.json: pkg/ui/webpack.%.js pkg/ui/yarn.installed $(UI_PROTOS_OSS)
1150
$(NODE_RUN) -C pkg/ui $(WEBPACK) -p --config webpack.$*.js --env.dist=oss
1151
1152
pkg/ui/dist/%.ccl.dll.js pkg/ui/%.ccl.manifest.json: pkg/ui/webpack.%.js pkg/ui/yarn.installed $(UI_PROTOS_CCL)
1153
$(NODE_RUN) -C pkg/ui $(WEBPACK) -p --config webpack.$*.js --env.dist=ccl
1154
1155
.PHONY: ui-test
1156
ui-test: $(UI_CCL_DLLS) $(UI_CCL_MANIFESTS)
1157
$(NODE_RUN) -C pkg/ui $(KARMA) start
1158
1159
.PHONY: ui-test-watch
1160
ui-test-watch: $(UI_CCL_DLLS) $(UI_CCL_MANIFESTS)
1161
$(NODE_RUN) -C pkg/ui $(KARMA) start --no-single-run --auto-watch
1163
.PHONY: ui-test-debug
1164
ui-test-debug: $(UI_DLLS) $(UI_MANIFESTS)
1165
$(NODE_RUN) -C $(UI_ROOT) $(KARMA) start --browsers Chrome --no-single-run --debug --auto-watch
1166
1167
pkg/ui/distccl/bindata.go: $(UI_CCL_DLLS) $(UI_CCL_MANIFESTS) $(UI_JS_CCL) $(shell find pkg/ui/ccl -type f)
1168
pkg/ui/distoss/bindata.go: $(UI_OSS_DLLS) $(UI_OSS_MANIFESTS) $(UI_JS_OSS)
1169
pkg/ui/dist%/bindata.go: pkg/ui/webpack.app.js $(shell find pkg/ui/src pkg/ui/styl -type f) | bin/.bootstrap
1170
find pkg/ui/dist$* -mindepth 1 -not -name dist$*.go -delete
1171
set -e; shopt -s extglob; for dll in $(notdir $(filter %.dll.js,$^)); do \
1172
ln -s ../dist/$$dll pkg/ui/dist$*/$${dll/@(.ccl|.oss)}; \
1173
done
1174
$(NODE_RUN) -C pkg/ui $(WEBPACK) --config webpack.app.js --env.dist=$*
1175
go-bindata -pkg dist$* -o $@ -prefix pkg/ui/dist$* pkg/ui/dist$*/...
1176
echo 'func init() { ui.Asset = Asset; ui.AssetDir = AssetDir; ui.AssetInfo = AssetInfo }' >> $@
1178
goimports -w $@
1180
pkg/ui/yarn.opt.installed:
1181
$(NODE_RUN) -C pkg/ui/opt yarn install
1184
.PHONY: ui-watch-secure
1185
ui-watch-secure: override WEBPACK_DEV_SERVER_FLAGS += --https
1186
ui-watch-secure: export TARGET ?= https://localhost:8080/
1187
1188
.PHONY: ui-watch
1189
ui-watch: export TARGET ?= http://localhost:8080
1190
ui-watch ui-watch-secure: PORT := 3000
1191
ui-watch ui-watch-secure: $(UI_CCL_DLLS) pkg/ui/yarn.opt.installed
1192
cd pkg/ui && $(WEBPACK_DASHBOARD) -- $(WEBPACK_DEV_SERVER) --config webpack.app.js --env.dist=ccl --port $(PORT) $(WEBPACK_DEV_SERVER_FLAGS)
1194
.PHONY: ui-clean
1195
ui-clean: ## Remove build artifacts.
1196
find pkg/ui/dist* -mindepth 1 -not -name dist*.go -delete
1197
rm -f pkg/ui/*manifest.json
1198
1199
.PHONY: ui-maintainer-clean
1200
ui-maintainer-clean: ## Like clean, but also remove installed dependencies
1201
ui-maintainer-clean: ui-clean
1202
rm -rf pkg/ui/node_modules pkg/ui/yarn.installed
1204
.SECONDARY: pkg/sql/parser/gen/sql.go.tmp
1205
pkg/sql/parser/gen/sql.go.tmp: pkg/sql/parser/gen/sql-gen.y bin/.bootstrap
1207
ret=$$(cd pkg/sql/parser/gen && goyacc -p sql -o sql.go.tmp sql-gen.y); \
1208
if expr "$$ret" : ".*conflicts" >/dev/null; then \
1209
echo "$$ret"; exit 1; \
1210
fi
1211
1212
# The lex package needs to know about all tokens, because the encode
1213
# functions and lexing predicates need to know about keywords, and
1214
# keywords map to the token constants. Therefore, generate the
1215
# constant tokens in the lex package primarily.
1216
pkg/sql/lex/tokens.go: pkg/sql/parser/gen/sql.go.tmp
1217
(echo "// Code generated by make. DO NOT EDIT."; \
1218
echo "// GENERATED FILE DO NOT EDIT"; \
1219
echo; \
1220
echo "package lex"; \
1221
echo; \
1222
grep '^const [A-Z][_A-Z0-9]* ' $^) > $@.tmp || rm $@.tmp
1223
mv -f $@.tmp $@
1224
1225
# The lex package is now the primary source for the token constant
1226
# definitions. Modify the code generated by goyacc here to refer to
1227
# the definitions in the lex package.
1228
pkg/sql/parser/sql.go: pkg/sql/parser/gen/sql.go.tmp
1229
(echo "// Code generated by goyacc. DO NOT EDIT."; \
1230
echo "// GENERATED FILE DO NOT EDIT"; \
1231
cat $^ | \
1232
sed -E 's/^const ([A-Z][_A-Z0-9]*) =.*$$/const \1 = lex.\1/g') > $@.tmp || rm $@.tmp
1233
mv -f $@.tmp $@
1235
1236
# This modifies the grammar to:
1237
# - improve the types used by the generated parser for non-terminals
1238
# - expand the help rules.
1239
#
1240
# For types:
1241
# Determine the types that will be migrated to union types by looking
1242
# at the accessors of sqlSymUnion. The first step in this pipeline
1243
# prints every return type of a sqlSymUnion accessor on a separate line.
1244
# The next step regular expression escapes these types. The third step
1245
# joins all of the lines into a single line with a '|' character to be
1246
# used as a regexp "or" meta-character. Finally, the last '|' character
1247
# is stripped from the string.
1248
# Then translate the original syntax file, with the types determined
1249
# above being replaced with the union type in their type declarations.
1250
.SECONDARY: pkg/sql/parser/gen/sql-gen.y
1251
pkg/sql/parser/gen/sql-gen.y: pkg/sql/parser/sql.y pkg/sql/parser/replace_help_rules.awk
1252
mkdir -p pkg/sql/parser/gen
1254
TYPES=$$(awk '/func.*sqlSymUnion/ {print $$(NF - 1)}' pkg/sql/parser/sql.y | \
1255
sed -e 's/[]\/$$*.^|[]/\\&/g' | \
1256
tr '\n' '|' | \
1257
sed -E '$$s/.$$//'); \
1258
sed -E "s_(type|token) <($$TYPES)>_\1 <union> /* <\2> */_" < pkg/sql/parser/sql.y | \
1259
awk -f pkg/sql/parser/replace_help_rules.awk | \
1260
sed -Ee 's,//.*$$,,g;s,/[*]([^*]|[*][^/])*[*]/, ,g;s/ +$$//g' > $@.tmp || rm $@.tmp
1261
mv -f $@.tmp $@
1263
pkg/sql/lex/reserved_keywords.go: pkg/sql/parser/sql.y pkg/sql/parser/reserved_keywords.awk
1264
awk -f pkg/sql/parser/reserved_keywords.awk < $< > $@.tmp || rm $@.tmp
1265
mv -f $@.tmp $@
1266
gofmt -s -w $@
1267
1268
pkg/sql/lex/keywords.go: pkg/sql/parser/sql.y pkg/sql/parser/all_keywords.awk
1269
awk -f pkg/sql/parser/all_keywords.awk < $< > $@.tmp || rm $@.tmp
1270
mv -f $@.tmp $@
1271
gofmt -s -w $@
1272
1273
# This target will print unreserved_keywords which are not actually
1274
# used in the grammar.
1275
.PHONY: sqlparser-unused-unreserved-keywords
1276
sqlparser-unused-unreserved-keywords: pkg/sql/parser/sql.y pkg/sql/parser/unreserved_keywords.awk
1277
@for kw in $$(awk -f pkg/sql/parser/unreserved_keywords.awk < $<); do \
1278
if [ $$(grep -c $${kw} $<) -le 2 ]; then \
1279
echo $${kw}; \
1280
fi \
1281
done
1282
1283
pkg/sql/parser/helpmap_test.go: pkg/sql/parser/gen/sql-gen.y pkg/sql/parser/help_gen_test.sh
1284
@pkg/sql/parser/help_gen_test.sh < $< >$@.tmp || rm $@.tmp
1285
mv -f $@.tmp $@
1286
gofmt -s -w $@
1287
1288
pkg/sql/parser/help_messages.go: pkg/sql/parser/sql.y pkg/sql/parser/help.awk
1289
awk -f pkg/sql/parser/help.awk < $< > $@.tmp || rm $@.tmp
1290
mv -f $@.tmp $@
1291
gofmt -s -w $@
1292
1293
bin/.docgen_bnfs: bin/docgen
1294
docgen grammar bnf docs/generated/sql/bnf --quiet
1297
bin/.docgen_functions: bin/docgen
1298
docgen functions docs/generated/sql --quiet
1301
settings-doc-gen := $(if $(filter buildshort,$(MAKECMDGOALS)),$(COCKROACHSHORT),$(COCKROACH))
1302
1303
$(SETTINGS_DOC_PAGE): $(settings-doc-gen)
1304
@$(settings-doc-gen) gen settings-list --format=html > $@
1306
optgen-defs := pkg/sql/opt/ops/*.opt
1307
optgen-norm-rules := pkg/sql/opt/norm/rules/*.opt
1308
optgen-xform-rules := pkg/sql/opt/xform/rules/*.opt
1309
1310
pkg/sql/opt/memo/expr.og.go: $(optgen-defs) bin/optgen
1311
optgen -out $@ exprs $(optgen-defs)
1312
1313
pkg/sql/opt/operator.og.go: $(optgen-defs) bin/optgen
1314
optgen -out $@ ops $(optgen-defs)
1315
1316
pkg/sql/opt/rule_name.og.go: $(optgen-defs) $(optgen-norm-rules) $(optgen-xform-rules) bin/optgen
1317
optgen -out $@ rulenames $(optgen-defs) $(optgen-norm-rules) $(optgen-xform-rules)
1318
1319
pkg/sql/opt/rule_name_string.go: pkg/sql/opt/rule_name.go pkg/sql/opt/rule_name.og.go bin/.bootstrap
1320
stringer -output=$@ -type=RuleName $(filter %.go,$^)
1321
1322
pkg/sql/opt/xform/explorer.og.go: $(optgen-defs) $(optgen-xform-rules) bin/optgen
1323
optgen -out $@ explorer $(optgen-defs) $(optgen-xform-rules)
1324
1325
pkg/sql/opt/norm/factory.og.go: $(optgen-defs) $(optgen-norm-rules) bin/optgen
1326
optgen -out $@ factory $(optgen-defs) $(optgen-norm-rules)
1327
1328
# Format non-generated .cc and .h files in libroach using clang-format.
1329
.PHONY: c-deps-fmt
1330
c-deps-fmt:
1331
find $(LIBROACH_SRC_DIR) -name '*.cc' -o -name '*.h' | xargs grep -L 'DO NOT EDIT' | xargs clang-format -i
1333
.PHONY: clean-c-deps
1334
clean-c-deps:
1335
rm -rf $(CRYPTOPP_DIR)
1336
rm -rf $(JEMALLOC_DIR)
1337
rm -rf $(PROTOBUF_DIR)
1338
rm -rf $(ROCKSDB_DIR)
1339
rm -rf $(SNAPPY_DIR)
1340
rm -rf $(LIBROACH_DIR)
1341
1342
.PHONY: unsafe-clean-c-deps
1343
unsafe-clean-c-deps:
1344
git -C $(CRYPTOPP_SRC_DIR) clean -dxf
1345
git -C $(JEMALLOC_SRC_DIR) clean -dxf
1346
git -C $(PROTOBUF_SRC_DIR) clean -dxf
1347
git -C $(ROCKSDB_SRC_DIR) clean -dxf
1348
git -C $(SNAPPY_SRC_DIR) clean -dxf
1349
git -C $(LIBROACH_SRC_DIR) clean -dxf
1351
.PHONY: clean
1352
clean: ## Remove build artifacts.
1353
clean: clean-c-deps
1354
rm -rf bin/.go_protobuf_sources bin/.gw_protobuf_sources bin/.cpp_protobuf_sources build/defs.mk*
1355
$(GO) clean $(GOFLAGS) -tags '$(TAGS)' -ldflags '$(LINKFLAGS)' -i -cache github.com/cockroachdb/cockroach...
1356
$(FIND_RELEVANT) -type f \( -name 'zcgo_flags*.go' -o -name '*.test' \) -exec rm {} +
1357
for f in cockroach*; do if [ -f "$$f" ]; then rm "$$f"; fi; done
1358
rm -rf artifacts bin $(ARCHIVE) pkg/sql/parser/gen
1359
1360
.PHONY: maintainer-clean
1361
maintainer-clean: ## Like clean, but also remove some auto-generated source code.
1362
maintainer-clean: clean ui-maintainer-clean
1363
rm -f $(SQLPARSER_TARGETS) $(OPTGEN_TARGETS) $(UI_PROTOS_OSS) $(UI_PROTOS_CCL)
1364
1365
.PHONY: unsafe-clean
1366
unsafe-clean: ## Like maintainer-clean, but also remove ALL untracked/ignored files.
1367
unsafe-clean: maintainer-clean unsafe-clean-c-deps
1368
git clean -dxf
1370
# The following rules automatically generate dependency information for Go
1371
# binaries. See [0] for details on the approach.
1372
#
1373
# [0]: http://make.mad-scientist.net/papers/advanced-auto-dependency-generation/
1374
1376
bin/allocsim \
1377
bin/benchmark \
1378
bin/cockroach-oss \
1379
bin/cockroach-short \
1380
bin/docgen \
1381
bin/generate-binary \
1382
bin/github-post \
1383
bin/github-pull-request-make \
1384
bin/gossipsim \
1385
bin/langgen \
1386
bin/protoc-gen-gogoroach \
1387
bin/publish-artifacts \
1388
bin/optgen \
1389
bin/returncheck \
1390
bin/roachprod-stress \
1391
bin/roachtest \
1392
bin/teamcity-trigger \
1393
bin/uptodate \
1394
bin/urlcheck \
1395
bin/workload \
1396
bin/zerosum
1397
1398
testbins = \
1399
bin/logictest \
1403
# Mappings for binaries that don't live in pkg/cmd.
1404
langgen-package = ./pkg/sql/opt/optgen/cmd/langgen
1405
optgen-package = ./pkg/sql/opt/optgen/cmd/optgen
1406
logictest-package = ./pkg/sql/logictest
1407
logictestccl-package = ./pkg/ccl/logictestccl
1408
logictestopt-package = ./pkg/sql/opt/exec/execbuilder
1410
logictest-bins := bin/logictest bin/logictestopt bin/logictestccl
1411
1412
# Additional dependencies for binaries that depend on generated code.
1413
#
1414
# TODO(benesch): Derive this automatically. This is getting out of hand.
1415
bin/workload bin/docgen bin/roachtest $(logictest-bins): $(SQLPARSER_TARGETS) $(PROTOBUF_TARGETS)
1416
bin/workload bin/roachtest $(logictest-bins): $(C_LIBS_CCL) $(CGO_FLAGS_FILES)
1417
bin/roachtest bin/logictestopt: $(OPTGEN_TARGETS)
1419
$(bins): bin/%: bin/%.d | bin/prereqs bin/.submodules-initialized
1421
bin/prereqs $(if $($*-package),$($*-package),./pkg/cmd/$*) > $@.d.tmp
1423
@$(GO_INSTALL) -v $(if $($*-package),$($*-package),./pkg/cmd/$*)
1425
$(testbins): bin/%: bin/%.d | bin/prereqs $(SUBMODULES_TARGET)
1426
@echo go test -c $($*-package)
1427
bin/prereqs -bin-name=$* -test $($*-package) > $@.d.tmp
1429
$(xgo) test $(GOFLAGS) -tags '$(TAGS)' -ldflags '$(LINKFLAGS)' -c -o $@ $($*-package)
1431
bin/prereqs: ./pkg/cmd/prereqs/*.go
1432
@echo go install -v ./pkg/cmd/prereqs
1433
@$(GO_INSTALL) -v ./pkg/cmd/prereqs
1434
1435
.PRECIOUS: bin/%.d
1436
bin/%.d: ;
1437
1438
include $(wildcard bin/*.d)