Skip to content

Commit

Permalink
printer: print commit hash version for extensions (#43095)
Browse files Browse the repository at this point in the history
close #43096
  • Loading branch information
CbcWestwolf authored Apr 20, 2023
1 parent d547306 commit b2853fd
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 9 deletions.
16 changes: 11 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -159,23 +159,29 @@ else
CGO_ENABLED=1 $(GOBUILD) -gcflags="all=-N -l" $(RACE_FLAG) -ldflags '$(LDFLAGS) $(CHECK_FLAG)' -o '$(TARGET)' ./tidb-server
endif

init-submodule:
git submodule init && git submodule update --force

enterprise-prepare:
git submodule init && git submodule update && cd extension/enterprise/generate && $(GO) generate -run genfile main.go
cd extension/enterprise/generate && $(GO) generate -run genfile main.go

enterprise-clear:
cd extension/enterprise/generate && $(GO) generate -run clear main.go

enterprise-docker: enterprise-prepare
enterprise-docker: init-submodule enterprise-prepare
docker build -t "$(DOCKERPREFIX)tidb:latest" --build-arg 'GOPROXY=$(shell go env GOPROXY),' -f Dockerfile.enterprise .

enterprise-server-build:
ifeq ($(TARGET), "")
CGO_ENABLED=1 $(GOBUILD) -tags enterprise $(RACE_FLAG) -ldflags '$(LDFLAGS) $(CHECK_FLAG)' -o bin/tidb-server tidb-server/main.go
CGO_ENABLED=1 $(GOBUILD) -tags enterprise $(RACE_FLAG) -ldflags '$(LDFLAGS) $(CHECK_FLAG) $(EXTENSION_FLAG)' -o bin/tidb-server tidb-server/main.go
else
CGO_ENABLED=1 $(GOBUILD) -tags enterprise $(RACE_FLAG) -ldflags '$(LDFLAGS) $(CHECK_FLAG)' -o '$(TARGET)' tidb-server/main.go
CGO_ENABLED=1 $(GOBUILD) -tags enterprise $(RACE_FLAG) -ldflags '$(LDFLAGS) $(CHECK_FLAG) $(EXTENSION_FLAG)' -o '$(TARGET)' tidb-server/main.go
endif

enterprise-server: enterprise-prepare enterprise-server-build
enterprise-server:
@make init-submodule
@make enterprise-prepare
@make enterprise-server-build

server_check:
ifeq ($(TARGET), "")
Expand Down
5 changes: 5 additions & 0 deletions Makefile.common
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@ LDFLAGS += -X "github.com/pingcap/tidb/util/versioninfo.TiDBGitHash=$(shell git
LDFLAGS += -X "github.com/pingcap/tidb/util/versioninfo.TiDBGitBranch=$(shell git rev-parse --abbrev-ref HEAD)"
LDFLAGS += -X "github.com/pingcap/tidb/util/versioninfo.TiDBEdition=$(TIDB_EDITION)"

EXTENSION_FLAG =
ifeq ($(shell if [ -a extension/enterprise/.git ]; then echo "true"; fi),true)
EXTENSION_FLAG += -X "github.com/pingcap/tidb/util/versioninfo.TiDBEnterpriseExtensionGitHash=$(shell cd extension/enterprise && git rev-parse HEAD)"
endif

TEST_LDFLAGS = -X "github.com/pingcap/tidb/config.checkBeforeDropLDFlag=1"
COVERAGE_SERVER_LDFLAGS = -X "github.com/pingcap/tidb/tidb-server.isCoverageServer=1"

Expand Down
5 changes: 5 additions & 0 deletions build/print-workspace-status.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,16 @@ TiDB_BUILD_UTCTIME=$(date -u '+%Y-%m-%d %H:%M:%S')
TIDB_GIT_HASH=$(git rev-parse HEAD)
TIDB_GIT_BRANCH=$(git rev-parse --abbrev-ref HEAD)
TIDB_EDITION=${TIDB_EDITION:-Community}
TIDB_ENTERPRISE_EXTENSION_GIT_HASH=""
if [ -a "extension/enterprise/.git" ]; then
TIDB_ENTERPRISE_EXTENSION_GIT_HASH=$(cd extension/enterprise && git rev-parse HEAD)
fi

cat <<EOF
STABLE_TiDB_RELEASE_VERSION ${TiDB_RELEASE_VERSION}
STABLE_TiDB_BUILD_UTCTIME ${TiDB_BUILD_UTCTIME}
STABLE_TIDB_GIT_HASH ${TIDB_GIT_HASH}
STABLE_TIDB_GIT_BRANCH ${TIDB_GIT_BRANCH}
STABLE_TIDB_EDITION ${TIDB_EDITION}
STABLE_TIDB_ENTERPRISE_EXTENSION_GIT_HASH ${TIDB_ENTERPRISE_EXTENSION_GIT_HASH}
EOF
1 change: 1 addition & 0 deletions tidb-server/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ go_binary(
"github.com/pingcap/tidb/parser/mysql.TiDBReleaseVersion": "{STABLE_TiDB_RELEASE_VERSION}",
"github.com/pingcap/tidb/util/versioninfo.TiDBBuildTS": "{STABLE_TiDB_BUILD_UTCTIME}",
"github.com/pingcap/tidb/util/versioninfo.TiDBGitHash": "{STABLE_TIDB_GIT_HASH}",
"github.com/pingcap/tidb/util/versioninfo.TiDBEnterpriseExtensionGitHash": "{STABLE_TIDB_ENTERPRISE_EXTENSION_GIT_HASH}",
"github.com/pingcap/tidb/util/versioninfo.TiDBGitBranch": "{STABLE_TIDB_GIT_BRANCH}",
"github.com/pingcap/tidb/util/versioninfo.TiDBEdition": "{STABLE_TIDB_EDITION}",
},
Expand Down
17 changes: 14 additions & 3 deletions util/printer/printer.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import (

// PrintTiDBInfo prints the TiDB version information.
func PrintTiDBInfo() {
logutil.BgLogger().Info("Welcome to TiDB.",
fields := []zap.Field{
zap.String("Release Version", mysql.TiDBReleaseVersion),
zap.String("Edition", versioninfo.TiDBEdition),
zap.String("Git Commit Hash", versioninfo.TiDBGitHash),
Expand All @@ -40,7 +40,12 @@ func PrintTiDBInfo() {
zap.String("GoVersion", buildVersion),
zap.Bool("Race Enabled", israce.RaceEnabled),
zap.Bool("Check Table Before Drop", config.CheckTableBeforeDrop),
zap.String("TiKV Min Version", versioninfo.TiKVMinVersion))
zap.String("TiKV Min Version", versioninfo.TiKVMinVersion),
}
if versioninfo.TiDBEnterpriseExtensionGitHash != "" {
fields = append(fields, zap.String("Enterprise Extension Commit Hash", versioninfo.TiDBEnterpriseExtensionGitHash))
}
logutil.BgLogger().Info("Welcome to TiDB.", fields...)
configJSON, err := json.Marshal(config.GetGlobalConfig())
if err != nil {
panic(err)
Expand All @@ -50,6 +55,10 @@ func PrintTiDBInfo() {

// GetTiDBInfo returns the git hash and build time of this tidb-server binary.
func GetTiDBInfo() string {
enterpriseVersion := ""
if versioninfo.TiDBEnterpriseExtensionGitHash != "" {
enterpriseVersion = fmt.Sprintf("\nEnterprise Extension Commit Hash: %s", versioninfo.TiDBEnterpriseExtensionGitHash)
}
return fmt.Sprintf("Release Version: %s\n"+
"Edition: %s\n"+
"Git Commit Hash: %s\n"+
Expand All @@ -59,7 +68,8 @@ func GetTiDBInfo() string {
"Race Enabled: %v\n"+
"TiKV Min Version: %s\n"+
"Check Table Before Drop: %v\n"+
"Store: %s",
"Store: %s"+
"%s",
mysql.TiDBReleaseVersion,
versioninfo.TiDBEdition,
versioninfo.TiDBGitHash,
Expand All @@ -70,6 +80,7 @@ func GetTiDBInfo() string {
versioninfo.TiKVMinVersion,
config.CheckTableBeforeDrop,
config.GetGlobalConfig().Store,
enterpriseVersion,
)
}

Expand Down
3 changes: 2 additions & 1 deletion util/versioninfo/versioninfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,6 @@ var (
TiDBGitBranch = "None"
TiDBEdition = CommunityEdition
// TiKVMinVersion is the minimum version of TiKV that can be compatible with the current TiDB.
TiKVMinVersion = "6.2.0-alpha"
TiKVMinVersion = "6.2.0-alpha"
TiDBEnterpriseExtensionGitHash = ""
)

0 comments on commit b2853fd

Please sign in to comment.