From 32d7cc13126f43911092e18465f3f6b6771c6092 Mon Sep 17 00:00:00 2001 From: Leon Zhang Date: Mon, 16 Sep 2019 13:59:21 +0800 Subject: [PATCH] update version.go --- .gitignore | 1 - Makefile | 21 +++++++++++++-------- advisor/rules.go | 2 +- common/version.go | 10 ++++++++++ doc/heuristic.md | 2 +- genver.sh | 38 -------------------------------------- 6 files changed, 25 insertions(+), 49 deletions(-) create mode 100644 common/version.go delete mode 100755 genver.sh diff --git a/.gitignore b/.gitignore index 7dbe1ba..c1f2fff 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,6 @@ bin/ release/ test/tmp/ -common/version.go doc/blueprint/ *.iml *.swp diff --git a/Makefile b/Makefile index d8c0934..2e241f4 100644 --- a/Makefile +++ b/Makefile @@ -11,7 +11,13 @@ ifeq "$(GOPATH)" "" endif PATH := ${GOPATH}/bin:$(PATH) GCFLAGS=-gcflags "all=-trimpath=${GOPATH}" -LDFLAGS=-ldflags="-s -w" +VERSION_TAG := $(shell git describe --tags --always) +VERSION_VERSION := $(shell git log --date=iso --pretty=format:"%cd" -1) $(VERSION_TAG) +VERSION_COMPILE := $(shell date +"%F %T %z") by $(shell go version) +VERSION_BRANCH := $(shell git rev-parse --abbrev-ref HEAD) +VERSION_GIT_DIRTY := $(shell git diff --no-ext-diff 2>/dev/null | wc -l) +VERSION_DEV_PATH:= $(shell pwd) +LDFLAGS=-ldflags="-s -w -X 'github.com/XiaoMi/soar/common.Version=$(VERSION_VERSION)' -X 'github.com/XiaoMi/soar/common.Compile=$(VERSION_COMPILE)' -X 'github.com/XiaoMi/soar/common.Branch=$(VERSION_BRANCH)' -X github.com/XiaoMi/soar/common.GitDirty=$(VERSION_GIT_DIRTY) -X github.com/XiaoMi/soar/common.DevPath=$(VERSION_DEV_PATH)" # These are the values we want to pass for VERSION and BUILD BUILD_TIME=`date +%Y%m%d%H%M` @@ -69,14 +75,14 @@ fmt: go_version_check .PHONY: test test: @echo "$(CGREEN)Run all test cases ...$(CEND)" - go test -timeout 10m -race ./... + @go test $(LDFLAGS) -timeout 10m -race ./... @echo "test Success!" # Rule golang test cases with `-update` flag .PHONY: test-update test-update: @echo "$(CGREEN)Run all test cases with -update flag ...$(CEND)" - go test ./... -update + @go test $(LDFLAGS) ./... -update @echo "test-update Success!" # Using bats test framework run all cli test cases @@ -92,9 +98,9 @@ test-cli: build .PHONY: cover cover: test @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 + @go test $(LDFLAGS) -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 "$(CRED)"$$0"%$(CEND)"} \ @@ -107,10 +113,9 @@ cover: test build: fmt @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 \ b=$$(basename $${d}) ; \ - go build ${GCFLAGS} -o bin/$${b} $$d || ret=$$? ; \ + go build ${LDFLAGS} ${GCFLAGS} -o bin/$${b} $$d || ret=$$? ; \ done ; exit $$ret @echo "build Success!" diff --git a/advisor/rules.go b/advisor/rules.go index 192be66..8614cb6 100644 --- a/advisor/rules.go +++ b/advisor/rules.go @@ -549,7 +549,7 @@ func init() { Item: "COL.016", Severity: "L1", Summary: "整型定义建议采用 INT(10) 或 BIGINT(20)", - Content: `INT(M) 在 integer 数据类型中,M 表示最大显示宽度。 在 INT(M) 中,M 的值跟 INT(M) 所占多少存储空间并无任何关系。 INT(3)、INT(4)、INT(8) 在磁盘上都是占用 4 bytes 的存储空间。`, + Content: `INT(M) 在 integer 数据类型中,M 表示最大显示宽度。 在 INT(M) 中,M 的值跟 INT(M) 所占多少存储空间并无任何关系。 INT(3)、INT(4)、INT(8) 在磁盘上都是占用 4 bytes 的存储空间。高版本 MySQL 已经不推荐设置整数显示宽度。`, Case: "CREATE TABLE tab (a INT(1));", Func: (*Query4Audit).RuleIntPrecision, }, diff --git a/common/version.go b/common/version.go new file mode 100644 index 0000000..85772ce --- /dev/null +++ b/common/version.go @@ -0,0 +1,10 @@ +package common + +// -version输出信息 +var ( + Version = "No Version Provided" + Compile = "" + Branch = "" + GitDirty = "" + DevPath = "" +) diff --git a/doc/heuristic.md b/doc/heuristic.md index 574ef79..91ad11d 100644 --- a/doc/heuristic.md +++ b/doc/heuristic.md @@ -506,7 +506,7 @@ CREATE TABLE `tbl` (`c` blob DEFAULT NULL); * **Item**:COL.016 * **Severity**:L1 -* **Content**:INT(M) 在 integer 数据类型中,M 表示最大显示宽度。 在 INT(M) 中,M 的值跟 INT(M) 所占多少存储空间并无任何关系。 INT(3)、INT(4)、INT(8) 在磁盘上都是占用 4 bytes 的存储空间。 +* **Content**:INT(M) 在 integer 数据类型中,M 表示最大显示宽度。 在 INT(M) 中,M 的值跟 INT(M) 所占多少存储空间并无任何关系。 INT(3)、INT(4)、INT(8) 在磁盘上都是占用 4 bytes 的存储空间。高版本 MySQL 已经不推荐设置整数显示宽度。 * **Case**: ```sql diff --git a/genver.sh b/genver.sh deleted file mode 100755 index 9495ff6..0000000 --- a/genver.sh +++ /dev/null @@ -1,38 +0,0 @@ -#!/bin/bash - -## Generate Repository Version -tag="$(git describe --tags --always)" -version="$(git log --date=iso --pretty=format:"%cd" -1) ${tag}" -if [ "X${version}" == "X" ]; then - version="not a git repo" - tag="not a git repo" -fi - -git_dirty=$(git diff --no-ext-diff 2>/dev/null | wc -l) - -compile="$(date +"%F %T %z") by $(go version)" - -branch=$(git rev-parse --abbrev-ref HEAD) - -dev_path=$( - cd "$(dirname "$0")" || exit - pwd -) - -cat <common/version.go -package common - -// -version输出信息 -const ( - Version = "${version}" - Compile = "${compile}" - Branch = "${branch}" - GitDirty= ${git_dirty} - DevPath = "${dev_path}" -) -EOF - -XIAOMI=$(git ls-remote --get-url | grep XiaoMi) -if [ "x${XIAOMI}" != "x" ]; then - echo "${tag}" | awk -F '-' '{print $1}' > VERSION -fi -- GitLab