forked from uber-go/cadence-client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
181 lines (142 loc) · 6.43 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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
.PHONY: git-submodules test bins clean cover cover_ci
# default target
default: test
IMPORT_ROOT := go.uber.org/cadence
THRIFT_GENDIR := .gen/go
THRIFTRW_SRC := idls/thrift/cadence.thrift
# one or more thriftrw-generated file(s), to create / depend on generated code
THRIFTRW_OUT := $(THRIFT_GENDIR)/cadence/idl.go
TEST_ARG ?= -v -race
# general build-product folder, cleaned as part of `make clean`
BUILD := .build
# general bins folder. NOT cleaned via `make clean`
BINS := .bins
INTEG_TEST_ROOT := ./test
COVER_ROOT := $(BUILD)/coverage
UT_COVER_FILE := $(COVER_ROOT)/unit_test_cover.out
INTEG_STICKY_OFF_COVER_FILE := $(COVER_ROOT)/integ_test_sticky_off_cover.out
INTEG_STICKY_ON_COVER_FILE := $(COVER_ROOT)/integ_test_sticky_on_cover.out
# Automatically gather all srcs + a "sentinel" thriftrw output file (which forces generation).
ALL_SRC := $(THRIFTRW_OUT) $(shell \
find . -name "*.go" | \
grep -v \
-e .gen/ \
-e .build/ \
)
UT_DIRS := $(filter-out $(INTEG_TEST_ROOT)%, $(sort $(dir $(filter %_test.go,$(ALL_SRC)))))
# Files that needs to run lint. excludes testify mocks and the thrift sentinel.
LINT_SRC := $(filter-out ./mock% $(THRIFTRW_OUT),$(ALL_SRC))
THRIFTRW_VERSION := v1.11.0
YARPC_VERSION := v1.29.1
GOLINT_VERSION := 470b6b0bb3005eda157f0275e2e4895055396a81
STATICCHECK_VERSION := 2019.2.3
ERRCHECK_VERSION := v1.2.0
# versioned tools. just change the version vars above, it'll automatically trigger a rebuild.
$(BINS)/versions/thriftrw-$(THRIFTRW_VERSION):
./versioned_go_build.sh go.uber.org/thriftrw $(THRIFTRW_VERSION) $@
$(BINS)/versions/yarpc-$(YARPC_VERSION):
./versioned_go_build.sh go.uber.org/yarpc $(YARPC_VERSION) encoding/thrift/thriftrw-plugin-yarpc $@
$(BINS)/versions/golint-$(GOLINT_VERSION):
./versioned_go_build.sh golang.org/x/lint $(GOLINT_VERSION) golint $@
$(BINS)/versions/staticcheck-$(STATICCHECK_VERSION):
./versioned_go_build.sh honnef.co/go/tools $(STATICCHECK_VERSION) cmd/staticcheck $@
$(BINS)/versions/errcheck-$(ERRCHECK_VERSION):
./versioned_go_build.sh github.com/kisielk/errcheck $(ERRCHECK_VERSION) $@
# stable tool targets. depend on / execute these instead of the versioned ones.
# this versioned-to-nice-name thing is mostly because thriftrw depends on the yarpc
# bin to be named "thriftrw-plugin-yarpc".
$(BINS)/thriftrw: $(BINS)/versions/thriftrw-$(THRIFTRW_VERSION)
@ln -fs $(CURDIR)/$< $@
$(BINS)/thriftrw-plugin-yarpc: $(BINS)/versions/yarpc-$(YARPC_VERSION)
@ln -fs $(CURDIR)/$< $@
$(BINS)/golint: $(BINS)/versions/golint-$(GOLINT_VERSION)
@ln -fs $(CURDIR)/$< $@
$(BINS)/staticcheck: $(BINS)/versions/staticcheck-$(STATICCHECK_VERSION)
@ln -fs $(CURDIR)/$< $@
$(BINS)/errcheck: $(BINS)/versions/errcheck-$(ERRCHECK_VERSION)
@ln -fs $(CURDIR)/$< $@
$(THRIFTRW_OUT): $(THRIFTRW_SRC) $(BINS)/thriftrw $(BINS)/thriftrw-plugin-yarpc
@echo 'thriftrw: $(THRIFTRW_SRC)'
@mkdir -p $(dir $@)
@# needs to be able to find the thriftrw-plugin-yarpc bin in PATH
$(foreach source,$(THRIFTRW_SRC),\
PATH="$(BINS)" \
$(BINS)/thriftrw \
--plugin=yarpc \
--pkg-prefix=$(IMPORT_ROOT)/$(THRIFT_GENDIR) \
--out=$(THRIFT_GENDIR) $(source);)
git-submodules:
git submodule update --init --recursive
yarpc-install:
GO111MODULE=off go get -u github.com/myitcv/gobin
GOOS= GOARCH= gobin -mod=readonly go.uber.org/thriftrw
GOOS= GOARCH= gobin -mod=readonly go.uber.org/yarpc/encoding/thrift/thriftrw-plugin-yarpc
thriftc: git-submodules yarpc-install $(THRIFTRW_OUT) copyright
clean_thrift:
rm -rf .gen
# `make copyright` or depend on "copyright" to force-run licensegen,
# or depend on $(BUILD)/copyright to let it run as needed.
copyright $(BUILD)/copyright: $(ALL_SRC)
@mkdir -p $(BUILD)
go run ./internal/cmd/tools/copyright/licensegen.go --verifyOnly
@touch $(BUILD)/copyright
$(BUILD)/dummy:
go build -i -o $@ internal/cmd/dummy/dummy.go
bins: thriftc $(ALL_SRC) $(BUILD)/copyright lint $(BUILD)/dummy
unit_test: $(BUILD)/dummy
@mkdir -p $(COVER_ROOT)
@echo "mode: atomic" > $(UT_COVER_FILE)
@for dir in $(UT_DIRS); do \
mkdir -p $(COVER_ROOT)/"$$dir"; \
go test "$$dir" $(TEST_ARG) -coverprofile=$(COVER_ROOT)/"$$dir"/cover.out || exit 1; \
cat $(COVER_ROOT)/"$$dir"/cover.out | grep -v "mode: atomic" >> $(UT_COVER_FILE); \
done;
integ_test_sticky_off: $(BUILD)/dummy
@mkdir -p $(COVER_ROOT)
STICKY_OFF=true go test $(TEST_ARG) ./test -coverprofile=$(INTEG_STICKY_OFF_COVER_FILE) -coverpkg=./...
integ_test_sticky_on: $(BUILD)/dummy
@mkdir -p $(COVER_ROOT)
STICKY_OFF=false go test $(TEST_ARG) ./test -coverprofile=$(INTEG_STICKY_ON_COVER_FILE) -coverpkg=./...
test: thriftc unit_test integ_test_sticky_off integ_test_sticky_on
$(COVER_ROOT)/cover.out: $(UT_COVER_FILE) $(INTEG_STICKY_OFF_COVER_FILE) $(INTEG_STICKY_ON_COVER_FILE)
@echo "mode: atomic" > $(COVER_ROOT)/cover.out
cat $(UT_COVER_FILE) | grep -v "mode: atomic" | grep -v ".gen" >> $(COVER_ROOT)/cover.out
cat $(INTEG_STICKY_OFF_COVER_FILE) | grep -v "mode: atomic" | grep -v ".gen" >> $(COVER_ROOT)/cover.out
cat $(INTEG_STICKY_ON_COVER_FILE) | grep -v "mode: atomic" | grep -v ".gen" >> $(COVER_ROOT)/cover.out
cover: $(COVER_ROOT)/cover.out
go tool cover -html=$(COVER_ROOT)/cover.out;
cover_ci: $(COVER_ROOT)/cover.out
goveralls -coverprofile=$(COVER_ROOT)/cover.out -service=buildkite || echo -e "\x1b[31mCoveralls failed\x1b[m";
# golint fails to report many lint failures if it is only given a single file
# to work on at a time, and it can't handle multiple packages at once, *and*
# we can't exclude files from its checks, so for best results we need to give
# it a whitelist of every file in every package that we want linted, per package.
#
# so lint + this golint func works like:
# - iterate over all lintable dirs (outputs "./folder/")
# - find .go files in a dir (via wildcard, so not recursively)
# - filter to only files in LINT_SRC
# - if it's not empty, run golint against the list
define lint_if_present
test -n "$1" && $(BINS)/golint -set_exit_status $1
endef
lint: $(BINS)/golint $(ALL_SRC)
$(foreach pkg,\
$(sort $(dir $(LINT_SRC))), \
$(call lint_if_present,$(filter $(wildcard $(pkg)*.go),$(LINT_SRC))) || ERR=1; \
) test -z "$$ERR" || exit 1
@OUTPUT=`gofmt -l $(ALL_SRC) 2>&1`; \
if [ "$$OUTPUT" ]; then \
echo "Run 'make fmt'. gofmt must be run on the following files:"; \
echo "$$OUTPUT"; \
exit 1; \
fi
staticcheck: $(BINS)/staticcheck $(ALL_SRC)
$(BINS)/staticcheck ./...
errcheck: $(BINS)/errcheck $(ALL_SRC)
$(BINS)/errcheck ./...
fmt:
@gofmt -w $(ALL_SRC)
clean:
rm -Rf $(BUILD)
rm -Rf .gen