提交 5d7071ab 编写于 作者: martianzhang's avatar martianzhang

makefile colors setting for compatible

上级 1457abf1
...@@ -17,6 +17,15 @@ LDFLAGS=-ldflags="-s -w" ...@@ -17,6 +17,15 @@ LDFLAGS=-ldflags="-s -w"
BUILD_TIME=`date +%Y%m%d%H%M` BUILD_TIME=`date +%Y%m%d%H%M`
COMMIT_VERSION=`git rev-parse HEAD` COMMIT_VERSION=`git rev-parse HEAD`
# colors compatible setting
COLOR_ENABLE=$(shell tput colors > /dev/null; echo $$?)
ifeq "$(COLOR_ENABLE)" "0"
CRED=$(shell echo "\033[91m")
CGREEN=$(shell echo "\033[92m")
CYELLOW=$(shell echo "\033[93m")
CEND=$(shell echo "\033[0m")
endif
# Add mysql version for testing `MYSQL_RELEASE=percona MYSQL_VERSION=5.7 make docker` # Add mysql version for testing `MYSQL_RELEASE=percona MYSQL_VERSION=5.7 make docker`
# MySQL 5.1 `MYSQL_RELEASE=vsamov/mysql-5.1.73 make docker` # MySQL 5.1 `MYSQL_RELEASE=vsamov/mysql-5.1.73 make docker`
# MYSQL_RELEASE: mysql, percona, mariadb ... # MYSQL_RELEASE: mysql, percona, mariadb ...
...@@ -34,7 +43,7 @@ GO_VERSION_MIN=1.10 ...@@ -34,7 +43,7 @@ GO_VERSION_MIN=1.10
# that allows the three components to be checked in a single comparison. # that allows the three components to be checked in a single comparison.
VER_TO_INT:=awk '{split(substr($$0, match ($$0, /[0-9\.]+/)), a, "."); print a[1]*10000+a[2]*100+a[3]}' VER_TO_INT:=awk '{split(substr($$0, match ($$0, /[0-9\.]+/)), a, "."); print a[1]*10000+a[2]*100+a[3]}'
go_version_check: go_version_check:
@echo "\033[92mGo version check\033[0m" @echo "$(CGREEN)Go version check ...$(CEND)"
@if test $(shell go version | $(VER_TO_INT) ) -lt \ @if test $(shell go version | $(VER_TO_INT) ) -lt \
$(shell echo "$(GO_VERSION_MIN)" | $(VER_TO_INT)); \ $(shell echo "$(GO_VERSION_MIN)" | $(VER_TO_INT)); \
then printf "go version $(GO_VERSION_MIN)+ required, found: "; go version; exit 1; \ then printf "go version $(GO_VERSION_MIN)+ required, found: "; go version; exit 1; \
...@@ -43,7 +52,7 @@ go_version_check: ...@@ -43,7 +52,7 @@ go_version_check:
# Dependency check # Dependency check
.PHONY: deps .PHONY: deps
deps: deps:
@echo "\033[92mDependency check\033[0m" @echo "$(CGREEN)Dependency check ...$(CEND)"
@bash ./deps.sh @bash ./deps.sh
# The retool tools.json is setup from retool-install.sh # The retool tools.json is setup from retool-install.sh
# some packages download need more open internet access # some packages download need more open internet access
...@@ -53,7 +62,7 @@ deps: ...@@ -53,7 +62,7 @@ deps:
# Code format # Code format
.PHONY: fmt .PHONY: fmt
fmt: go_version_check fmt: go_version_check
@echo "\033[92mRun gofmt on all source files ...\033[0m" @echo "$(CGREEN)Run gofmt on all source files ...$(CEND)"
@echo "gofmt -l -s -w ..." @echo "gofmt -l -s -w ..."
@ret=0 && for d in $$(go list -f '{{.Dir}}' ./... | grep -v /vendor/); do \ @ret=0 && for d in $$(go list -f '{{.Dir}}' ./... | grep -v /vendor/); do \
gofmt -l -s -w $$d/*.go || ret=$$? ; \ gofmt -l -s -w $$d/*.go || ret=$$? ; \
...@@ -62,13 +71,13 @@ fmt: go_version_check ...@@ -62,13 +71,13 @@ fmt: go_version_check
# Run golang test cases # Run golang test cases
.PHONY: test .PHONY: test
test: test:
@echo "\033[92mRun all test cases ...\033[0m" @echo "$(CGREEN)Run all test cases ...$(CEND)"
go test -race ./... go test -race ./...
@echo "test Success!" @echo "test Success!"
# Rule golang test cases with `-update` flag # Rule golang test cases with `-update` flag
test-update: test-update:
@echo "\033[92mRun all test cases with -update flag ...\033[0m" @echo "$(CGREEN)Run all test cases with -update flag ...$(CEND)"
go test ./... -update go test ./... -update
@echo "test-update Success!" @echo "test-update Success!"
...@@ -76,21 +85,21 @@ test-update: ...@@ -76,21 +85,21 @@ test-update:
# colorful coverage numerical >=90% GREEN, <80% RED, Other YELLOW # colorful coverage numerical >=90% GREEN, <80% RED, Other YELLOW
.PHONY: cover .PHONY: cover
cover: test cover: test
@echo "\033[92mRun test cover check ...\033[0m" @echo "$(CGREEN)Run test cover check ...$(CEND)"
go test -coverpkg=./... -coverprofile=coverage.data ./... | column -t go test -coverpkg=./... -coverprofile=coverage.data ./... | column -t
go tool cover -html=coverage.data -o coverage.html go tool cover -html=coverage.data -o coverage.html
go tool cover -func=coverage.data -o coverage.txt go tool cover -func=coverage.data -o coverage.txt
@tail -n 1 coverage.txt | awk '{sub(/%/, "", $$NF); \ @tail -n 1 coverage.txt | awk '{sub(/%/, "", $$NF); \
if($$NF < 80) \ if($$NF < 80) \
{print "\033[91m"$$0"%\033[0m"} \ {print "$(CRED)"$$0"%$(CEND)"} \
else if ($$NF >= 90) \ else if ($$NF >= 90) \
{print "\033[92m"$$0"%\033[0m"} \ {print "$(CGREEN)"$$0"%$(CEND)"} \
else \ else \
{print "\033[93m"$$0"%\033[0m"}}' {print "$(CYELLOW)"$$0"%$(CEND)"}}'
# Builds the project # Builds the project
build: fmt build: fmt
@echo "\033[92mBuilding ...\033[0m" @echo "$(CGREEN)Building ...$(CEND)"
@mkdir -p bin @mkdir -p bin
@bash ./genver.sh @bash ./genver.sh
@ret=0 && for d in $$(go list -f '{{if (eq .Name "main")}}{{.ImportPath}}{{end}}' ./...); do \ @ret=0 && for d in $$(go list -f '{{if (eq .Name "main")}}{{.ImportPath}}{{end}}' ./...); do \
...@@ -101,14 +110,14 @@ build: fmt ...@@ -101,14 +110,14 @@ build: fmt
# Installs our project: copies binaries # Installs our project: copies binaries
install: build install: build
@echo "\033[92mInstall ...\033[0m" @echo "$(CGREEN)Install ...$(CEND)"
go install ./... go install ./...
@echo "install Success!" @echo "install Success!"
# Generate doc use -list* command # Generate doc use -list* command
.PHONY: doc .PHONY: doc
doc: build doc: build
@echo "\033[92mAuto generate doc ...\033[0m" @echo "$(CGREEN)Auto generate doc ...$(CEND)"
./bin/soar -list-heuristic-rules > doc/heuristic.md ./bin/soar -list-heuristic-rules > doc/heuristic.md
./bin/soar -list-rewrite-rules > doc/rewrite.md ./bin/soar -list-rewrite-rules > doc/rewrite.md
./bin/soar -list-report-types > doc/report_type.md ./bin/soar -list-report-types > doc/report_type.md
...@@ -116,7 +125,7 @@ doc: build ...@@ -116,7 +125,7 @@ doc: build
# Add or change a heuristic rule # Add or change a heuristic rule
.PHONY: heuristic .PHONY: heuristic
heuristic: doc heuristic: doc
@echo "\033[92mUpdate Heuristic rule golden files ...\033[0m" @echo "$(CGREEN)Update Heuristic rule golden files ...$(CEND)"
go test github.com/XiaoMi/soar/advisor -v -update -run TestListHeuristicRules go test github.com/XiaoMi/soar/advisor -v -update -run TestListHeuristicRules
go test github.com/XiaoMi/soar/advisor -v -update -run TestMergeConflictHeuristicRules go test github.com/XiaoMi/soar/advisor -v -update -run TestMergeConflictHeuristicRules
docker stop soar-mysql 2>/dev/null || true docker stop soar-mysql 2>/dev/null || true
...@@ -124,19 +133,19 @@ heuristic: doc ...@@ -124,19 +133,19 @@ heuristic: doc
# Update vitess vendor # Update vitess vendor
.PHONY: vitess .PHONY: vitess
vitess: vitess:
@echo "\033[92mUpdate vitess deps ...\033[0m" @echo "$(CGREEN)Update vitess deps ...$(CEND)"
govendor fetch -v vitess.io/vitess/... govendor fetch -v vitess.io/vitess/...
# Update tidb vendor # Update tidb vendor
.PHONY: tidb .PHONY: tidb
tidb: tidb:
@echo "\033[92mUpdate tidb deps ...\033[0m" @echo "$(CGREEN)Update tidb deps ...$(CEND)"
govendor fetch -v github.com/pingcap/tidb/... govendor fetch -v github.com/pingcap/tidb/...
# make pingcap parser # make pingcap parser
.PHONY: pingcap-parser .PHONY: pingcap-parser
pingcap-parser: tidb pingcap-parser: tidb
@echo "\033[92mUpdate pingcap parser deps ...\033[0m" @echo "$(CGREEN)Update pingcap parser deps ...$(CEND)"
govendor fetch -v github.com/pingcap/parser/... govendor fetch -v github.com/pingcap/parser/...
# Update all vendor # Update all vendor
...@@ -147,7 +156,7 @@ vendor: vitess pingcap-parser ...@@ -147,7 +156,7 @@ vendor: vitess pingcap-parser
#@bash doc/example/metalinter.sh #@bash doc/example/metalinter.sh
.PHONY: lint .PHONY: lint
lint: build lint: build
@echo "\033[92mRun linter check ...\033[0m" @echo "$(CGREEN)Run linter check ...$(CEND)"
CGO_ENABLED=0 retool do gometalinter.v2 -j 1 --config doc/example/metalinter.json ./... CGO_ENABLED=0 retool do gometalinter.v2 -j 1 --config doc/example/metalinter.json ./...
retool do revive -formatter friendly --exclude vendor/... -config doc/example/revive.toml ./... retool do revive -formatter friendly --exclude vendor/... -config doc/example/revive.toml ./...
retool do golangci-lint --tests=false run retool do golangci-lint --tests=false run
...@@ -155,7 +164,7 @@ lint: build ...@@ -155,7 +164,7 @@ lint: build
.PHONY: release .PHONY: release
release: build release: build
@echo "\033[92mCross platform building for release ...\033[0m" @echo "$(CGREEN)Cross platform building for release ...$(CEND)"
@mkdir -p release @mkdir -p release
@for GOOS in darwin linux windows; do \ @for GOOS in darwin linux windows; do \
for GOARCH in amd64; do \ for GOARCH in amd64; do \
...@@ -169,7 +178,7 @@ release: build ...@@ -169,7 +178,7 @@ release: build
.PHONY: docker .PHONY: docker
docker: docker:
@echo "\033[92mBuild mysql test enviorment\033[0m" @echo "$(CGREEN)Build mysql test enviorment ...$(CEND)"
@docker stop soar-mysql 2>/dev/null || true @docker stop soar-mysql 2>/dev/null || true
@docker wait soar-mysql 2>/dev/null || true @docker wait soar-mysql 2>/dev/null || true
@echo "docker run --name soar-mysql $(MYSQL_RELEASE):$(MYSQL_VERSION)" @echo "docker run --name soar-mysql $(MYSQL_RELEASE):$(MYSQL_VERSION)"
...@@ -199,30 +208,30 @@ docker-it: ...@@ -199,30 +208,30 @@ docker-it:
.PHONY: main_test .PHONY: main_test
main_test: install main_test: install
@echo "\033[92mrunning main_test\033[0m" @echo "$(CGREEN)running main_test ...$(CEND)"
@echo "soar -list-test-sqls | soar" @echo "soar -list-test-sqls | soar"
@./doc/example/main_test.sh @./doc/example/main_test.sh
@echo "main_test Success!" @echo "main_test Success!"
.PHONY: daily .PHONY: daily
daily: | deps fmt vendor docker cover doc lint release install main_test clean logo daily: | deps fmt vendor docker cover doc lint release install main_test clean logo
@echo "\033[92mdaily build finished\033[0m" @echo "$(CGREEN)daily build finished ...$(CEND)"
# vendor, docker will cost long time, if all those are ready, daily-quick will much more fast. # vendor, docker will cost long time, if all those are ready, daily-quick will much more fast.
.PHONY: daily-quick .PHONY: daily-quick
daily-quick: | deps fmt cover main_test doc lint logo daily-quick: | deps fmt cover main_test doc lint logo
@echo "\033[92mdaily-quick build finished\033[0m" @echo "$(CGREEN)daily-quick build finished ...$(CEND)"
.PHONY: logo .PHONY: logo
logo: logo:
@echo "\033[93m" @echo "$(CYELLOW)"
@cat doc/images/logo.ascii @cat doc/images/logo.ascii
@echo "\033[m" @echo "$(CEND)"
# Cleans our projects: deletes binaries # Cleans our projects: deletes binaries
.PHONY: clean .PHONY: clean
clean: clean:
@echo "\033[92mCleanup ...\033[0m" @echo "$(CGREEN)Cleanup ...$(CEND)"
go clean go clean
@for GOOS in darwin linux windows; do \ @for GOOS in darwin linux windows; do \
for GOARCH in 386 amd64; do \ for GOARCH in 386 amd64; do \
......
...@@ -173,44 +173,44 @@ ...@@ -173,44 +173,44 @@
{ {
"checksumSHA1": "Uv9aqrZqzNFUgUferYPfNGUxOmM=", "checksumSHA1": "Uv9aqrZqzNFUgUferYPfNGUxOmM=",
"path": "github.com/pingcap/tidb/sessionctx/stmtctx", "path": "github.com/pingcap/tidb/sessionctx/stmtctx",
"revision": "90b619a452cf203bbc804f934fa7ae798706789e", "revision": "b74d0283a2a6f780b75c7192e760b41a03e80884",
"revisionTime": "2018-12-25T13:59:04Z" "revisionTime": "2018-12-25T14:40:38Z"
}, },
{ {
"checksumSHA1": "kXyszfR2fQ6bHvuCCFlHRkt1mF0=", "checksumSHA1": "kXyszfR2fQ6bHvuCCFlHRkt1mF0=",
"path": "github.com/pingcap/tidb/types", "path": "github.com/pingcap/tidb/types",
"revision": "90b619a452cf203bbc804f934fa7ae798706789e", "revision": "b74d0283a2a6f780b75c7192e760b41a03e80884",
"revisionTime": "2018-12-25T13:59:04Z" "revisionTime": "2018-12-25T14:40:38Z"
}, },
{ {
"checksumSHA1": "DWVD7+ygtT66IQ+cqXmMJ5OVqUk=", "checksumSHA1": "DWVD7+ygtT66IQ+cqXmMJ5OVqUk=",
"path": "github.com/pingcap/tidb/types/json", "path": "github.com/pingcap/tidb/types/json",
"revision": "90b619a452cf203bbc804f934fa7ae798706789e", "revision": "b74d0283a2a6f780b75c7192e760b41a03e80884",
"revisionTime": "2018-12-25T13:59:04Z" "revisionTime": "2018-12-25T14:40:38Z"
}, },
{ {
"checksumSHA1": "6vi/eCZXqNTa5eAUpxDZet4LPlY=", "checksumSHA1": "6vi/eCZXqNTa5eAUpxDZet4LPlY=",
"path": "github.com/pingcap/tidb/types/parser_driver", "path": "github.com/pingcap/tidb/types/parser_driver",
"revision": "90b619a452cf203bbc804f934fa7ae798706789e", "revision": "b74d0283a2a6f780b75c7192e760b41a03e80884",
"revisionTime": "2018-12-25T13:59:04Z" "revisionTime": "2018-12-25T14:40:38Z"
}, },
{ {
"checksumSHA1": "SS7twHZofFKr8w/pwIKmkp3u5qU=", "checksumSHA1": "SS7twHZofFKr8w/pwIKmkp3u5qU=",
"path": "github.com/pingcap/tidb/util/execdetails", "path": "github.com/pingcap/tidb/util/execdetails",
"revision": "90b619a452cf203bbc804f934fa7ae798706789e", "revision": "b74d0283a2a6f780b75c7192e760b41a03e80884",
"revisionTime": "2018-12-25T13:59:04Z" "revisionTime": "2018-12-25T14:40:38Z"
}, },
{ {
"checksumSHA1": "nUC7zVoAMNR2a+z2iGqHoN2AkFE=", "checksumSHA1": "nUC7zVoAMNR2a+z2iGqHoN2AkFE=",
"path": "github.com/pingcap/tidb/util/hack", "path": "github.com/pingcap/tidb/util/hack",
"revision": "90b619a452cf203bbc804f934fa7ae798706789e", "revision": "b74d0283a2a6f780b75c7192e760b41a03e80884",
"revisionTime": "2018-12-25T13:59:04Z" "revisionTime": "2018-12-25T14:40:38Z"
}, },
{ {
"checksumSHA1": "xSyepiuqsoaaeDch7cXeumvVHKM=", "checksumSHA1": "xSyepiuqsoaaeDch7cXeumvVHKM=",
"path": "github.com/pingcap/tidb/util/memory", "path": "github.com/pingcap/tidb/util/memory",
"revision": "90b619a452cf203bbc804f934fa7ae798706789e", "revision": "b74d0283a2a6f780b75c7192e760b41a03e80884",
"revisionTime": "2018-12-25T13:59:04Z" "revisionTime": "2018-12-25T14:40:38Z"
}, },
{ {
"checksumSHA1": "SmYeIK/fIYXNu8IKxD6HOVQVTuU=", "checksumSHA1": "SmYeIK/fIYXNu8IKxD6HOVQVTuU=",
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册