forked from matrixorigin/matrixone
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
226 lines (193 loc) · 6.99 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
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
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
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
# Copyright 2021 - 2022 Matrix Origin
#
# 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.
#
# Examples
#
# By default, make builds the mo-service
#
# make
#
# To re-build MO -
#
# make clean
# make config
# make build
#
# To re-build MO in debug mode also with race detector enabled -
#
# make clean
# make config
# make debug
#
# To run static checks -
#
# make install-static-check-tools
# make static-check
#
# To construct a directory named vendor in the main module’s root directory that contains copies of all packages needed to support builds and tests of packages in the main module.
# make vendor
#
# where am I
ROOT_DIR = $(shell dirname $(realpath $(lastword $(MAKEFILE_LIST))))
GOBIN := go
BIN_NAME := mo-service
MO_DUMP := mo-dump
BUILD_CFG := gen_config
UNAME_S := $(shell uname -s)
GOPATH := $(shell go env GOPATH)
GO_VERSION=$(shell go version)
BRANCH_NAME=$(shell git rev-parse --abbrev-ref HEAD)
LAST_COMMIT_ID=$(shell git rev-parse HEAD)
BUILD_TIME=$(shell date)
MO_VERSION=$(shell git describe --always --tags $(shell git rev-list --tags --max-count=1))
# cross compilation has been disabled for now
ifneq ($(GOARCH)$(TARGET_ARCH)$(GOOS)$(TARGET_OS),)
$(error cross compilation has been disabled)
endif
###############################################################################
# default target
###############################################################################
all: build
###############################################################################
# build vendor directory
###############################################################################
VENDOR_DIRECTORY := ./vendor
.PHONY: vendor-build
vendor-build:
$(info [go mod vendor])
@go mod vendor
###############################################################################
# code generation
###############################################################################
.PHONY: config
config:
$(info [Create build config])
@go mod tidy
.PHONY: generate-pb
generate-pb:
$(ROOT_DIR)/proto/gen.sh
# Generate protobuf files
.PHONY: pb
pb: vendor-build generate-pb fmt
$(info all protos are generated)
###############################################################################
# build mo-service
###############################################################################
RACE_OPT :=
DEBUG_OPT :=
CGO_DEBUG_OPT :=
CGO_OPTS=CGO_CFLAGS="-I$(ROOT_DIR)/cgo" CGO_LDFLAGS="-L$(ROOT_DIR)/cgo -lmo -lm"
GO=$(CGO_OPTS) $(GOBIN)
GOLDFLAGS=-ldflags="-X 'main.GoVersion=$(GO_VERSION)' -X 'main.BranchName=$(BRANCH_NAME)' -X 'main.CommitID=$(LAST_COMMIT_ID)' -X 'main.BuildTime=$(BUILD_TIME)' -X 'main.Version=$(MO_VERSION)'"
.PHONY: cgo
cgo:
@(cd cgo; make ${CGO_DEBUG_OPT})
BUILD_NAME=binary
# build mo-service binary
.PHONY: build
build: config cgo cmd/mo-service/$(wildcard *.go)
$(info [Build $(BUILD_NAME)])
$(GO) build $(RACE_OPT) $(GOLDFLAGS) -o $(BIN_NAME) ./cmd/mo-service
.PHONY: modump
modump:
$(GO) build $(RACE_OPT) $(GOLDFLAGS) -o $(MO_DUMP) ./cmd/mo-dump
# build mo-service binary for debugging with go's race detector enabled
# produced executable is 10x slower and consumes much more memory
.PHONY: debug
debug: override BUILD_NAME := debug-binary
debug: override RACE_OPT := -race
debug: override DEBUG_OPT := -gcflags=all="-N -l"
debug: override CGO_DEBUG_OPT := debug
debug: build
###############################################################################
# run unit tests
###############################################################################
# Excluding frontend test cases temporarily
# Argument SKIP_TEST to skip a specific go test
.PHONY: ut
ut: config cgo
$(info [Unit testing])
ifeq ($(UNAME_S),Darwin)
@cd optools && ./run_ut.sh UT $(SKIP_TEST)
else
@cd optools && timeout 60m ./run_ut.sh UT $(SKIP_TEST)
endif
###############################################################################
# bvt and unit test
###############################################################################
UT_PARALLEL ?= 1
ENABLE_UT ?= "false"
GOPROXY ?= "https://proxy.golang.com.cn,direct"
LAUNCH ?= "launch-tae-CN-tae-DN"
.PHONY: ci
ci:
@rm -rf $(ROOT_DIR)/tester-log
@docker image prune -f
@docker build -f optools/bvt_ut/Dockerfile . -t matrixorigin/matrixone:local-ci --build-arg GOPROXY=$(GOPROXY)
@docker run --name tester -it \
-e LAUNCH=$(LAUNCH) \
-e UT_PARALLEL=$(UT_PARALLEL) \
-e ENABLE_UT=$(ENABLE_UT)\
--rm -v $(ROOT_DIR)/tester-log:/matrixone-test/tester-log matrixorigin/matrixone:local-ci
.PHONY: ci-clean
ci-clean:
@docker rmi matrixorigin/matrixone:local-ci
@docker image prune -f
###############################################################################
# clean
###############################################################################
.PHONY: clean
clean:
$(info [Clean up])
$(info Clean go test cache)
@go clean -testcache
rm -f $(BIN_NAME) $(BUILD_CFG)
rm -rf $(VENDOR_DIRECTORY)
$(MAKE) -C cgo clean
###############################################################################
# static checks
###############################################################################
.PHONY: fmt
fmt:
gofmt -l -s -w .
.PHONY: install-static-check-tools
install-static-check-tools:
@curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | bash -s -- -b $(GOPATH)/bin v1.48.0
@go install github.com/matrixorigin/linter/cmd/molint@latest
@go install github.com/apache/skywalking-eyes/cmd/[email protected]
.PHONY: static-check
static-check: config cgo err-check
$(CGO_OPTS) go vet -vettool=`which molint` $(shell go list ./... | grep -v github.com/matrixorigin/matrixone/cmd/mo-dump)
$(CGO_OPTS) license-eye -c .licenserc.yml header check
$(CGO_OPTS) license-eye -c .licenserc.yml dep check
$(CGO_OPTS) golangci-lint run -c .golangci.yml ./...
fmtErrs := $(shell grep -onr 'fmt.Errorf' pkg/ --exclude-dir=.git --exclude-dir=vendor \
--exclude=*.pb.go --exclude=system_vars.go --exclude=Makefile)
errNews := $(shell grep -onr 'errors.New' pkg/ --exclude-dir=.git --exclude-dir=vendor \
--exclude=*.pb.go --exclude=system_vars.go --exclude=Makefile)
.PHONY: err-check
err-check:
ifneq ("$(strip $(fmtErrs))$(strip $(errNews))", "")
ifneq ("$(strip $(fmtErrs))", "")
$(warning 'fmt.Errorf()' is found.)
$(warning One of 'fmt.Errorf()' is called at: $(shell printf "%s\n" $(fmtErrs) | head -1))
endif
ifneq ("$(strip $(errNews))", "")
$(warning 'errors.New()' is found.)
$(warning One of 'errors.New()' is called at: $(shell printf "%s\n" $(errNews) | head -1))
endif
$(error Use moerr instead.)
else
$(info Neither 'fmt.Errorf()' nor 'errors.New()' is found)
endif