@@ -37,7 +37,23 @@ TLS_CA ?=
3737TLS_CERT ?=
3838TLS_KEY ?=
3939
40- LDFLAGS += -X "github.com/tikv/migration/br/pkg/version/build.ReleaseVersion=$(shell git describe --tags --dirty --always) "
40+ RELEASE_VERSION ?=
41+ ifeq ($(RELEASE_VERSION ) ,)
42+ RELEASE_VERSION := br-v1.1-master
43+ release_version_regex := ^br-v[0-9]\..*$$
44+ release_branch_regex := "^br-[0-9]\.[0-9].*$$|^HEAD$$|^.*/*tags/br-v[0-9]\.[0-9]\..*$$"
45+ ifneq ($(shell git rev-parse --abbrev-ref HEAD | egrep $(release_branch_regex)),)
46+ # If we are in release branch, try to use tag version.
47+ ifneq ($(shell git describe --tags --dirty | egrep $(release_version_regex)),)
48+ RELEASE_VERSION := $(shell git describe --tags --dirty)
49+ endif
50+ else ifneq ($(shell git status --porcelain),)
51+ # Add -dirty if the working tree is dirty for non release branch.
52+ RELEASE_VERSION := $(RELEASE_VERSION)-dirty
53+ endif
54+ endif
55+
56+ LDFLAGS += -X "github.com/tikv/migration/br/pkg/version/build.ReleaseVersion=$(RELEASE_VERSION ) "
4157LDFLAGS += -X "github.com/tikv/migration/br/pkg/version/build.BuildTS=$(shell date -u '+% Y-% m-% d % H:% M:% S') "
4258LDFLAGS += -X "github.com/tikv/migration/br/pkg/version/build.GitHash=$(shell git rev-parse HEAD) "
4359LDFLAGS += -X "github.com/tikv/migration/br/pkg/version/build.GitBranch=$(shell git rev-parse --abbrev-ref HEAD) "
@@ -94,10 +110,10 @@ tools/bin/failpoint-ctl: tools/check/go.mod
94110 cd tools/check && $(GO ) build -o ../bin/failpoint-ctl github.com/pingcap/failpoint/failpoint-ctl
95111
96112build :
97- CGO_ENABLED=1 $(GO ) build -tags codes -gcflags " all=-N -l" -ldflags ' $(LDFLAGS)' -o $(BR_BIN_PATH ) cmd/br/* .go
113+ CGO_ENABLED=0 $(GO ) build -tags codes -gcflags " all=-N -l" -ldflags ' $(LDFLAGS)' -o $(BR_BIN_PATH ) cmd/br/* .go
98114
99115release :
100- CGO_ENABLED=1 GOOS=$(TARGET_OS ) GOARCH=$(TARGET_ARCH ) $(GO ) build -tags codes -ldflags ' $(LDFLAGS)' -o $(BR_BIN_PATH ) cmd/br/* .go
116+ CGO_ENABLED=0 GOOS=$(TARGET_OS ) GOARCH=$(TARGET_ARCH ) $(GO ) build -tags codes -ldflags ' $(LDFLAGS)' -o $(BR_BIN_PATH ) cmd/br/* .go
101117
102118build/rawkv-integration-test :
103119 cd tests/rawkv && $(GO ) build -mod=mod -o ../../bin/rawkv_test * .go
0 commit comments