Skip to content

Commit

Permalink
br: let tools use the same version detecting mechanism (#27060) (#27145)
Browse files Browse the repository at this point in the history
  • Loading branch information
ti-srebot authored Aug 13, 2021
1 parent ab167f8 commit 4c68def
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 30 deletions.
10 changes: 5 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -243,16 +243,16 @@ br_web:
@cd br/web && npm install && npm run build

build_br:
CGO_ENABLED=1 $(GOBUILD) $(RACE_FLAG) -ldflags '$(TOOL_LDFLAGS) $(CHECK_FLAG)' -o $(BR_BIN) br/cmd/br/*.go
CGO_ENABLED=1 $(GOBUILD) $(RACE_FLAG) -ldflags '$(LDFLAGS) $(CHECK_FLAG)' -o $(BR_BIN) br/cmd/br/*.go

build_lightning_for_web:
CGO_ENABLED=1 $(GOBUILD) -tags dev $(RACE_FLAG) -ldflags '$(TOOL_LDFLAGS) $(CHECK_FLAG)' -o $(LIGHTNING_BIN) br/cmd/tidb-lightning/main.go
CGO_ENABLED=1 $(GOBUILD) -tags dev $(RACE_FLAG) -ldflags '$(LDFLAGS) $(CHECK_FLAG)' -o $(LIGHTNING_BIN) br/cmd/tidb-lightning/main.go

build_lightning:
CGO_ENABLED=1 $(GOBUILD) $(RACE_FLAG) -ldflags '$(TOOL_LDFLAGS) $(CHECK_FLAG)' -o $(LIGHTNING_BIN) br/cmd/tidb-lightning/main.go
CGO_ENABLED=1 $(GOBUILD) $(RACE_FLAG) -ldflags '$(LDFLAGS) $(CHECK_FLAG)' -o $(LIGHTNING_BIN) br/cmd/tidb-lightning/main.go

build_lightning-ctl:
CGO_ENABLED=1 $(GOBUILD) $(RACE_FLAG) -ldflags '$(TOOL_LDFLAGS) $(CHECK_FLAG)' -o $(LIGHTNING_CTL_BIN) br/cmd/tidb-lightning-ctl/main.go
CGO_ENABLED=1 $(GOBUILD) $(RACE_FLAG) -ldflags '$(LDFLAGS) $(CHECK_FLAG)' -o $(LIGHTNING_CTL_BIN) br/cmd/tidb-lightning-ctl/main.go

build_for_br_integration_test:
@make failpoint-enable
Expand All @@ -279,7 +279,7 @@ build_for_br_integration_test:
br_unit_test: export ARGS=$$($(BR_PACKAGES))
br_unit_test:
@make failpoint-enable
$(GOTEST) $(RACE_FLAG) -tags leak $(ARGS) || ( make failpoint-disable && exit 1 )
$(GOTEST) $(RACE_FLAG) -ldflags '$(LDFLAGS)' -tags leak $(ARGS) || ( make failpoint-disable && exit 1 )
@make failpoint-disable

br_integration_test: br_bins build_br build_for_br_integration_test
Expand Down
21 changes: 0 additions & 21 deletions Makefile.common
Original file line number Diff line number Diff line change
Expand Up @@ -87,24 +87,3 @@ LIGHTNING_BIN := bin/tidb-lightning
LIGHTNING_CTL_BIN := bin/tidb-lightning-ctl
BR_BIN := bin/br
TEST_DIR := /tmp/backup_restore_test

TOOL_RELEASE_VERSION =
ifeq ($(TOOL_RELEASE_VERSION),)
TOOL_RELEASE_VERSION := v4.0.0-dev
release_version_regex := ^v4\..*$$
release_branch_regex := "^release-[0-9]\.[0-9].*$$|^HEAD$$|^.*/*tags/v[0-9]\.[0-9]\..*$$"
ifneq ($(shell git rev-parse --abbrev-ref HEAD | egrep $(release_branch_regex)),)
# If we are in release branch, try to use tag version.
ifneq ($(shell git describe --tags --dirty | egrep $(release_version_regex)),)
TOOL_RELEASE_VERSION := $(shell git describe --tags --dirty)
endif
else ifneq ($(shell git status --porcelain),)
# Add -dirty if the working tree is dirty for non release branch.
TOOL_RELEASE_VERSION := $(TOOL_RELEASE_VERSION)-dirty
endif
endif

TOOL_LDFLAGS += -X "$(BR_PKG)/pkg/version/build.ReleaseVersion=$(TOOL_RELEASE_VERSION)"
TOOL_LDFLAGS += -X "$(BR_PKG)/pkg/version/build.BuildTS=$(shell date -u '+%Y-%m-%d %I:%M:%S')"
TOOL_LDFLAGS += -X "$(BR_PKG)/pkg/version/build.GitHash=$(shell git rev-parse HEAD)"
TOOL_LDFLAGS += -X "$(BR_PKG)/pkg/version/build.GitBranch=$(shell git rev-parse --abbrev-ref HEAD)"
17 changes: 13 additions & 4 deletions br/pkg/version/build/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,28 @@ import (
"runtime"

"github.com/pingcap/log"
"github.com/pingcap/parser/mysql"
"github.com/pingcap/tidb/util/israce"
"github.com/pingcap/tidb/util/versioninfo"
"go.uber.org/zap"
)

// Version information.
var (
ReleaseVersion = "v5.0.0-master"
BuildTS = "None"
GitHash = "None"
GitBranch = "None"
ReleaseVersion = getReleaseVersion()
BuildTS = versioninfo.TiDBBuildTS
GitHash = versioninfo.TiDBGitHash
GitBranch = versioninfo.TiDBGitBranch
goVersion = runtime.Version()
)

func getReleaseVersion() string {
if mysql.TiDBReleaseVersion != "None" {
return mysql.TiDBReleaseVersion
}
return "v5.0.0-master"
}

// AppName is a name of a built binary.
type AppName string

Expand Down

0 comments on commit 4c68def

Please sign in to comment.