github.com/pingcap/ticdc@v0.0.0-20220526033649-485a10ef2652/Makefile (about)

     1  ### Makefile for ticdc
     2  .PHONY: build test check clean fmt cdc kafka_consumer coverage \
     3  	integration_test_build integration_test integration_test_mysql integration_test_kafka
     4  
     5  PROJECT=ticdc
     6  
     7  FAIL_ON_STDOUT := awk '{ print  } END { if (NR > 0) { exit 1  }  }'
     8  
     9  CURDIR := $(shell pwd)
    10  path_to_add := $(addsuffix /bin,$(subst :,/bin:,$(GOPATH)))
    11  export PATH := $(path_to_add):$(PATH)
    12  
    13  TEST_DIR := /tmp/tidb_cdc_test
    14  SHELL	 := /usr/bin/env bash
    15  
    16  GO       := GO111MODULE=on go
    17  ifeq (${CDC_ENABLE_VENDOR}, 1)
    18  GOVENDORFLAG := -mod=vendor
    19  endif
    20  
    21  GOBUILD  := CGO_ENABLED=0 $(GO) build $(BUILD_FLAG) -trimpath $(GOVENDORFLAG)
    22  GOBUILDNOVENDOR  := CGO_ENABLED=0 $(GO) build $(BUILD_FLAG) -trimpath
    23  ifeq ($(GOVERSION114), 1)
    24  GOTEST   := CGO_ENABLED=1 $(GO) test -p 3 --race -gcflags=all=-d=checkptr=0
    25  else
    26  GOTEST   := CGO_ENABLED=1 $(GO) test -p 3 --race
    27  endif
    28  
    29  ARCH  := "`uname -s`"
    30  LINUX := "Linux"
    31  MAC   := "Darwin"
    32  PACKAGE_LIST := go list ./...| grep -vE 'vendor|proto|ticdc\/tests|integration|testing_utils'
    33  PACKAGES  := $$($(PACKAGE_LIST))
    34  PACKAGE_DIRECTORIES := $(PACKAGE_LIST) | sed 's|github.com/pingcap/$(PROJECT)/||'
    35  FILES := $$(find . -name '*.go' -type f | grep -vE 'vendor|kv_gen|proto')
    36  TEST_FILES := $$(find . -name '*_test.go' -type f | grep -vE 'vendor|kv_gen|integration|testing_utils')
    37  CDC_PKG := github.com/pingcap/ticdc
    38  FAILPOINT_DIR := $$(for p in $(PACKAGES); do echo $${p\#"github.com/pingcap/$(PROJECT)/"}|grep -v "github.com/pingcap/$(PROJECT)"; done)
    39  FAILPOINT := bin/failpoint-ctl
    40  
    41  FAILPOINT_ENABLE  := $$(echo $(FAILPOINT_DIR) | xargs $(FAILPOINT) enable >/dev/null)
    42  FAILPOINT_DISABLE := $$(find $(FAILPOINT_DIR) | xargs $(FAILPOINT) disable >/dev/null)
    43  
    44  RELEASE_VERSION =
    45  ifeq ($(RELEASE_VERSION),)
    46  	RELEASE_VERSION := v5.0.0-dev
    47  	release_version_regex := ^v5\..*$$
    48  	release_branch_regex := "^release-[0-9]\.[0-9].*$$|^HEAD$$|^.*/*tags/v[0-9]\.[0-9]\..*$$"
    49  	ifneq ($(shell git rev-parse --abbrev-ref HEAD | egrep $(release_branch_regex)),)
    50  		# If we are in release branch, try to use tag version.
    51  		ifneq ($(shell git describe --tags --dirty | egrep $(release_version_regex)),)
    52  			RELEASE_VERSION := $(shell git describe --tags --dirty)
    53  		endif
    54  	else ifneq ($(shell git status --porcelain),)
    55  		# Add -dirty if the working tree is dirty for non release branch.
    56  		RELEASE_VERSION := $(RELEASE_VERSION)-dirty
    57  	endif
    58  endif
    59  
    60  LDFLAGS += -X "$(CDC_PKG)/pkg/version.ReleaseVersion=$(RELEASE_VERSION)"
    61  LDFLAGS += -X "$(CDC_PKG)/pkg/version.BuildTS=$(shell date -u '+%Y-%m-%d %H:%M:%S')"
    62  LDFLAGS += -X "$(CDC_PKG)/pkg/version.GitHash=$(shell git rev-parse HEAD)"
    63  LDFLAGS += -X "$(CDC_PKG)/pkg/version.GitBranch=$(shell git rev-parse --abbrev-ref HEAD)"
    64  LDFLAGS += -X "$(CDC_PKG)/pkg/version.GoVersion=$(shell go version)"
    65  
    66  default: build buildsucc
    67  
    68  buildsucc:
    69  	@echo Build TiDB CDC successfully!
    70  
    71  all: dev install
    72  
    73  dev: check test
    74  
    75  test: unit_test
    76  
    77  build: cdc
    78  
    79  build-failpoint:
    80  	$(FAILPOINT_ENABLE)
    81  	$(GOBUILD) -ldflags '$(LDFLAGS)' -o bin/cdc ./cmd/cdc/main.go
    82  	$(FAILPOINT_DISABLE)
    83  
    84  cdc:
    85  	$(GOBUILD) -ldflags '$(LDFLAGS)' -o bin/cdc ./cmd/cdc/main.go
    86  
    87  kafka_consumer:
    88  	$(GOBUILD) -ldflags '$(LDFLAGS)' -o bin/cdc_kafka_consumer ./cmd/kafka-consumer/main.go
    89  
    90  install:
    91  	go install ./...
    92  
    93  unit_test: check_failpoint_ctl
    94  	./scripts/fix_lib_zstd.sh
    95  	mkdir -p "$(TEST_DIR)"
    96  	$(FAILPOINT_ENABLE)
    97  	@export log_level=error;\
    98  	$(GOTEST) -cover -covermode=atomic -coverprofile="$(TEST_DIR)/cov.unit.out" $(PACKAGES) \
    99  	|| { $(FAILPOINT_DISABLE); exit 1; }
   100  	$(FAILPOINT_DISABLE)
   101  
   102  leak_test: check_failpoint_ctl
   103  	./scripts/fix_lib_zstd.sh
   104  	$(FAILPOINT_ENABLE)
   105  	@export log_level=error;\
   106  	$(GOTEST) -count=1 --tags leak $(PACKAGES) || { $(FAILPOINT_DISABLE); exit 1; }
   107  	$(FAILPOINT_DISABLE)
   108  
   109  check_failpoint_ctl:
   110  	which $(FAILPOINT) >/dev/null 2>&1 || $(GOBUILDNOVENDOR) -o $(FAILPOINT) github.com/pingcap/failpoint/failpoint-ctl
   111  
   112  check_third_party_binary:
   113  	@which bin/tidb-server
   114  	@which bin/tikv-server
   115  	@which bin/pd-server
   116  	@which bin/tiflash
   117  	@which bin/pd-ctl
   118  	@which bin/sync_diff_inspector
   119  	@which bin/go-ycsb
   120  	@which bin/etcdctl
   121  	@which bin/jq
   122  	@which bin/minio
   123  
   124  integration_test_build: check_failpoint_ctl
   125  	./scripts/fix_lib_zstd.sh
   126  	$(FAILPOINT_ENABLE)
   127  	$(GOTEST) -ldflags '$(LDFLAGS)' -c -cover -covermode=atomic \
   128  		-coverpkg=github.com/pingcap/ticdc/... \
   129  		-o bin/cdc.test github.com/pingcap/ticdc/cmd/cdc \
   130  	|| { $(FAILPOINT_DISABLE); exit 1; }
   131  	$(GOBUILD) -ldflags '$(LDFLAGS)' -o bin/cdc ./cmd/cdc/main.go \
   132  	|| { $(FAILPOINT_DISABLE); exit 1; }
   133  	$(FAILPOINT_DISABLE)
   134  
   135  integration_test: integration_test_mysql
   136  
   137  integration_test_mysql:
   138  	tests/run.sh mysql "$(CASE)"
   139  
   140  integration_test_kafka: check_third_party_binary
   141  	tests/run.sh kafka "$(CASE)"
   142  
   143  fmt: tools/bin/gofumports
   144  	@echo "gofmt (simplify)"
   145  	tools/bin/gofumports -s -l -w $(FILES) 2>&1 | $(FAIL_ON_STDOUT)
   146  
   147  lint: tools/bin/revive
   148  	@echo "linting"
   149  	@tools/bin/revive -formatter friendly -config tools/check/revive.toml $(FILES)
   150  
   151  errdoc: tools/bin/errdoc-gen
   152  	@echo "generator errors.toml"
   153  	./tools/check/check-errdoc.sh
   154  
   155  check-copyright:
   156  	@echo "check-copyright"
   157  	@./scripts/check-copyright.sh
   158  
   159  check-merge-conflicts:
   160  	@echo "check-merge-conflicts"
   161  	@./scripts/check-merge-conflicts.sh
   162  
   163  check-leaktest-added: tools/bin/gofumports
   164  	@echo "check leak test added in all unit tests"
   165  	./scripts/add-leaktest.sh $(TEST_FILES)
   166  
   167  vet:
   168  	@echo "vet"
   169  	$(GO) vet $(PACKAGES) 2>&1 | $(FAIL_ON_STDOUT)
   170  
   171  tidy:
   172  	@echo "go mod tidy"
   173  	./tools/check/check-tidy.sh
   174  
   175  check: check-copyright fmt lint check-static tidy errdoc check-leaktest-added check-merge-conflicts
   176  
   177  coverage:
   178  	GO111MODULE=off go get github.com/wadey/gocovmerge
   179  	gocovmerge "$(TEST_DIR)"/cov.* | grep -vE ".*.pb.go|$(CDC_PKG)/testing_utils/.*|$(CDC_PKG)/cdc/kv/testing.go|$(CDC_PKG)/cdc/entry/schema_test_helper.go|$(CDC_PKG)/cdc/sink/simple_mysql_tester.go|.*.__failpoint_binding__.go" > "$(TEST_DIR)/all_cov.out"
   180  	grep -vE ".*.pb.go|$(CDC_PKG)/testing_utils/.*|$(CDC_PKG)/cdc/kv/testing.go|$(CDC_PKG)/cdc/sink/simple_mysql_tester.go|.*.__failpoint_binding__.go" "$(TEST_DIR)/cov.unit.out" > "$(TEST_DIR)/unit_cov.out"
   181  ifeq ("$(JenkinsCI)", "1")
   182  	GO111MODULE=off go get github.com/mattn/goveralls
   183  	@goveralls -coverprofile=$(TEST_DIR)/all_cov.out -service=jenkins-ci -repotoken $(COVERALLS_TOKEN)
   184  	@bash <(curl -s https://codecov.io/bash) -f $(TEST_DIR)/unit_cov.out -t $(CODECOV_TOKEN)
   185  else
   186  	go tool cover -html "$(TEST_DIR)/all_cov.out" -o "$(TEST_DIR)/all_cov.html"
   187  	go tool cover -html "$(TEST_DIR)/unit_cov.out" -o "$(TEST_DIR)/unit_cov.html"
   188  	go tool cover -func="$(TEST_DIR)/unit_cov.out"
   189  endif
   190  
   191  check-static: tools/bin/golangci-lint
   192  	tools/bin/golangci-lint run --timeout 10m0s --skip-files kv_gen
   193  
   194  data-flow-diagram: docs/data-flow.dot
   195  	dot -Tsvg docs/data-flow.dot > docs/data-flow.svg
   196  
   197  clean:
   198  	go clean -i ./...
   199  	rm -rf *.out
   200  	rm -f bin/cdc
   201  	rm -f bin/cdc_kafka_consumer
   202  
   203  tools/bin/gofumports: tools/check/go.mod
   204  	cd tools/check; test -e ../bin/gofumports || \
   205  	$(GO) build -o ../bin/gofumports mvdan.cc/gofumpt
   206  
   207  tools/bin/revive: tools/check/go.mod
   208  	cd tools/check; test -e ../bin/revive || \
   209  	$(GO) build -o ../bin/revive github.com/mgechev/revive
   210  
   211  tools/bin/errdoc-gen: tools/check/go.mod
   212  	cd tools/check; test -e ../bin/errdoc-gen || \
   213  	$(GO) build -o ../bin/errdoc-gen github.com/pingcap/errors/errdoc-gen
   214  
   215  tools/bin/golangci-lint:
   216  	cd tools/check; test -e ../bin/golangci-lint || \
   217  	curl -sfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh| sh -s -- -b ../bin v1.30.0
   218  
   219  failpoint-enable: check_failpoint_ctl
   220  	$(FAILPOINT_ENABLE)
   221  
   222  failpoint-disable: check_failpoint_ctl
   223  	$(FAILPOINT_DISABLE)