| 1 |
### Makefile for failpoint-ctl |
| 2 |
|
| 3 |
LDFLAGS += -X "github.com/pingcap/failpoint/failpoint-ctl/version.releaseVersion=$(shell git describe --tags --dirty="-dev" --always)" |
| 4 |
LDFLAGS += -X "github.com/pingcap/failpoint/failpoint-ctl/version.buildTS=$(shell date -u '+%Y-%m-%d %I:%M:%S')" |
| 5 |
LDFLAGS += -X "github.com/pingcap/failpoint/failpoint-ctl/version.gitHash=$(shell git rev-parse HEAD)" |
| 6 |
LDFLAGS += -X "github.com/pingcap/failpoint/failpoint-ctl/version.gitBranch=$(shell git rev-parse --abbrev-ref HEAD)" |
| 7 |
LDFLAGS += -X "github.com/pingcap/failpoint/failpoint-ctl/version.goVersion=$(shell go version)" |
| 8 |
|
| 9 |
FAILPOINT_CTL_BIN := bin/failpoint-ctl |
| 10 |
FAILPOINT_TOOLEXEC_BIN := bin/failpoint-toolexec |
| 11 |
|
| 12 |
path_to_add := $(addsuffix /bin,$(subst :,/bin:,$(GOPATH))) |
| 13 |
export PATH := $(path_to_add):$(PATH):$(shell pwd)/tools/bin |
| 14 |
|
| 15 |
GO := GO111MODULE=on go |
| 16 |
GOBUILD := GO111MODULE=on CGO_ENABLED=0 $(GO) build |
| 17 |
GOTEST := GO111MODULE=on GO_FAILPOINTS="failpoint-env1=return(10);failpoint-env2=return(true)" CGO_ENABLED=1 $(GO) test -p 4 |
| 18 |
|
| 19 |
ARCH := "`uname -s`" |
| 20 |
LINUX := "Linux" |
| 21 |
MAC := "Darwin" |
| 22 |
|
| 23 |
RACE_FLAG = |
| 24 |
ifeq ("$(WITH_RACE)", "1") |
| 25 |
RACE_FLAG = -race |
| 26 |
GOBUILD = GOPATH=$(GOPATH) CGO_ENABLED=1 $(GO) build |
| 27 |
endif |
| 28 |
|
| 29 |
.PHONY: build checksuccess test cover upload-cover gotest check-static |
| 30 |
|
| 31 |
default: build checksuccess |
| 32 |
|
| 33 |
build: |
| 34 |
$(GOBUILD) $(RACE_FLAG) -ldflags '$(LDFLAGS)' -o $(FAILPOINT_CTL_BIN) failpoint-ctl/main.go |
| 35 |
$(GOBUILD) $(RACE_FLAG) -ldflags '$(LDFLAGS)' -o $(FAILPOINT_TOOLEXEC_BIN) failpoint-toolexec/main.go |
| 36 |
|
| 37 |
checksuccess: |
| 38 |
@if [ -f $(FAILPOINT_CTL_BIN) ]; \ |
| 39 |
then \ |
| 40 |
echo "failpoint-ctl build successfully :-) !" ; \ |
| 41 |
fi |
| 42 |
@if [ -f $(FAILPOINT_TOOLEXEC_BIN) ]; \ |
| 43 |
then \ |
| 44 |
echo "failpoint-toolexec build successfully :-) !" ; \ |
| 45 |
fi |
| 46 |
|
| 47 |
test: gotest check-static |
| 48 |
|
| 49 |
check-static: tools/bin/gometalinter |
| 50 |
@ # TODO: enable megacheck. |
| 51 |
@ # TODO: gometalinter has been DEPRECATED. |
| 52 |
@ # https://github.com/alecthomas/gometalinter/issues/590 |
| 53 |
@ echo "----------- static check ---------------" |
| 54 |
tools/bin/gometalinter --disable-all --deadline 120s \ |
| 55 |
--enable gofmt \ |
| 56 |
--enable misspell \ |
| 57 |
--enable ineffassign \ |
| 58 |
./... |
| 59 |
@ # TODO --enable errcheck |
| 60 |
@ # TODO --enable golint |
| 61 |
|
| 62 |
gotest: |
| 63 |
@ echo "----------- go test ---------------" |
| 64 |
$(GOTEST) -covermode=atomic -coverprofile=coverage.txt -coverpkg=./... -v $(go list ./... | grep -v examples) |
| 65 |
|
| 66 |
tools/bin/gometalinter: |
| 67 |
cd tools; \ |
| 68 |
curl -L https://git.io/vp6lP | sh |
| 69 |
|
| 70 |
test-examples: |
| 71 |
@ echo "----------- go test examples ---------------" |
| 72 |
$(GO) run failpoint-ctl/main.go enable ./examples |
| 73 |
$(GOTEST) -covermode=atomic -coverprofile=coverage.txt -coverpkg=./... -v ./examples/... |
| 74 |
$(GO) run failpoint-ctl/main.go disable ./examples |
| 75 |
|
| 76 |
test-examples-toolexec: build |
| 77 |
@ echo "----------- go test examples using toolexec ---------------" |
| 78 |
GOCACHE=/tmp/failpoint-cache $(GOTEST) -covermode=atomic -coverprofile=coverage.txt -coverpkg=./... -toolexec="$(PWD)/bin/failpoint-toolexec" -v ./examples/... |