Makefile 5.5 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 27 28
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)
	@which ruleguard 1>/dev/null || (echo "Installing ruleguard" && GO111MODULE=off go get github.com/quasilyte/go-ruleguard/...)

29 30
cppcheck:
	@(env bash ${PWD}/scripts/core_build.sh -l)
31 32 33

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

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

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

#TODO: Check code specifications by golangci-lint
X
xige-16 已提交
53
lint:
54 55
	@echo "Running $@ check"
	@GO111MODULE=on ${GOPATH}/bin/golangci-lint cache clean
X
XuanYang-cn 已提交
56 57 58
	@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/...
	@GO111MODULE=on ${GOPATH}/bin/golangci-lint run --timeout=30m --config ./.golangci.yml ./tests/go/...
59

C
cai.zhang 已提交
60
ruleguard:
61 62 63 64
ifdef GO_DIFF_FILES
	@echo "Running $@ check"
	@${GOPATH}/bin/ruleguard -rules ruleguard.rules.go $(GO_DIFF_FILES)
else
C
cai.zhang 已提交
65
	@echo "Running $@ check"
C
cai.zhang 已提交
66 67
	@${GOPATH}/bin/ruleguard -rules ruleguard.rules.go ./internal/...
	@${GOPATH}/bin/ruleguard -rules ruleguard.rules.go ./cmd/...
G
godchen 已提交
68
	@${GOPATH}/bin/ruleguard -rules ruleguard.rules.go ./tests/go/...
69
endif
C
cai.zhang 已提交
70

X
xige-16 已提交
71
verifiers: getdeps cppcheck fmt lint ruleguard
72 73

# Builds various components locally.
F
FluorineDog 已提交
74
build-go: build-cpp
75
	@echo "Building each component's binary to './bin'"
76
	@echo "Building master ..."
77
	@mkdir -p $(INSTALL_PATH) && go env -w CGO_ENABLED="0" && GO111MODULE=on $(GO) build -o $(INSTALL_PATH)/master $(PWD)/cmd/master/main.go 1>/dev/null
78
	@echo "Building proxy ..."
79
	@mkdir -p $(INSTALL_PATH) && go env -w CGO_ENABLED="0" && GO111MODULE=on $(GO) build -o $(INSTALL_PATH)/proxy $(PWD)/cmd/proxy/proxy.go 1>/dev/null
Z
zhenshan.cao 已提交
80 81
	@echo "Building query node ..."
	@mkdir -p $(INSTALL_PATH) && go env -w CGO_ENABLED="1" && GO111MODULE=on $(GO) build -o $(INSTALL_PATH)/querynode $(PWD)/cmd/querynode/query_node.go 1>/dev/null
Z
zhenshan.cao 已提交
82 83
	@echo "Building indexbuilder ..."
	@mkdir -p $(INSTALL_PATH) && go env -w CGO_ENABLED="1" && GO111MODULE=on $(GO) build -o $(INSTALL_PATH)/indexbuilder $(PWD)/cmd/indexbuilder/indexbuilder.go 1>/dev/null
X
XuanYang-cn 已提交
84 85
	@echo "Building write node ..."
	@mkdir -p $(INSTALL_PATH) && go env -w CGO_ENABLED="1" && GO111MODULE=on $(GO) build -o $(INSTALL_PATH)/writenode $(PWD)/cmd/writenode/writenode.go 1>/dev/null
N
neza2017 已提交
86 87
	@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
88 89

build-cpp:
90 91
	@(env bash $(PWD)/scripts/core_build.sh -f "$(CUSTOM_THIRDPARTY_PATH)")
	@(env bash $(PWD)/scripts/cwrapper_build.sh -t Release -f "$(CUSTOM_THIRDPARTY_PATH)")
92 93

build-cpp-with-unittest:
94 95
	@(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)")
96 97

# Runs the tests.
98
unittest: test-cpp test-go
99

N
neza2017 已提交
100
#TODO: proxy master query node writer's unittest
C
cai.zhang 已提交
101
test-go:
102 103 104 105
	@echo "Running go unittests..."
	@(env bash $(PWD)/scripts/run_go_unittest.sh)

test-cpp: build-cpp-with-unittest
C
cai.zhang 已提交
106
	@echo "Running cpp unittests..."
107 108 109 110
	@(env bash $(PWD)/scripts/run_cpp_unittest.sh)

#TODO: build each component to docker
docker: verifiers
N
neza2017 已提交
111
	@echo "Building query node docker image '$(TAG)'"
112 113 114 115 116 117
	@echo "Building proxy docker image '$(TAG)'"
	@echo "Building master docker image '$(TAG)'"

# Builds each component and installs it to $GOPATH/bin.
install: all
	@echo "Installing binary to './bin'"
N
neza2017 已提交
118
	@mkdir -p $(GOPATH)/bin && cp -f $(PWD)/bin/querynode $(GOPATH)/bin/querynode
119 120
	@mkdir -p $(GOPATH)/bin && cp -f $(PWD)/bin/master $(GOPATH)/bin/master
	@mkdir -p $(GOPATH)/bin && cp -f $(PWD)/bin/proxy $(GOPATH)/bin/proxy
X
XuanYang-cn 已提交
121
	@mkdir -p $(GOPATH)/bin && cp -f $(PWD)/bin/writenode $(GOPATH)/bin/writenode
122 123 124 125 126 127 128
	@mkdir -p $(LIBRARY_PATH) && cp -f $(PWD)/internal/core/output/lib/* $(LIBRARY_PATH)
	@echo "Installation successful."

clean:
	@echo "Cleaning up all the generated files"
	@find . -name '*.test' | xargs rm -fv
	@find . -name '*~' | xargs rm -fv
N
neza2017 已提交
129
	@rm -rvf querynode
130 131
	@rm -rvf master
	@rm -rvf proxy
X
XuanYang-cn 已提交
132
	@rm -rvf writenode