github.com/whtcorpsinc/milevadb-prod@v0.0.0-20211104133533-f57f4be3b597/Makefile (about) 1 # Copyright 2020 WHTCORPS INC, Inc. 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 # See the License for the specific language governing permissions and 12 # limitations under the License. 13 14 PROJECT=milevadb 15 GOPATH ?= $(shell go env GOPATH) 16 P=8 17 18 # Ensure GOPATH is set before running build process. 19 ifeq "$(GOPATH)" "" 20 $(error Please set the environment variable GOPATH before running `make`) 21 endif 22 FAIL_ON_STDOUT := awk '{ print } END { if (NR > 0) { exit 1 } }' 23 24 CURDIR := $(shell pwd) 25 path_to_add := $(addsuffix /bin,$(subst :,/bin:,$(GOPATH))):$(PWD)/tools/bin 26 export PATH := $(path_to_add):$(PATH) 27 28 GO := GO111MODULE=on go 29 GOBUILD := $(GO) build $(BUILD_FLAG) -tags codes 30 GOBUILDCOVERAGE := GOPATH=$(GOPATH) cd milevadb-server; $(GO) test -coverpkg="../..." -c . 31 GOTEST := $(GO) test -p $(P) 32 OVERALLS := GO111MODULE=on overalls 33 STATICCHECK := GO111MODULE=on staticcheck 34 MilevaDB_EDITION ?= Community 35 36 # Ensure MilevaDB_EDITION is set to Community or Enterprise before running build process. 37 ifneq "$(MilevaDB_EDITION)" "Community" 38 ifneq "$(MilevaDB_EDITION)" "Enterprise" 39 $(error Please set the correct environment variable MilevaDB_EDITION before running `make`) 40 endif 41 endif 42 43 ARCH := "`uname -s`" 44 LINUX := "Linux" 45 MAC := "Darwin" 46 PACKAGE_LIST := go list ./...| grep -vE "cmd" 47 PACKAGES ?= $$($(PACKAGE_LIST)) 48 PACKAGE_DIRECTORIES := $(PACKAGE_LIST) | sed 's|github.com/whtcorpsinc/$(PROJECT)/||' 49 FILES := $$(find $$($(PACKAGE_DIRECTORIES)) -name "*.go") 50 51 FAILPOINT_ENABLE := $$(find $$PWD/ -type d | grep -vE "(\.git|tools)" | xargs tools/bin/failpoint-ctl enable) 52 FAILPOINT_DISABLE := $$(find $$PWD/ -type d | grep -vE "(\.git|tools)" | xargs tools/bin/failpoint-ctl disable) 53 54 LDFLAGS += -X "github.com/whtcorpsinc/BerolinaSQL/allegrosql.MilevaDBReleaseVersion=$(shell git describe --tags --dirty --always)" 55 LDFLAGS += -X "github.com/whtcorpsinc/milevadb/soliton/versioninfo.MilevaDBBuildTS=$(shell date -u '+%Y-%m-%d %H:%M:%S')" 56 LDFLAGS += -X "github.com/whtcorpsinc/milevadb/soliton/versioninfo.MilevaDBGitHash=$(shell git rev-parse HEAD)" 57 LDFLAGS += -X "github.com/whtcorpsinc/milevadb/soliton/versioninfo.MilevaDBGitBranch=$(shell git rev-parse --abbrev-ref HEAD)" 58 LDFLAGS += -X "github.com/whtcorpsinc/milevadb/soliton/versioninfo.MilevaDBEdition=$(MilevaDB_EDITION)" 59 60 TEST_LDFLAGS = -X "github.com/whtcorpsinc/milevadb/config.checkBeforeDropLDFlag=1" 61 COVERAGE_SERVER_LDFLAGS = -X "github.com/whtcorpsinc/milevadb/milevadb-server.isCoverageServer=1" 62 63 CHECK_LDFLAGS += $(LDFLAGS) ${TEST_LDFLAGS} 64 65 TARGET = "" 66 67 # VB = Vector Benchmark 68 VB_FILE = 69 VB_FUNC = 70 71 72 .PHONY: all clean test gotest server dev benchekv benchraw check checklist BerolinaSQL tidy dbstest 73 74 default: server buildsucc 75 76 server-admin-check: server_check buildsucc 77 78 buildsucc: 79 @echo Build MilevaDB Server successfully! 80 81 all: dev server benchekv 82 83 BerolinaSQL: 84 @echo "remove this command later, when our CI script doesn't call it" 85 86 dev: checklist check test 87 88 # Install the check tools. 89 check-setup:tools/bin/revive tools/bin/goword tools/bin/gospacetimelinter tools/bin/gosec 90 91 check: fmt errcheck unconvert lint tidy testSuite check-static vet staticcheck 92 93 # These need to be fixed before they can be ran regularly 94 check-fail: goword check-slow 95 96 fmt: 97 @echo "gofmt (simplify)" 98 @gofmt -s -l -w $(FILES) 2>&1 | $(FAIL_ON_STDOUT) 99 @cd cmd/importcheck && $(GO) run . ../.. 100 101 goword:tools/bin/goword 102 tools/bin/goword $(FILES) 2>&1 | $(FAIL_ON_STDOUT) 103 104 gosec:tools/bin/gosec 105 tools/bin/gosec $$($(PACKAGE_DIRECTORIES)) 106 107 check-static: tools/bin/golangci-lint 108 tools/bin/golangci-lint run -v --disable-all --deadline=3m \ 109 --enable=misspell \ 110 --enable=ineffassign \ 111 $$($(PACKAGE_DIRECTORIES)) 112 113 check-slow:tools/bin/gospacetimelinter tools/bin/gosec 114 tools/bin/gospacetimelinter --disable-all \ 115 --enable errcheck \ 116 $$($(PACKAGE_DIRECTORIES)) 117 118 errcheck:tools/bin/errcheck 119 @echo "errcheck" 120 @GO111MODULE=on tools/bin/errcheck -exclude ./tools/check/errcheck_excludes.txt -ignoretests -blank $(PACKAGES) 121 122 unconvert:tools/bin/unconvert 123 @echo "unconvert check" 124 @GO111MODULE=on tools/bin/unconvert ./... 125 126 gogenerate: 127 @echo "go generate ./..." 128 ./tools/check/check-gogenerate.sh 129 130 lint:tools/bin/revive 131 @echo "linting" 132 @tools/bin/revive -formatter friendly -config tools/check/revive.toml $(FILES) 133 134 vet: 135 @echo "vet" 136 $(GO) vet -all $(PACKAGES) 2>&1 | $(FAIL_ON_STDOUT) 137 138 staticcheck: 139 $(GO) get honnef.co/go/tools/cmd/staticcheck 140 $(STATICCHECK) ./... 141 142 tidy: 143 @echo "go mod tidy" 144 ./tools/check/check-tidy.sh 145 146 testSuite: 147 @echo "testSuite" 148 ./tools/check/check_testSuite.sh 149 150 clean: 151 $(GO) clean -i ./... 152 rm -rf *.out 153 rm -rf BerolinaSQL 154 155 # Split tests for CI to run `make test` in parallel. 156 test: test_part_1 test_part_2 157 @>&2 echo "Great, all tests passed." 158 159 test_part_1: checklist explaintest 160 161 test_part_2: checkdep gotest gogenerate 162 163 explaintest: server_check 164 @cd cmd/explaintest && ./run-tests.sh -s ../../bin/milevadb-server 165 166 dbstest: 167 @cd cmd/dbstest && $(GO) test -o ../../bin/dbstest -c 168 169 upload-coverage: SHELL:=/bin/bash 170 upload-coverage: 171 ifeq ("$(TRAVIS_COVERAGE)", "1") 172 mv overalls.coverprofile coverage.txt 173 bash <(curl -s https://codecov.io/bash) 174 endif 175 176 gotest: failpoint-enable 177 ifeq ("$(TRAVIS_COVERAGE)", "1") 178 @echo "Running in TRAVIS_COVERAGE mode." 179 $(GO) get github.com/go-playground/overalls 180 @export log_level=error; \ 181 $(OVERALLS) -project=github.com/whtcorpsinc/milevadb \ 182 -covermode=count \ 183 -ignore='.git,vendor,cmd,docs,LICENSES' \ 184 -concurrency=4 \ 185 -- -coverpkg=./... \ 186 || { $(FAILPOINT_DISABLE); exit 1; } 187 else 188 @echo "Running in native mode." 189 @export log_level=fatal; export TZ='Asia/Shanghai'; \ 190 $(GOTEST) -ldflags '$(TEST_LDFLAGS)' $(EXTRA_TEST_ARGS) -cover $(PACKAGES) -check.p true -check.timeout 4s || { $(FAILPOINT_DISABLE); exit 1; } 191 endif 192 @$(FAILPOINT_DISABLE) 193 194 race: failpoint-enable 195 @export log_level=debug; \ 196 $(GOTEST) -timeout 20m -race $(PACKAGES) || { $(FAILPOINT_DISABLE); exit 1; } 197 @$(FAILPOINT_DISABLE) 198 199 leak: failpoint-enable 200 @export log_level=debug; \ 201 $(GOTEST) -tags leak $(PACKAGES) || { $(FAILPOINT_DISABLE); exit 1; } 202 @$(FAILPOINT_DISABLE) 203 204 einsteindb_integration_test: failpoint-enable 205 $(GOTEST) ./causetstore/einsteindb/. -with-einsteindb=true || { $(FAILPOINT_DISABLE); exit 1; } 206 @$(FAILPOINT_DISABLE) 207 208 RACE_FLAG = 209 ifeq ("$(WITH_RACE)", "1") 210 RACE_FLAG = -race 211 GOBUILD = GOPATH=$(GOPATH) $(GO) build 212 endif 213 214 CHECK_FLAG = 215 ifeq ("$(WITH_CHECK)", "1") 216 CHECK_FLAG = $(TEST_LDFLAGS) 217 endif 218 219 server: 220 ifeq ($(TARGET), "") 221 CGO_ENABLED=1 $(GOBUILD) $(RACE_FLAG) -ldflags '$(LDFLAGS) $(CHECK_FLAG)' -o bin/milevadb-server milevadb-server/main.go 222 else 223 CGO_ENABLED=1 $(GOBUILD) $(RACE_FLAG) -ldflags '$(LDFLAGS) $(CHECK_FLAG)' -o '$(TARGET)' milevadb-server/main.go 224 endif 225 226 server_check: 227 ifeq ($(TARGET), "") 228 $(GOBUILD) $(RACE_FLAG) -ldflags '$(CHECK_LDFLAGS)' -o bin/milevadb-server milevadb-server/main.go 229 else 230 $(GOBUILD) $(RACE_FLAG) -ldflags '$(CHECK_LDFLAGS)' -o '$(TARGET)' milevadb-server/main.go 231 endif 232 233 linux: 234 ifeq ($(TARGET), "") 235 GOOS=linux $(GOBUILD) $(RACE_FLAG) -ldflags '$(LDFLAGS) $(CHECK_FLAG)' -o bin/milevadb-server-linux milevadb-server/main.go 236 else 237 GOOS=linux $(GOBUILD) $(RACE_FLAG) -ldflags '$(LDFLAGS) $(CHECK_FLAG)' -o '$(TARGET)' milevadb-server/main.go 238 endif 239 240 server_coverage: 241 ifeq ($(TARGET), "") 242 $(GOBUILDCOVERAGE) $(RACE_FLAG) -ldflags '$(LDFLAGS) $(COVERAGE_SERVER_LDFLAGS) $(CHECK_FLAG)' -o ../bin/milevadb-server-coverage 243 else 244 $(GOBUILDCOVERAGE) $(RACE_FLAG) -ldflags '$(LDFLAGS) $(COVERAGE_SERVER_LDFLAGS) $(CHECK_FLAG)' -o '$(TARGET)' 245 endif 246 247 benchekv: 248 $(GOBUILD) -ldflags '$(LDFLAGS)' -o bin/benchekv cmd/benchekv/main.go 249 250 benchraw: 251 $(GOBUILD) -ldflags '$(LDFLAGS)' -o bin/benchraw cmd/benchraw/main.go 252 253 benchdb: 254 $(GOBUILD) -ldflags '$(LDFLAGS)' -o bin/benchdb cmd/benchdb/main.go 255 256 importer: 257 $(GOBUILD) -ldflags '$(LDFLAGS)' -o bin/importer ./cmd/importer 258 259 checklist: 260 cat checklist.md 261 262 failpoint-enable: tools/bin/failpoint-ctl 263 # Converting gofail failpoints... 264 @$(FAILPOINT_ENABLE) 265 266 failpoint-disable: tools/bin/failpoint-ctl 267 # Restoring gofail failpoints... 268 @$(FAILPOINT_DISABLE) 269 270 checkdep: 271 $(GO) list -f '{{ join .Imports "\n" }}' github.com/whtcorpsinc/milevadb/causetstore/einsteindb | grep ^github.com/whtcorpsinc/BerolinaSQL$$ || exit 0; exit 1 272 273 tools/bin/megacheck: tools/check/go.mod 274 cd tools/check; \ 275 $(GO) build -o ../bin/megacheck honnef.co/go/tools/cmd/megacheck 276 277 tools/bin/revive: tools/check/go.mod 278 cd tools/check; \ 279 $(GO) build -o ../bin/revive github.com/mgechev/revive 280 281 tools/bin/goword: tools/check/go.mod 282 cd tools/check; \ 283 $(GO) build -o ../bin/goword github.com/chzchzchz/goword 284 285 tools/bin/gospacetimelinter: tools/check/go.mod 286 cd tools/check; \ 287 $(GO) build -o ../bin/gospacetimelinter gopkg.in/alecthomas/gospacetimelinter.v3 288 289 tools/bin/gosec: tools/check/go.mod 290 cd tools/check; \ 291 $(GO) build -o ../bin/gosec github.com/securego/gosec/cmd/gosec 292 293 tools/bin/errcheck: tools/check/go.mod 294 cd tools/check; \ 295 $(GO) build -o ../bin/errcheck github.com/kisielk/errcheck 296 297 tools/bin/unconvert: tools/check/go.mod 298 cd tools/check; \ 299 $(GO) build -o ../bin/unconvert github.com/mdempsky/unconvert 300 301 tools/bin/failpoint-ctl: go.mod 302 $(GO) build -o $@ github.com/whtcorpsinc/failpoint/failpoint-ctl 303 304 tools/bin/golangci-lint: 305 curl -sfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh| sh -s -- -b ./tools/bin v1.29.0 306 307 # Usage: 308 # 309 # $ make vectorized-bench VB_FILE=Time VB_FUNC=builtinCurrentDateSig 310 vectorized-bench: 311 cd ./memex && \ 312 go test -v -timeout=0 -benchmem \ 313 -bench=BenchmarkVectorizedBuiltin$(VB_FILE)Func \ 314 -run=BenchmarkVectorizedBuiltin$(VB_FILE)Func \ 315 -args "$(VB_FUNC)" 316 317 testpkg: failpoint-enable 318 ifeq ("$(pkg)", "") 319 @echo "Require pkg parameter" 320 else 321 @echo "Running unit test for github.com/whtcorpsinc/milevadb/$(pkg)" 322 @export log_level=fatal; export TZ='Asia/Shanghai'; \ 323 $(GOTEST) -ldflags '$(TEST_LDFLAGS)' -cover github.com/whtcorpsinc/milevadb/$(pkg) -check.p true -check.timeout 4s || { $(FAILPOINT_DISABLE); exit 1; } 324 endif 325 @$(FAILPOINT_DISABLE)