Makefile 14.5 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11
# Copyright (C) 2019-2020 Zilliz. All rights reserved.
#
# 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.

12 13
GO		  ?= go
PWD 	  := $(shell pwd)
E
Enwei Jiao 已提交
14 15
GOPATH	:= $(shell $(GO) env GOPATH)
SHELL 	:= /bin/bash
16
OBJPREFIX := "github.com/milvus-io/milvus/cmd/milvus"
17 18 19

INSTALL_PATH := $(PWD)/bin
LIBRARY_PATH := $(PWD)/lib
J
jaime 已提交
20 21 22
OS := $(shell uname -s)
ARCH := $(shell arch)
mode = Release
23
disk_index = OFF
24 25 26 27
useasan = false 
ifeq (${USE_ASAN}, true)
useasan = true 
endif
28

S
SimFG 已提交
29
export GIT_BRANCH=master
30

S
SimFG 已提交
31
milvus: build-cpp print-build-info
32 33 34 35
	@echo "Building Milvus ..."
	@source $(PWD)/scripts/setenv.sh && \
		mkdir -p $(INSTALL_PATH) && go env -w CGO_ENABLED="1" && \
		GO111MODULE=on $(GO) build -ldflags="-r $${RPATH} -X '$(OBJPREFIX).BuildTags=$(BUILD_TAGS)' -X '$(OBJPREFIX).BuildTime=$(BUILD_TIME)' -X '$(OBJPREFIX).GitCommit=$(GIT_COMMIT)' -X '$(OBJPREFIX).GoVersion=$(GO_VERSION)'" \
P
presburger 已提交
36
		${AARCH64_FLAG} -o $(INSTALL_PATH)/milvus $(PWD)/cmd/main.go 1>/dev/null
37 38 39 40

get-build-deps:
	@(env bash $(PWD)/scripts/install_deps.sh)

41
# attention: upgrade golangci-lint should also change Dockerfiles in build/docker/builder/cpu/<os>
42
getdeps:
43 44 45
	@mkdir -p $(INSTALL_PATH)
	@$(INSTALL_PATH)/golangci-lint --version 2>&1 1>/dev/null || (echo "Installing golangci-lint into ./bin/" && curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(INSTALL_PATH) v1.46.2)
	@$(INSTALL_PATH)/mockery --version 2>&1 1>/dev/null || (echo "Installing mockery v2.16.0 to ./bin/" && GOBIN=$(INSTALL_PATH)/ go install github.com/vektra/mockery/v2@v2.16.0)
46

47 48 49 50
tools/bin/revive: tools/check/go.mod
	cd tools/check; \
	$(GO) build -o ../bin/revive github.com/mgechev/revive

51 52
cppcheck:
	@(env bash ${PWD}/scripts/core_build.sh -l)
53

54
# put generate proto as a separated target because build cpp have different cases like with unittest.
E
Enwei Jiao 已提交
55
generated-proto-go-without-cpp: export protoc:=${PWD}/cmake_build/bin/protoc
56
generated-proto-go-without-cpp: 
57
	@mkdir -p ${GOPATH}/bin
58
	@which protoc-gen-go 1>/dev/null || (echo "Installing protoc-gen-go" && cd /tmp && go install github.com/golang/protobuf/protoc-gen-go@v1.3.2)
59 60
	@(env bash $(PWD)/scripts/proto_gen_go.sh)

61 62 63 64 65 66
generated-proto-go: build-cpp generated-proto-go-without-cpp

check-proto-product-only:
	 @(env bash $(PWD)/scripts/check_proto_product.sh)
check-proto-product: generated-proto-go check-proto-product-only
	
67

68
fmt:
69 70 71 72
ifdef GO_DIFF_FILES
	@echo "Running $@ check"
	@GO111MODULE=on env bash $(PWD)/scripts/gofmt.sh $(GO_DIFF_FILES)
else
73
	@echo "Running $@ check"
74 75
	@GO111MODULE=on env bash $(PWD)/scripts/gofmt.sh cmd/
	@GO111MODULE=on env bash $(PWD)/scripts/gofmt.sh internal/
76
	@GO111MODULE=on env bash $(PWD)/scripts/gofmt.sh tests/integration/
G
godchen 已提交
77
	@GO111MODULE=on env bash $(PWD)/scripts/gofmt.sh tests/go/
78
endif
79

80
lint: tools/bin/revive
81 82 83
	@echo "Running $@ check"
	@tools/bin/revive -formatter friendly -config tools/check/revive.toml ./...

84
#TODO: Check code specifications by golangci-lint
85
static-check: getdeps
86
	@echo "Running $@ check"
87 88 89
	@GO111MODULE=on $(INSTALL_PATH)/golangci-lint cache clean
	@source $(PWD)/scripts/setenv.sh && GO111MODULE=on $(INSTALL_PATH)/golangci-lint run --timeout=30m --config ./.golangci.yml ./internal/...
	@source $(PWD)/scripts/setenv.sh && GO111MODULE=on $(INSTALL_PATH)/golangci-lint run --timeout=30m --config ./.golangci.yml ./cmd/...
90
	@source $(PWD)/scripts/setenv.sh && GO111MODULE=on $(INSTALL_PATH)/golangci-lint run --timeout=30m --config ./.golangci.yml ./tests/integration/...
91

92
verifiers: build-cpp getdeps cppcheck fmt static-check
93

94
# Build various components locally.
C
Cai Yudong 已提交
95 96
binlog:
	@echo "Building binlog ..."
E
Enwei Jiao 已提交
97
	@source $(PWD)/scripts/setenv.sh && \
E
Enwei Jiao 已提交
98 99
		mkdir -p $(INSTALL_PATH) && go env -w CGO_ENABLED="1" && \
		GO111MODULE=on $(GO) build -ldflags="-r $${RPATH}" -o $(INSTALL_PATH)/binlog $(PWD)/cmd/tools/binlog/main.go 1>/dev/null
Z
zhenshan.cao 已提交
100

J
Jiquan Long 已提交
101
MIGRATION_PATH = $(PWD)/cmd/tools/migration
J
Jiquan Long 已提交
102
meta-migration:
J
Jiquan Long 已提交
103
	@echo "Building migration tool ..."
104 105 106
	@source $(PWD)/scripts/setenv.sh && \
    		mkdir -p $(INSTALL_PATH) && go env -w CGO_ENABLED="1" && \
    		GO111MODULE=on $(GO) build -ldflags="-r $${RPATH} -X '$(OBJPREFIX).BuildTags=$(BUILD_TAGS)' -X '$(OBJPREFIX).BuildTime=$(BUILD_TIME)' -X '$(OBJPREFIX).GitCommit=$(GIT_COMMIT)' -X '$(OBJPREFIX).GoVersion=$(GO_VERSION)'" \
P
presburger 已提交
107
    		${AARCH64_FLAG} -o $(INSTALL_PATH)/meta-migration $(MIGRATION_PATH)/main.go 1>/dev/null
J
Jiquan Long 已提交
108

109 110 111 112 113 114 115 116
INTERATION_PATH = $(PWD)/tests/integration
integration-test:
	@echo "Building integration tests ..."
	@source $(PWD)/scripts/setenv.sh && \
    		mkdir -p $(INSTALL_PATH) && go env -w CGO_ENABLED="1" && \
    		GO111MODULE=on $(GO) build -ldflags="-r $${RPATH} -X '$(OBJPREFIX).BuildTags=$(BUILD_TAGS)' -X '$(OBJPREFIX).BuildTime=$(BUILD_TIME)' -X '$(OBJPREFIX).GitCommit=$(GIT_COMMIT)' -X '$(OBJPREFIX).GoVersion=$(GO_VERSION)'" \
    		${APPLE_SILICON_FLAG} -o $(INSTALL_PATH)/integration-test $(INTERATION_PATH)/ 1>/dev/null

117
BUILD_TAGS = $(shell git describe --tags --always --dirty="-dev")
J
jaime 已提交
118
BUILD_TIME = $(shell date -u)
119 120
GIT_COMMIT = $(shell git rev-parse --short HEAD)
GO_VERSION = $(shell go version)
P
presburger 已提交
121

122
ifeq ($(ARCH),arm64)
P
presburger 已提交
123
	AARCH64_FLAG = -tags dynamic
124
endif
P
presburger 已提交
125 126 127

ifeq ($(ARCH),aarch64)
	AARCH64_FLAG = -tags dynamic
128
endif
129

D
dragondriver 已提交
130
print-build-info:
J
Jenny Li 已提交
131
	$(shell git config --global --add safe.directory '*')
D
dragondriver 已提交
132 133 134 135 136
	@echo "Build Tag: $(BUILD_TAGS)"
	@echo "Build Time: $(BUILD_TIME)"
	@echo "Git Commit: $(GIT_COMMIT)"
	@echo "Go Version: $(GO_VERSION)"

137

138

139 140
embd-milvus: build-cpp-embd print-build-info
	@echo "Building **Embedded** Milvus ..."
E
Enwei Jiao 已提交
141 142 143
	@source $(PWD)/scripts/setenv.sh && \
		mkdir -p $(INSTALL_PATH) && go env -w CGO_ENABLED="1" && \
		GO111MODULE=on $(GO) build -ldflags="-r /tmp/milvus/lib/ -X '$(OBJPREFIX).BuildTags=$(BUILD_TAGS)' -X '$(OBJPREFIX).BuildTime=$(BUILD_TIME)' -X '$(OBJPREFIX).GitCommit=$(GIT_COMMIT)' -X '$(OBJPREFIX).GoVersion=$(GO_VERSION)'" \
P
presburger 已提交
144
		${AARCH64_FLAG} -buildmode=c-shared -o $(INSTALL_PATH)/embd-milvus.so $(PWD)/pkg/embedded/embedded.go 1>/dev/null
145

146 147 148
update-milvus-api: download-milvus-proto
	@echo "Update milvus/api version ..."
	@(env bash $(PWD)/scripts/update-api-version.sh)
S
SimFG 已提交
149

S
SimFG 已提交
150 151 152
download-milvus-proto:
	@echo "Download milvus-proto repo ..."
	@(env bash $(PWD)/scripts/download_milvus_proto.sh)
153

S
SimFG 已提交
154
build-cpp: download-milvus-proto
155
	@echo "Building Milvus cpp library ..."
156
	@(env bash $(PWD)/scripts/core_build.sh -t ${mode} -f "$(CUSTOM_THIRDPARTY_PATH)" -n ${disk_index})
157

S
SimFG 已提交
158
build-cpp-embd: download-milvus-proto
159
	@echo "Building **Embedded** Milvus cpp library ..."
160
	@(env bash $(PWD)/scripts/core_build.sh -b -t ${mode} -f "$(CUSTOM_THIRDPARTY_PATH)" -n ${disk_index})
161

S
SimFG 已提交
162
build-cpp-with-unittest: download-milvus-proto
163
	@echo "Building Milvus cpp library with unittest ..."
164
	@(env bash $(PWD)/scripts/core_build.sh -t ${mode} -u -f "$(CUSTOM_THIRDPARTY_PATH)" -n ${disk_index})
165

S
SimFG 已提交
166
build-cpp-with-coverage: download-milvus-proto
167
	@echo "Building Milvus cpp library with coverage and unittest ..."
168
	@(env bash $(PWD)/scripts/core_build.sh -t ${mode} -u -a ${useasan} -c -f "$(CUSTOM_THIRDPARTY_PATH)" -n ${disk_index})
169 170


171
# Run the tests.
172
unittest: test-cpp test-go
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
test-util:
	@echo "Running go unittests..."
	@(env bash $(PWD)/scripts/run_go_unittest.sh -t util)

test-storage:
	@echo "Running go unittests..."
	@(env bash $(PWD)/scripts/run_go_unittest.sh -t storage)

test-allocator:
	@echo "Running go unittests..."
	@(env bash $(PWD)/scripts/run_go_unittest.sh -t allocator)

test-config:
	@echo "Running go unittests..."
	@(env bash $(PWD)/scripts/run_go_unittest.sh -t config)

test-tso:
	@echo "Running go unittests..."
	@(env bash $(PWD)/scripts/run_go_unittest.sh -t tso)

test-kv:
	@echo "Running go unittests..."
	@(env bash $(PWD)/scripts/run_go_unittest.sh -t kv)

test-mq:
	@echo "Running go unittests..."
	@(env bash $(PWD)/scripts/run_go_unittest.sh -t mq)

test-rootcoord:
	@echo "Running go unittests..."
	@(env bash $(PWD)/scripts/run_go_unittest.sh -t rootcoord)

206 207
test-indexnode:
	@echo "Running go unittests..."
208
	@(env bash $(PWD)/scripts/run_go_unittest.sh -t indexnode)
209

Z
zhenshan.cao 已提交
210 211 212 213
test-indexcoord:
	@echo "Running go unittests..."
	@(env bash $(PWD)/scripts/run_go_unittest.sh -t indexcoord)

Z
zhenshan.cao 已提交
214 215
test-proxy:
	@echo "Running go unittests..."
216
	@(env bash $(PWD)/scripts/run_go_unittest.sh -t proxy)
Z
zhenshan.cao 已提交
217

218 219
test-datacoord:
	@echo "Running go unittests..."
220
	@(env bash $(PWD)/scripts/run_go_unittest.sh -t datacoord)
221

222 223
test-datanode:
	@echo "Running go unittests..."
224
	@(env bash $(PWD)/scripts/run_go_unittest.sh -t datanode)
Z
zhenshan.cao 已提交
225

226 227
test-querynode:
	@echo "Running go unittests..."
228
	@(env bash $(PWD)/scripts/run_go_unittest.sh -t querynode)
229

B
bigsheeper 已提交
230 231
test-querycoord:
	@echo "Running go unittests..."
232
	@(env bash $(PWD)/scripts/run_go_unittest.sh -t querycoord)
B
bigsheeper 已提交
233

234 235 236
test-metastore:
	@echo "Running go unittests..."
	@(env bash $(PWD)/scripts/run_go_unittest.sh -t metastore)
B
bigsheeper 已提交
237

238
test-go: build-cpp-with-unittest
239
	@echo "Running go unittests..."
240
	@(env bash $(PWD)/scripts/run_go_unittest.sh)
241 242

test-cpp: build-cpp-with-unittest
C
cai.zhang 已提交
243
	@echo "Running cpp unittests..."
244
	@(env bash $(PWD)/scripts/run_cpp_unittest.sh)
245

246
# Run code coverage.
G
groot 已提交
247
codecov: codecov-go codecov-cpp
G
groot 已提交
248

G
groot 已提交
249
# Run codecov-go
250
codecov-go: build-cpp-with-coverage
G
groot 已提交
251
	@echo "Running go coverage..."
252 253
	@(env bash $(PWD)/scripts/run_go_codecov.sh)

G
groot 已提交
254
# Run codecov-cpp
255
codecov-cpp: build-cpp-with-coverage
G
groot 已提交
256
	@echo "Running cpp coverage..."
257 258
	@(env bash $(PWD)/scripts/run_cpp_codecov.sh)

259 260 261 262
# Package docker image locally.
# TODO: fix error occur at starting up
docker: install
	./build/build_image.sh
263

264
# Build each component and install binary to $GOPATH/bin.
265
install: milvus
266
	@echo "Installing binary to './bin'"
267
	@mkdir -p $(GOPATH)/bin && cp -f $(PWD)/bin/milvus $(GOPATH)/bin/milvus
J
Jenny Li 已提交
268
	@mkdir -p $(LIBRARY_PATH)
269 270 271
	-cp -r -P $(PWD)/internal/core/output/lib/*.dylib* $(LIBRARY_PATH) 2>/dev/null
	-cp -r -P $(PWD)/internal/core/output/lib/*.so* $(LIBRARY_PATH) 2>/dev/null
	-cp -r -P $(PWD)/internal/core/output/lib64/*.so* $(LIBRARY_PATH) 2>/dev/null
272 273 274 275 276 277
	@echo "Installation successful."

clean:
	@echo "Cleaning up all the generated files"
	@find . -name '*.test' | xargs rm -fv
	@find . -name '*~' | xargs rm -fv
278 279
	@rm -rf bin/
	@rm -rf lib/
X
Xiaofan 已提交
280
	@rm -rf $(GOPATH)/bin/milvus
281 282
	@rm -rf cmake_build
	@rm -rf cwrapper_build
J
jaime 已提交
283
	@rm -rf internal/core/output
284

D
dragondriver 已提交
285
milvus-tools: print-build-info
286 287 288 289
	@echo "Building tools ..."
	@mkdir -p $(INSTALL_PATH)/tools && go env -w CGO_ENABLED="1" && GO111MODULE=on $(GO) build \
		-ldflags="-X 'main.BuildTags=$(BUILD_TAGS)' -X 'main.BuildTime=$(BUILD_TIME)' -X 'main.GitCommit=$(GIT_COMMIT)' -X 'main.GoVersion=$(GO_VERSION)'" \
		-o $(INSTALL_PATH)/tools $(PWD)/cmd/tools/* 1>/dev/null
S
shaoyue 已提交
290

291
rpm-setup:
S
shaoyue 已提交
292
	@echo "Setuping rpm env ...;"
293
	@build/rpm/setup-env.sh
S
shaoyue 已提交
294 295 296 297 298 299 300 301 302 303 304 305 306 307

rpm: install
	@echo "Note: run 'make rpm-setup' to setup build env for rpm builder"
	@echo "Building rpm ...;"
	@yum -y install rpm-build rpmdevtools wget
	@rm -rf ~/rpmbuild/BUILD/*
	@rpmdev-setuptree
	@wget https://github.com/etcd-io/etcd/releases/download/v3.5.0/etcd-v3.5.0-linux-amd64.tar.gz && tar -xf etcd-v3.5.0-linux-amd64.tar.gz
	@cp etcd-v3.5.0-linux-amd64/etcd bin/etcd
	@wget https://dl.min.io/server/minio/release/linux-amd64/archive/minio.RELEASE.2021-02-14T04-01-33Z -O bin/minio
	@cp -r bin ~/rpmbuild/BUILD/
	@cp -r lib ~/rpmbuild/BUILD/
	@cp -r configs ~/rpmbuild/BUILD/
	@cp -r build/rpm/services ~/rpmbuild/BUILD/
308
	@QA_RPATHS="$$[ 0x001|0x0002|0x0020 ]" rpmbuild -ba ./build/rpm/milvus.spec
309 310 311 312

mock-datanode:
	mockery --name=DataNode --dir=$(PWD)/internal/types --output=$(PWD)/internal/mocks --filename=mock_datanode.go --with-expecter

313 314 315
mock-rootcoord:
	mockery --name=RootCoord --dir=$(PWD)/internal/types --output=$(PWD)/internal/mocks --filename=mock_rootcoord.go --with-expecter

316 317 318
mock-datacoord:
	mockery --name=DataCoord --dir=$(PWD)/internal/types --output=$(PWD)/internal/mocks --filename=mock_datacoord.go --with-expecter

319 320
mock-tnx-kv:
	mockery --name=TxnKV --dir=$(PWD)/internal/kv --output=$(PWD)/internal/kv/mocks --filename=TxnKV.go --with-expecter
321

322 323 324 325 326 327 328 329
generate-mockery: getdeps
	# internal/querycoordv2
	$(PWD)/bin/mockery --name=QueryNodeServer --dir=$(PWD)/internal/proto/querypb/ --output=$(PWD)/internal/querycoordv2/mocks --filename=mock_querynode.go --with-expecter --structname=MockQueryNodeServer 
	$(PWD)/bin/mockery --name=Broker --dir=$(PWD)/internal/querycoordv2/meta --output=$(PWD)/internal/querycoordv2/meta --filename=mock_broker.go --with-expecter --structname=MockBroker --outpkg=meta 
	$(PWD)/bin/mockery --name=Scheduler --dir=$(PWD)/internal/querycoordv2/task --output=$(PWD)/internal/querycoordv2/task --filename=mock_scheduler.go --with-expecter --structname=MockScheduler --outpkg=task --inpackage 
	$(PWD)/bin/mockery --name=Cluster --dir=$(PWD)/internal/querycoordv2/session --output=$(PWD)/internal/querycoordv2/session --filename=mock_cluster.go --with-expecter --structname=MockCluster --outpkg=session --inpackage 
	$(PWD)/bin/mockery --name=Store --dir=$(PWD)/internal/querycoordv2/meta --output=$(PWD)/internal/querycoordv2/meta --filename=mock_store.go --with-expecter --structname=MockStore --outpkg=meta --inpackage
	$(PWD)/bin/mockery --name=Balance --dir=$(PWD)/internal/querycoordv2/balance --output=$(PWD)/internal/querycoordv2/balance --filename=mock_balancer.go --with-expecter --structname=MockBalancer --outpkg=balance --inpackage
330
		$(PWD)/bin/mockery --name=Controller --dir=$(PWD)/internal/querycoordv2/dist --output=$(PWD)/internal/querycoordv2/dist --filename=mock_controller.go --with-expecter --structname=MockController --outpkg=dist --inpackage
331 332 333 334 335
	# internal/querynode
	$(PWD)/bin/mockery --name=TSafeReplicaInterface --dir=$(PWD)/internal/querynode --output=$(PWD)/internal/querynode --filename=mock_tsafe_replica_test.go --with-expecter --structname=MockTSafeReplicaInterface --outpkg=querynode --inpackage
	# internal/rootcoord
	$(PWD)/bin/mockery --name=IMetaTable --dir=$(PWD)/internal/rootcoord --output=$(PWD)/internal/rootcoord/mocks --filename=meta_table.go --with-expecter --outpkg=mockrootcoord
	$(PWD)/bin/mockery --name=GarbageCollector --dir=$(PWD)/internal/rootcoord --output=$(PWD)/internal/rootcoord/mocks --filename=garbage_collector.go --with-expecter --outpkg=mockrootcoord
W
wei liu 已提交
336 337
	#internal/types
	$(PWD)/bin/mockery --name=QueryCoordComponent --dir=$(PWD)/internal/types --output=$(PWD)/internal/types --filename=mock_querycoord.go --with-expecter --structname=MockQueryCoord --outpkg=types --inpackage
338
ci-ut: build-cpp-with-coverage generated-proto-go-without-cpp codecov-cpp codecov-go