From 5d7071aba440b5580d5cba45fbae4dd75455e7e5 Mon Sep 17 00:00:00 2001 From: Leon Zhang Date: Tue, 25 Dec 2018 23:47:38 +0800 Subject: [PATCH] makefile colors setting for compatible --- Makefile | 59 ++++++++++++++++++++++++++-------------------- vendor/vendor.json | 28 +++++++++++----------- 2 files changed, 48 insertions(+), 39 deletions(-) diff --git a/Makefile b/Makefile index a06388e..9f7636a 100644 --- a/Makefile +++ b/Makefile @@ -17,6 +17,15 @@ LDFLAGS=-ldflags="-s -w" BUILD_TIME=`date +%Y%m%d%H%M` 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` # MySQL 5.1 `MYSQL_RELEASE=vsamov/mysql-5.1.73 make docker` # MYSQL_RELEASE: mysql, percona, mariadb ... @@ -34,7 +43,7 @@ GO_VERSION_MIN=1.10 # 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]}' 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 \ $(shell echo "$(GO_VERSION_MIN)" | $(VER_TO_INT)); \ then printf "go version $(GO_VERSION_MIN)+ required, found: "; go version; exit 1; \ @@ -43,7 +52,7 @@ go_version_check: # Dependency check .PHONY: deps deps: - @echo "\033[92mDependency check\033[0m" + @echo "$(CGREEN)Dependency check ...$(CEND)" @bash ./deps.sh # The retool tools.json is setup from retool-install.sh # some packages download need more open internet access @@ -53,7 +62,7 @@ deps: # Code format .PHONY: fmt 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 ..." @ret=0 && for d in $$(go list -f '{{.Dir}}' ./... | grep -v /vendor/); do \ gofmt -l -s -w $$d/*.go || ret=$$? ; \ @@ -62,13 +71,13 @@ fmt: go_version_check # Run golang test cases .PHONY: test test: - @echo "\033[92mRun all test cases ...\033[0m" + @echo "$(CGREEN)Run all test cases ...$(CEND)" go test -race ./... @echo "test Success!" # Rule golang test cases with `-update` flag 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 @echo "test-update Success!" @@ -76,21 +85,21 @@ test-update: # colorful coverage numerical >=90% GREEN, <80% RED, Other YELLOW .PHONY: cover 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 tool cover -html=coverage.data -o coverage.html go tool cover -func=coverage.data -o coverage.txt @tail -n 1 coverage.txt | awk '{sub(/%/, "", $$NF); \ if($$NF < 80) \ - {print "\033[91m"$$0"%\033[0m"} \ + {print "$(CRED)"$$0"%$(CEND)"} \ else if ($$NF >= 90) \ - {print "\033[92m"$$0"%\033[0m"} \ + {print "$(CGREEN)"$$0"%$(CEND)"} \ else \ - {print "\033[93m"$$0"%\033[0m"}}' + {print "$(CYELLOW)"$$0"%$(CEND)"}}' # Builds the project build: fmt - @echo "\033[92mBuilding ...\033[0m" + @echo "$(CGREEN)Building ...$(CEND)" @mkdir -p bin @bash ./genver.sh @ret=0 && for d in $$(go list -f '{{if (eq .Name "main")}}{{.ImportPath}}{{end}}' ./...); do \ @@ -101,14 +110,14 @@ build: fmt # Installs our project: copies binaries install: build - @echo "\033[92mInstall ...\033[0m" + @echo "$(CGREEN)Install ...$(CEND)" go install ./... @echo "install Success!" # Generate doc use -list* command .PHONY: doc 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-rewrite-rules > doc/rewrite.md ./bin/soar -list-report-types > doc/report_type.md @@ -116,7 +125,7 @@ doc: build # Add or change a heuristic rule .PHONY: heuristic 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 TestMergeConflictHeuristicRules docker stop soar-mysql 2>/dev/null || true @@ -124,19 +133,19 @@ heuristic: doc # Update vitess vendor .PHONY: vitess vitess: - @echo "\033[92mUpdate vitess deps ...\033[0m" + @echo "$(CGREEN)Update vitess deps ...$(CEND)" govendor fetch -v vitess.io/vitess/... # Update tidb vendor .PHONY: tidb tidb: - @echo "\033[92mUpdate tidb deps ...\033[0m" + @echo "$(CGREEN)Update tidb deps ...$(CEND)" govendor fetch -v github.com/pingcap/tidb/... # make pingcap parser .PHONY: pingcap-parser 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/... # Update all vendor @@ -147,7 +156,7 @@ vendor: vitess pingcap-parser #@bash doc/example/metalinter.sh .PHONY: lint 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 ./... retool do revive -formatter friendly --exclude vendor/... -config doc/example/revive.toml ./... retool do golangci-lint --tests=false run @@ -155,7 +164,7 @@ lint: build .PHONY: release release: build - @echo "\033[92mCross platform building for release ...\033[0m" + @echo "$(CGREEN)Cross platform building for release ...$(CEND)" @mkdir -p release @for GOOS in darwin linux windows; do \ for GOARCH in amd64; do \ @@ -169,7 +178,7 @@ release: build .PHONY: 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 wait soar-mysql 2>/dev/null || true @echo "docker run --name soar-mysql $(MYSQL_RELEASE):$(MYSQL_VERSION)" @@ -199,30 +208,30 @@ docker-it: .PHONY: main_test main_test: install - @echo "\033[92mrunning main_test\033[0m" + @echo "$(CGREEN)running main_test ...$(CEND)" @echo "soar -list-test-sqls | soar" @./doc/example/main_test.sh @echo "main_test Success!" .PHONY: daily 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. .PHONY: daily-quick 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 logo: - @echo "\033[93m" + @echo "$(CYELLOW)" @cat doc/images/logo.ascii - @echo "\033[m" + @echo "$(CEND)" # Cleans our projects: deletes binaries .PHONY: clean clean: - @echo "\033[92mCleanup ...\033[0m" + @echo "$(CGREEN)Cleanup ...$(CEND)" go clean @for GOOS in darwin linux windows; do \ for GOARCH in 386 amd64; do \ diff --git a/vendor/vendor.json b/vendor/vendor.json index d0ad663..fdd2be1 100644 --- a/vendor/vendor.json +++ b/vendor/vendor.json @@ -173,44 +173,44 @@ { "checksumSHA1": "Uv9aqrZqzNFUgUferYPfNGUxOmM=", "path": "github.com/pingcap/tidb/sessionctx/stmtctx", - "revision": "90b619a452cf203bbc804f934fa7ae798706789e", - "revisionTime": "2018-12-25T13:59:04Z" + "revision": "b74d0283a2a6f780b75c7192e760b41a03e80884", + "revisionTime": "2018-12-25T14:40:38Z" }, { "checksumSHA1": "kXyszfR2fQ6bHvuCCFlHRkt1mF0=", "path": "github.com/pingcap/tidb/types", - "revision": "90b619a452cf203bbc804f934fa7ae798706789e", - "revisionTime": "2018-12-25T13:59:04Z" + "revision": "b74d0283a2a6f780b75c7192e760b41a03e80884", + "revisionTime": "2018-12-25T14:40:38Z" }, { "checksumSHA1": "DWVD7+ygtT66IQ+cqXmMJ5OVqUk=", "path": "github.com/pingcap/tidb/types/json", - "revision": "90b619a452cf203bbc804f934fa7ae798706789e", - "revisionTime": "2018-12-25T13:59:04Z" + "revision": "b74d0283a2a6f780b75c7192e760b41a03e80884", + "revisionTime": "2018-12-25T14:40:38Z" }, { "checksumSHA1": "6vi/eCZXqNTa5eAUpxDZet4LPlY=", "path": "github.com/pingcap/tidb/types/parser_driver", - "revision": "90b619a452cf203bbc804f934fa7ae798706789e", - "revisionTime": "2018-12-25T13:59:04Z" + "revision": "b74d0283a2a6f780b75c7192e760b41a03e80884", + "revisionTime": "2018-12-25T14:40:38Z" }, { "checksumSHA1": "SS7twHZofFKr8w/pwIKmkp3u5qU=", "path": "github.com/pingcap/tidb/util/execdetails", - "revision": "90b619a452cf203bbc804f934fa7ae798706789e", - "revisionTime": "2018-12-25T13:59:04Z" + "revision": "b74d0283a2a6f780b75c7192e760b41a03e80884", + "revisionTime": "2018-12-25T14:40:38Z" }, { "checksumSHA1": "nUC7zVoAMNR2a+z2iGqHoN2AkFE=", "path": "github.com/pingcap/tidb/util/hack", - "revision": "90b619a452cf203bbc804f934fa7ae798706789e", - "revisionTime": "2018-12-25T13:59:04Z" + "revision": "b74d0283a2a6f780b75c7192e760b41a03e80884", + "revisionTime": "2018-12-25T14:40:38Z" }, { "checksumSHA1": "xSyepiuqsoaaeDch7cXeumvVHKM=", "path": "github.com/pingcap/tidb/util/memory", - "revision": "90b619a452cf203bbc804f934fa7ae798706789e", - "revisionTime": "2018-12-25T13:59:04Z" + "revision": "b74d0283a2a6f780b75c7192e760b41a03e80884", + "revisionTime": "2018-12-25T14:40:38Z" }, { "checksumSHA1": "SmYeIK/fIYXNu8IKxD6HOVQVTuU=", -- GitLab