Makefile 5.7 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 25 26
getdeps:
	@mkdir -p ${GOPATH}/bin
	@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.27.0)
C
cai.zhang 已提交
27
	@which ruleguard 1>/dev/null || (echo "Installing ruleguard" && go get github.com/quasilyte/go-ruleguard/cmd/ruleguard@v0.2.1)
28

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

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

36
generated-proto-go: export protoc:=${PWD}/cmake_build/thirdparty/protobuf/protobuf-build/protoc
37
generated-proto-go: build-cpp
38 39
	@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)
40 41 42 43 44
	@(env bash $(PWD)/scripts/proto_gen_go.sh)

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

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

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

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

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

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

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

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

91
milvus: build-cpp
92
	@echo "Building Milvus ..."
93 94 95
	@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
96

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

99
build-cpp:
100
	@echo "Building Milvus cpp library ..."
101 102
	@(env bash $(PWD)/scripts/core_build.sh -f "$(CUSTOM_THIRDPARTY_PATH)")
	@(env bash $(PWD)/scripts/cwrapper_build.sh -t Release -f "$(CUSTOM_THIRDPARTY_PATH)")
Y
yukun 已提交
103
	@(env bash $(PWD)/scripts/cwrapper_dablooms_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 ..."
108 109
	@(env bash $(PWD)/scripts/core_build.sh -u -f "$(CUSTOM_THIRDPARTY_PATH)")
	@(env bash $(PWD)/scripts/cwrapper_build.sh -t Release -f "$(CUSTOM_THIRDPARTY_PATH)")
110 111

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

114
test-go: build-cpp-with-unittest
115
	@echo "Running go unittests..."
116 117
	@(env bash $(PWD)/scripts/run_go_codecov.sh)
# 	@(env bash $(PWD)/scripts/run_go_unittest.sh)
118 119

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

123 124 125 126 127
# Run go-codecov
go-codecov:
	@echo "Running go unittests..."
	@(env bash $(PWD)/scripts/run_go_codecov.sh)

128 129 130 131 132 133
#TODO: build each component to docker
docker: verifiers

# Builds each component and installs it to $GOPATH/bin.
install: all
	@echo "Installing binary to './bin'"
134
	@mkdir -p $(GOPATH)/bin && cp -f $(PWD)/bin/milvus $(GOPATH)/bin/milvus
135
	@mkdir -p $(LIBRARY_PATH) && cp -P $(PWD)/internal/core/output/lib/* $(LIBRARY_PATH)
136 137 138 139 140 141
	@echo "Installation successful."

clean:
	@echo "Cleaning up all the generated files"
	@find . -name '*.test' | xargs rm -fv
	@find . -name '*~' | xargs rm -fv
142 143
	@rm -rf bin/
	@rm -rf lib/
N
neza2017 已提交
144
	@rm $(GOPATH)/bin/milvus
145 146 147 148 149 150

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