github.com/matrixorigin/matrixone@v0.7.0/Makefile (about) 1 # Copyright 2021 - 2022 Matrix Origin 2 # 3 # Licensed under the Apache License, Version 2.0 (the "License"); 4 # you may not use this file except in compliance with the License. 5 # You may obtain a copy of the License at 6 # 7 # http://www.apache.org/licenses/LICENSE-2.0 8 # 9 # Unless required by applicable law or agreed to in writing, software 10 # distributed under the License is distributed on an "AS IS" BASIS, 11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 # See the License for the specific language governing permissions and 13 # limitations under the License. 14 15 # 16 # Examples 17 # 18 # By default, make builds the mo-service 19 # 20 # make 21 # 22 # To re-build MO - 23 # 24 # make clean 25 # make config 26 # make build 27 # 28 # To re-build MO in debug mode also with race detector enabled - 29 # 30 # make clean 31 # make config 32 # make debug 33 # 34 # To run static checks - 35 # 36 # make install-static-check-tools 37 # make static-check 38 # 39 # 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. 40 # make vendor 41 # 42 43 # where am I 44 ROOT_DIR = $(shell dirname $(realpath $(lastword $(MAKEFILE_LIST)))) 45 GOBIN := go 46 BIN_NAME := mo-service 47 MO_DUMP := mo-dump 48 BUILD_CFG := gen_config 49 UNAME_S := $(shell uname -s) 50 GOPATH := $(shell go env GOPATH) 51 GO_VERSION=$(shell go version) 52 BRANCH_NAME=$(shell git rev-parse --abbrev-ref HEAD) 53 LAST_COMMIT_ID=$(shell git rev-parse HEAD) 54 BUILD_TIME=$(shell date) 55 MO_VERSION=$(shell git describe --always --tags $(shell git rev-list --tags --max-count=1)) 56 57 # cross compilation has been disabled for now 58 ifneq ($(GOARCH)$(TARGET_ARCH)$(GOOS)$(TARGET_OS),) 59 $(error cross compilation has been disabled) 60 endif 61 62 ############################################################################### 63 # default target 64 ############################################################################### 65 all: build 66 67 68 ############################################################################### 69 # build vendor directory 70 ############################################################################### 71 72 VENDOR_DIRECTORY := ./vendor 73 .PHONY: vendor-build 74 vendor-build: 75 $(info [go mod vendor]) 76 @go mod vendor 77 78 79 80 ############################################################################### 81 # code generation 82 ############################################################################### 83 84 .PHONY: config 85 config: 86 $(info [Create build config]) 87 @go mod tidy 88 89 .PHONY: generate-pb 90 generate-pb: 91 $(ROOT_DIR)/proto/gen.sh 92 93 # Generate protobuf files 94 .PHONY: pb 95 pb: vendor-build generate-pb fmt 96 $(info all protos are generated) 97 98 ############################################################################### 99 # build mo-service 100 ############################################################################### 101 102 RACE_OPT := 103 DEBUG_OPT := 104 CGO_DEBUG_OPT := 105 CGO_OPTS=CGO_CFLAGS="-I$(ROOT_DIR)/cgo" CGO_LDFLAGS="-L$(ROOT_DIR)/cgo -lmo -lm" 106 GO=$(CGO_OPTS) $(GOBIN) 107 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)'" 108 109 .PHONY: cgo 110 cgo: 111 @(cd cgo; make ${CGO_DEBUG_OPT}) 112 113 BUILD_NAME=binary 114 # build mo-service binary 115 .PHONY: build 116 build: config cgo cmd/mo-service/$(wildcard *.go) 117 $(info [Build $(BUILD_NAME)]) 118 $(GO) build $(RACE_OPT) $(GOLDFLAGS) -o $(BIN_NAME) ./cmd/mo-service 119 120 .PHONY: modump 121 modump: 122 $(GO) build $(RACE_OPT) $(GOLDFLAGS) -o $(MO_DUMP) ./cmd/mo-dump 123 124 # build mo-service binary for debugging with go's race detector enabled 125 # produced executable is 10x slower and consumes much more memory 126 .PHONY: debug 127 debug: override BUILD_NAME := debug-binary 128 debug: override RACE_OPT := -race 129 debug: override DEBUG_OPT := -gcflags=all="-N -l" 130 debug: override CGO_DEBUG_OPT := debug 131 debug: build 132 133 ############################################################################### 134 # run unit tests 135 ############################################################################### 136 # Excluding frontend test cases temporarily 137 # Argument SKIP_TEST to skip a specific go test 138 .PHONY: ut 139 ut: config cgo 140 $(info [Unit testing]) 141 ifeq ($(UNAME_S),Darwin) 142 @cd optools && ./run_ut.sh UT $(SKIP_TEST) 143 else 144 @cd optools && timeout 60m ./run_ut.sh UT $(SKIP_TEST) 145 endif 146 147 ############################################################################### 148 # bvt and unit test 149 ############################################################################### 150 UT_PARALLEL ?= 1 151 ENABLE_UT ?= "false" 152 GOPROXY ?= "https://proxy.golang.com.cn,direct" 153 LAUNCH ?= "launch-tae-CN-tae-DN" 154 155 .PHONY: ci 156 ci: 157 @rm -rf $(ROOT_DIR)/tester-log 158 @docker image prune -f 159 @docker build -f optools/bvt_ut/Dockerfile . -t matrixorigin/matrixone:local-ci --build-arg GOPROXY=$(GOPROXY) 160 @docker run --name tester -it \ 161 -e LAUNCH=$(LAUNCH) \ 162 -e UT_PARALLEL=$(UT_PARALLEL) \ 163 -e ENABLE_UT=$(ENABLE_UT)\ 164 --rm -v $(ROOT_DIR)/tester-log:/matrixone-test/tester-log matrixorigin/matrixone:local-ci 165 166 .PHONY: ci-clean 167 ci-clean: 168 @docker rmi matrixorigin/matrixone:local-ci 169 @docker image prune -f 170 171 ############################################################################### 172 # clean 173 ############################################################################### 174 175 .PHONY: clean 176 clean: 177 $(info [Clean up]) 178 $(info Clean go test cache) 179 @go clean -testcache 180 rm -f $(BIN_NAME) $(BUILD_CFG) 181 rm -rf $(VENDOR_DIRECTORY) 182 $(MAKE) -C cgo clean 183 184 ############################################################################### 185 # static checks 186 ############################################################################### 187 188 .PHONY: fmt 189 fmt: 190 gofmt -l -s -w . 191 192 .PHONY: install-static-check-tools 193 install-static-check-tools: 194 @curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | bash -s -- -b $(GOPATH)/bin v1.48.0 195 @go install github.com/matrixorigin/linter/cmd/molint@latest 196 @go install github.com/apache/skywalking-eyes/cmd/license-eye@v0.4.0 197 198 199 .PHONY: static-check 200 static-check: config cgo err-check 201 $(CGO_OPTS) go vet -vettool=`which molint` $(shell go list ./... | grep -v github.com/matrixorigin/matrixone/cmd/mo-dump) 202 $(CGO_OPTS) license-eye -c .licenserc.yml header check 203 $(CGO_OPTS) license-eye -c .licenserc.yml dep check 204 $(CGO_OPTS) golangci-lint run -c .golangci.yml ./... 205 206 fmtErrs := $(shell grep -onr 'fmt.Errorf' pkg/ --exclude-dir=.git --exclude-dir=vendor \ 207 --exclude=*.pb.go --exclude=system_vars.go --exclude=Makefile) 208 errNews := $(shell grep -onr 'errors.New' pkg/ --exclude-dir=.git --exclude-dir=vendor \ 209 --exclude=*.pb.go --exclude=system_vars.go --exclude=Makefile) 210 211 .PHONY: err-check 212 err-check: 213 ifneq ("$(strip $(fmtErrs))$(strip $(errNews))", "") 214 ifneq ("$(strip $(fmtErrs))", "") 215 $(warning 'fmt.Errorf()' is found.) 216 $(warning One of 'fmt.Errorf()' is called at: $(shell printf "%s\n" $(fmtErrs) | head -1)) 217 endif 218 ifneq ("$(strip $(errNews))", "") 219 $(warning 'errors.New()' is found.) 220 $(warning One of 'errors.New()' is called at: $(shell printf "%s\n" $(errNews) | head -1)) 221 endif 222 223 $(error Use moerr instead.) 224 else 225 $(info Neither 'fmt.Errorf()' nor 'errors.New()' is found) 226 endif