Makefile 10.3 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

S
SimFG 已提交
25
export GIT_BRANCH=master
26

S
SimFG 已提交
27
milvus: build-cpp print-build-info
28 29 30 31 32
	@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)'" \
		${APPLE_SILICON_FLAG} -o $(INSTALL_PATH)/milvus $(PWD)/cmd/main.go 1>/dev/null
33 34 35 36

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

37
# attention: upgrade golangci-lint should also change Dockerfiles in build/docker/builder/cpu/<os>
38 39
getdeps:
	@mkdir -p ${GOPATH}/bin
E
Enwei Jiao 已提交
40
	@which golangci-lint 1>/dev/null || (echo "Installing golangci-lint" && curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(GOPATH)/bin v1.46.2)
41

42 43 44 45
tools/bin/revive: tools/check/go.mod
	cd tools/check; \
	$(GO) build -o ../bin/revive github.com/mgechev/revive

46 47
cppcheck:
	@(env bash ${PWD}/scripts/core_build.sh -l)
48

49
generated-proto-go: export protoc:=${PWD}/cmake_build/thirdparty/protobuf/protobuf-build/protoc
50
generated-proto-go: build-cpp
51
	@mkdir -p ${GOPATH}/bin
52
	@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)
53 54 55 56 57
	@(env bash $(PWD)/scripts/proto_gen_go.sh)

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

58
fmt:
59 60 61 62
ifdef GO_DIFF_FILES
	@echo "Running $@ check"
	@GO111MODULE=on env bash $(PWD)/scripts/gofmt.sh $(GO_DIFF_FILES)
else
63
	@echo "Running $@ check"
64 65
	@GO111MODULE=on env bash $(PWD)/scripts/gofmt.sh cmd/
	@GO111MODULE=on env bash $(PWD)/scripts/gofmt.sh internal/
G
godchen 已提交
66
	@GO111MODULE=on env bash $(PWD)/scripts/gofmt.sh tests/go/
67
endif
68

69
lint: tools/bin/revive
70 71 72
	@echo "Running $@ check"
	@tools/bin/revive -formatter friendly -config tools/check/revive.toml ./...

73
#TODO: Check code specifications by golangci-lint
S
SimFG 已提交
74
static-check:
75 76
	@echo "Running $@ check"
	@GO111MODULE=on ${GOPATH}/bin/golangci-lint cache clean
E
Enwei Jiao 已提交
77 78
	@source $(PWD)/scripts/setenv.sh && GO111MODULE=on ${GOPATH}/bin/golangci-lint run --timeout=30m --config ./.golangci.yml ./internal/...
	@source $(PWD)/scripts/setenv.sh && GO111MODULE=on ${GOPATH}/bin/golangci-lint run --timeout=30m --config ./.golangci.yml ./cmd/...
79
#	@GO111MODULE=on ${GOPATH}/bin/golangci-lint run --timeout=30m --config ./.golangci.yml ./tests/go_client/...
80

81
verifiers: build-cpp getdeps cppcheck fmt static-check
82

83
# Build various components locally.
C
Cai Yudong 已提交
84 85
binlog:
	@echo "Building binlog ..."
E
Enwei Jiao 已提交
86
	@source $(PWD)/scripts/setenv.sh && \
E
Enwei Jiao 已提交
87 88
		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 已提交
89

J
Jiquan Long 已提交
90
MIGRATION_PATH = $(PWD)/cmd/tools/migration
J
Jiquan Long 已提交
91
meta-migration:
J
Jiquan Long 已提交
92
	@echo "Building migration tool ..."
93
	@mkdir -p $(INSTALL_PATH) && go env -w CGO_ENABLED="1" && GO111MODULE=on $(GO) build -o $(INSTALL_PATH)/meta-migration $(MIGRATION_PATH)/main.go 1>/dev/null
J
Jiquan Long 已提交
94

95
BUILD_TAGS = $(shell git describe --tags --always --dirty="-dev")
J
jaime 已提交
96
BUILD_TIME = $(shell date -u)
97 98
GIT_COMMIT = $(shell git rev-parse --short HEAD)
GO_VERSION = $(shell go version)
99 100 101 102 103
ifeq ($(OS),Darwin)
ifeq ($(ARCH),arm64)
	APPLE_SILICON_FLAG = -tags dynamic
endif
endif
104

D
dragondriver 已提交
105
print-build-info:
J
Jenny Li 已提交
106
	$(shell git config --global --add safe.directory '*')
D
dragondriver 已提交
107 108 109 110 111
	@echo "Build Tag: $(BUILD_TAGS)"
	@echo "Build Time: $(BUILD_TIME)"
	@echo "Git Commit: $(GIT_COMMIT)"
	@echo "Go Version: $(GO_VERSION)"

112

113

114 115
embd-milvus: build-cpp-embd print-build-info
	@echo "Building **Embedded** Milvus ..."
E
Enwei Jiao 已提交
116 117 118
	@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)'" \
119
		${APPLE_SILICON_FLAG} -buildmode=c-shared -o $(INSTALL_PATH)/embd-milvus.so $(PWD)/pkg/embedded/embedded.go 1>/dev/null
120

121 122 123
update-milvus-api: download-milvus-proto
	@echo "Update milvus/api version ..."
	@(env bash $(PWD)/scripts/update-api-version.sh)
S
SimFG 已提交
124

S
SimFG 已提交
125 126 127
download-milvus-proto:
	@echo "Download milvus-proto repo ..."
	@(env bash $(PWD)/scripts/download_milvus_proto.sh)
128

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

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

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

S
SimFG 已提交
141
build-cpp-with-coverage: download-milvus-proto
142
	@echo "Building Milvus cpp library with coverage and unittest ..."
143
	@(env bash $(PWD)/scripts/core_build.sh -t ${mode} -u -c -f "$(CUSTOM_THIRDPARTY_PATH)" -n ${disk_index})
144 145


146
# Run the tests.
147
unittest: test-cpp test-go
148

149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180
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)

181 182
test-indexnode:
	@echo "Running go unittests..."
183
	@(env bash $(PWD)/scripts/run_go_unittest.sh -t indexnode)
184

Z
zhenshan.cao 已提交
185 186 187 188
test-indexcoord:
	@echo "Running go unittests..."
	@(env bash $(PWD)/scripts/run_go_unittest.sh -t indexcoord)

Z
zhenshan.cao 已提交
189 190
test-proxy:
	@echo "Running go unittests..."
191
	@(env bash $(PWD)/scripts/run_go_unittest.sh -t proxy)
Z
zhenshan.cao 已提交
192

193 194
test-datacoord:
	@echo "Running go unittests..."
195
	@(env bash $(PWD)/scripts/run_go_unittest.sh -t datacoord)
196

197 198
test-datanode:
	@echo "Running go unittests..."
199
	@(env bash $(PWD)/scripts/run_go_unittest.sh -t datanode)
Z
zhenshan.cao 已提交
200

201 202
test-querynode:
	@echo "Running go unittests..."
203
	@(env bash $(PWD)/scripts/run_go_unittest.sh -t querynode)
204

B
bigsheeper 已提交
205 206
test-querycoord:
	@echo "Running go unittests..."
207
	@(env bash $(PWD)/scripts/run_go_unittest.sh -t querycoord)
B
bigsheeper 已提交
208

209 210 211
test-metastore:
	@echo "Running go unittests..."
	@(env bash $(PWD)/scripts/run_go_unittest.sh -t metastore)
B
bigsheeper 已提交
212

213
test-go: build-cpp-with-unittest
214
	@echo "Running go unittests..."
215
	@(env bash $(PWD)/scripts/run_go_unittest.sh)
216 217

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

221
# Run code coverage.
G
groot 已提交
222
codecov: codecov-go codecov-cpp
G
groot 已提交
223

G
groot 已提交
224
# Run codecov-go
225
codecov-go: build-cpp-with-coverage
G
groot 已提交
226
	@echo "Running go coverage..."
227 228
	@(env bash $(PWD)/scripts/run_go_codecov.sh)

G
groot 已提交
229
# Run codecov-cpp
230
codecov-cpp: build-cpp-with-coverage
G
groot 已提交
231
	@echo "Running cpp coverage..."
232 233
	@(env bash $(PWD)/scripts/run_cpp_codecov.sh)

234 235 236 237
# Package docker image locally.
# TODO: fix error occur at starting up
docker: install
	./build/build_image.sh
238

239
# Build each component and install binary to $GOPATH/bin.
240
install: milvus
241
	@echo "Installing binary to './bin'"
242
	@mkdir -p $(GOPATH)/bin && cp -f $(PWD)/bin/milvus $(GOPATH)/bin/milvus
J
Jenny Li 已提交
243 244 245 246 247 248
	@mkdir -p $(LIBRARY_PATH)
ifeq ($(OS),Darwin)
	@cp -r -P $(PWD)/internal/core/output/lib/*.dylib* $(LIBRARY_PATH)
else
	@cp -r -P $(PWD)/internal/core/output/lib/*.so* $(LIBRARY_PATH)
endif
249 250 251 252 253 254
	@echo "Installation successful."

clean:
	@echo "Cleaning up all the generated files"
	@find . -name '*.test' | xargs rm -fv
	@find . -name '*~' | xargs rm -fv
255 256
	@rm -rf bin/
	@rm -rf lib/
X
Xiaofan 已提交
257
	@rm -rf $(GOPATH)/bin/milvus
258 259
	@rm -rf cmake_build
	@rm -rf cwrapper_build
J
jaime 已提交
260
	@rm -rf internal/core/output
261

D
dragondriver 已提交
262
milvus-tools: print-build-info
263 264 265 266
	@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 已提交
267

268
rpm-setup:
S
shaoyue 已提交
269
	@echo "Setuping rpm env ...;"
270
	@build/rpm/setup-env.sh
S
shaoyue 已提交
271 272 273 274 275 276 277 278 279 280 281 282 283 284

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/
285
	@QA_RPATHS="$$[ 0x001|0x0002|0x0020 ]" rpmbuild -ba ./build/rpm/milvus.spec
286 287 288 289 290 291

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

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