Makefile 6.4 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
# 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.

GO		?= go
PWD 	:= $(shell pwd)
GOPATH 	:= $(shell $(GO) env GOPATH)

INSTALL_PATH := $(PWD)/bin
LIBRARY_PATH := $(PWD)/lib

C
cai.zhang 已提交
19
all: build-cpp build-go
20 21 22 23

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

24
# attention: upgrade golangci-lint should also change Dockerfiles in build/docker/builder/cpu/<os>
25 26
getdeps:
	@mkdir -p ${GOPATH}/bin
27
	@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.43.0)
C
cai.zhang 已提交
28
	@which ruleguard 1>/dev/null || (echo "Installing ruleguard" && go get github.com/quasilyte/go-ruleguard/cmd/ruleguard@v0.2.1)
29

30 31 32 33
tools/bin/revive: tools/check/go.mod
	cd tools/check; \
	$(GO) build -o ../bin/revive github.com/mgechev/revive

34 35
cppcheck:
	@(env bash ${PWD}/scripts/core_build.sh -l)
36

37
generated-proto-go: export protoc:=${PWD}/cmake_build/thirdparty/protobuf/protobuf-build/protoc
38
generated-proto-go: build-cpp
39 40
	@mkdir -p ${GOPATH}/bin
	@which protoc-gen-go 1>/dev/null || (echo "Installing protoc-gen-go" && go get github.com/golang/protobuf/protoc-gen-go@v1.3.2)
41 42 43 44 45
	@(env bash $(PWD)/scripts/proto_gen_go.sh)

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

46
fmt:
47 48 49 50
ifdef GO_DIFF_FILES
	@echo "Running $@ check"
	@GO111MODULE=on env bash $(PWD)/scripts/gofmt.sh $(GO_DIFF_FILES)
else
51
	@echo "Running $@ check"
52 53
	@GO111MODULE=on env bash $(PWD)/scripts/gofmt.sh cmd/
	@GO111MODULE=on env bash $(PWD)/scripts/gofmt.sh internal/
G
godchen 已提交
54
	@GO111MODULE=on env bash $(PWD)/scripts/gofmt.sh tests/go/
55
endif
56

57
lint: tools/bin/revive
58 59 60
	@echo "Running $@ check"
	@tools/bin/revive -formatter friendly -config tools/check/revive.toml ./...

61
#TODO: Check code specifications by golangci-lint
X
XuanYang-cn 已提交
62
static-check:
63 64
	@echo "Running $@ check"
	@GO111MODULE=on ${GOPATH}/bin/golangci-lint cache clean
X
XuanYang-cn 已提交
65 66
	@GO111MODULE=on ${GOPATH}/bin/golangci-lint run --timeout=30m --config ./.golangci.yml ./internal/...
	@GO111MODULE=on ${GOPATH}/bin/golangci-lint run --timeout=30m --config ./.golangci.yml ./cmd/...
67
#	@GO111MODULE=on ${GOPATH}/bin/golangci-lint run --timeout=30m --config ./.golangci.yml ./tests/go_client/...
68

C
cai.zhang 已提交
69
ruleguard:
70 71 72 73
ifdef GO_DIFF_FILES
	@echo "Running $@ check"
	@${GOPATH}/bin/ruleguard -rules ruleguard.rules.go $(GO_DIFF_FILES)
else
C
cai.zhang 已提交
74
	@echo "Running $@ check"
C
cai.zhang 已提交
75 76
	@${GOPATH}/bin/ruleguard -rules ruleguard.rules.go ./internal/...
	@${GOPATH}/bin/ruleguard -rules ruleguard.rules.go ./cmd/...
77
#	@${GOPATH}/bin/ruleguard -rules ruleguard.rules.go ./tests/go/...
78
endif
C
cai.zhang 已提交
79

80
verifiers: build-cpp getdeps cppcheck fmt static-check ruleguard
81

82
# Build various components locally.
C
Cai Yudong 已提交
83 84
binlog:
	@echo "Building binlog ..."
85
	@mkdir -p $(INSTALL_PATH) && go env -w CGO_ENABLED="1" && GO111MODULE=on $(GO) build -o $(INSTALL_PATH)/binlog $(PWD)/cmd/tools/binlog/main.go 1>/dev/null
Z
zhenshan.cao 已提交
86

87
BUILD_TAGS = $(shell git describe --tags --always --dirty="-dev")
C
Cai Yudong 已提交
88
BUILD_TIME = $(shell date --utc)
89 90 91
GIT_COMMIT = $(shell git rev-parse --short HEAD)
GO_VERSION = $(shell go version)

92
milvus: build-cpp
93
	@echo "Building Milvus ..."
94 95 96
	@mkdir -p $(INSTALL_PATH) && 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)/milvus $(PWD)/cmd/main.go 1>/dev/null
97

98
build-go: milvus
N
neza2017 已提交
99

100
build-cpp:
101
	@echo "Building Milvus cpp library ..."
102 103
	@(env bash $(PWD)/scripts/core_build.sh -f "$(CUSTOM_THIRDPARTY_PATH)")
	@(env bash $(PWD)/scripts/cwrapper_build.sh -t Release -f "$(CUSTOM_THIRDPARTY_PATH)")
X
XuanYang-cn 已提交
104
	@(env bash $(PWD)/scripts/cwrapper_rocksdb_build.sh -t Release -f "$(CUSTOM_THIRDPARTY_PATH)")
105 106

build-cpp-with-unittest:
107
	@echo "Building Milvus cpp library with unittest ..."
G
groot 已提交
108
	@(env bash $(PWD)/scripts/core_build.sh -u -c -f "$(CUSTOM_THIRDPARTY_PATH)")
109
	@(env bash $(PWD)/scripts/cwrapper_build.sh -t Release -f "$(CUSTOM_THIRDPARTY_PATH)")
110
	@(env bash $(PWD)/scripts/cwrapper_rocksdb_build.sh -t Release -f "$(CUSTOM_THIRDPARTY_PATH)")
111

112
# Run the tests.
113
unittest: test-cpp test-go
114

Z
zhenshan.cao 已提交
115 116 117 118 119
test-proxy:
	@echo "Running go unittests..."
	go test -race -coverpkg=./... -coverprofile=profile.out -covermode=atomic -timeout 5m github.com/milvus-io/milvus/internal/proxy -v


B
bigsheeper 已提交
120 121 122 123 124
test-querycoord:
	@echo "Running go unittests..."
	go test -race -coverpkg=./... -coverprofile=profile.out -covermode=atomic -timeout 5m github.com/milvus-io/milvus/internal/querycoord	-v


125
test-go: build-cpp-with-unittest
126
	@echo "Running go unittests..."
127
	@(env bash $(PWD)/scripts/run_go_unittest.sh)
128 129

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

133
# Run code coverage.
G
groot 已提交
134
codecov: codecov-go codecov-cpp
G
groot 已提交
135

G
groot 已提交
136 137
# Run codecov-go
codecov-go: build-cpp-with-unittest
G
groot 已提交
138
	@echo "Running go coverage..."
139 140
	@(env bash $(PWD)/scripts/run_go_codecov.sh)

G
groot 已提交
141 142
# Run codecov-cpp
codecov-cpp: build-cpp-with-unittest
G
groot 已提交
143
	@echo "Running cpp coverage..."
144 145
	@(env bash $(PWD)/scripts/run_cpp_codecov.sh)

146 147 148 149
# Package docker image locally.
# TODO: fix error occur at starting up
docker: install
	./build/build_image.sh
150

151
# Build each component and install binary to $GOPATH/bin.
152 153
install: all
	@echo "Installing binary to './bin'"
154
	@mkdir -p $(GOPATH)/bin && cp -f $(PWD)/bin/milvus $(GOPATH)/bin/milvus
155
	@mkdir -p $(LIBRARY_PATH) && cp -P $(PWD)/internal/core/output/lib/* $(LIBRARY_PATH)
156 157 158 159 160 161
	@echo "Installation successful."

clean:
	@echo "Cleaning up all the generated files"
	@find . -name '*.test' | xargs rm -fv
	@find . -name '*~' | xargs rm -fv
162 163
	@rm -rf bin/
	@rm -rf lib/
X
Xiaofan 已提交
164
	@rm -rf $(GOPATH)/bin/milvus
165 166 167 168 169 170

milvus-tools: 
	@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