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