forked from thriftrw/thriftrw-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
157 lines (127 loc) · 4.98 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
WANT_VERSION = $(shell grep '^v[0-9]' CHANGELOG.md | head -n1 | cut -d' ' -f1)
# Paths besides auto-detected generated files that should be excluded from
# lint results. If generated code uses '//line' directives with a different
# filename, that file won't be auto-detected.
LINT_EXCLUDES_EXTRAS = \
idl/internal/lex.rl \
idl/internal/thrift.y \
idl/internal/yaccpar \
compile/primitive.go
ERRCHECK_FLAGS ?= -ignoretests
##############################################################################
export GO15VENDOREXPERIMENT=1
GO_VERSION := $(shell go version | cut -d' ' -f3) # e.g.: go1.6.2
GO_MINOR_VERSION := $(word 2, $(subst ., , $(GO_VERSION)))
PACKAGES := $(shell glide novendor)
GO_FILES := $(shell \
find . '(' -path '*/.*' -o -path './vendor' ')' -prune \
-o -name '*.go' -print | cut -b3-)
# Files whose first line contains "Code generated by" are generated.
GENERATED_GO_FILES := $(shell \
find $(GO_FILES) \
-exec sh -c 'head -n1 {} | grep "Code generated by\|Automatically generated by " >/dev/null' \; \
-print)
LINT_EXCLUDES := $(GENERATED_GO_FILES) $(LINT_EXCLUDES_EXTRAS)
# Pipe lint output into this to filter out ignored files.
FILTER_LINT := grep -v $(patsubst %,-e %, $(LINT_EXCLUDES)) -e "vendor/"
# Disable printf-like invocation checking due to testify.assert.Error()
VET_RULES := -printf=false
BUILD_FLAGS ?=
RAGEL_PATH := $(shell pwd)/build/ragel
.PHONY: build
build:
go build -i $(BUILD_FLAGS)
$(RAGEL_PATH)/bin/ragel:
mkdir -p $(RAGEL_PATH)
curl https://www.colm.net/files/ragel/ragel-6.9.tar.gz | \
tar -xz -C $(RAGEL_PATH) --strip-components 1
cd $(RAGEL_PATH) ; (./configure --prefix=$(RAGEL_PATH) && make install)
.PHONY: generate
generate: $(RAGEL_PATH)/bin/ragel
go get -u github.com/golang/mock/mockgen
go get -u golang.org/x/tools/cmd/stringer
go get -u golang.org/x/tools/cmd/goyacc
go build -i
PATH=$$(pwd):$$PATH:$(RAGEL_PATH)/bin go generate $$(glide nv)
make -C ./gen/internal/tests
./scripts/updateLicenses.sh
.PHONY: lint
lint:
$(eval FMT_LOG := $(shell mktemp -t gofmt.XXXXX))
@gofmt -e -s -l $(GO_FILES) | $(FILTER_LINT) > $(FMT_LOG) || true
@[ ! -s "$(FMT_LOG)" ] || (echo "gofmt failed:" | cat - $(FMT_LOG) && false)
$(eval VET_LOG := $(shell mktemp -t govet.XXXXX))
@$(foreach pkg, $(PACKAGES), \
go tool vet $(VET_RULES) $(pkg) 2>&1 | \
grep -v '^exit status' | \
$(FILTER_LINT) | \
> $(VET_LOG) || true; \
)
@[ ! -s "$(VET_LOG)" ] || (echo "govet failed:" | cat - $(VET_LOG) && false)
$(eval LINT_LOG := $(shell mktemp -t golint.XXXXX))
@cat /dev/null > $(LINT_LOG)
@$(foreach pkg, $(PACKAGES), golint $(pkg) | $(FILTER_LINT) >> $(LINT_LOG) || true;)
@[ ! -s "$(LINT_LOG)" ] || (echo "golint failed:" | cat - $(LINT_LOG) && false)
$(eval ERRCHECK_LOG := $(shell mktemp -t errcheck.XXXXX))
@cat /dev/null > $(ERRCHECK_LOG)
@$(foreach pkg, $(PACKAGES), errcheck $(ERRCHECK_FLAGS) $(pkg) | $(FILTER_LINT) >> $(ERRCHECK_LOG) || true;)
@[ ! -s "$(ERRCHECK_LOG)" ] || (echo "errcheck failed:" | cat - $(ERRCHECK_LOG) && false)
.PHONY: verifyversion
verifyversion: build
$(eval CHANGELOG_VERSION := $(shell perl -ne '/^## \[(\S+?)\]/ && print "v$$1\n"' CHANGELOG.md | head -n1))
$(eval INTHECODE_VERSION := $(shell perl -ne '/^const Version.*"([^"]+)".*$$/ && print "v$$1\n"' version/version.go))
@if [ "$(INTHECODE_VERSION)" = "$(CHANGELOG_VERSION)" ]; then \
echo "thriftrw-go: $(CHANGELOG_VERSION)"; \
elif [ "$(CHANGELOG_VERSION)" = "vUnreleased" ]; then \
echo "thriftrw-go (development): $(INTHECODE_VERSION)"; \
else \
echo "Version number in version/version.go does not match CHANGELOG.md"; \
echo "version/version.go: $(INTHECODE_VERSION)"; \
echo "CHANGELOG : $(CHANGELOG_VERSION)"; \
exit 1; \
fi
.PHONY: test
test: build verifyversion
go test -race ./...
# List of files we don't need to track coverage for.
# (Include a reason for each.)
#
# lex.go, y.go: Generated by Ragel and goyacc. Many cases cannot be exercised.
# mock_protocol.go: Generated by gomock, which is thoroughly tested.
# plugin/api/*.go: Generated by us. We're already testing codegen elsewhere.
COVER_IGNORE_FILES = \
idl/internal/lex.go \
idl/internal/y.go \
thrifttest/mock_protocol.go \
$(wildcard plugin/api/*.go)
# literal space
space :=
space +=
.PHONY: cover
cover:
go test -v -covermode=atomic -coverprofile cover.full.out -coverpkg=./... ./...
grep -v "$(subst $(space),\|,$(COVER_IGNORE_FILES))" cover.full.out > cover.out
go tool cover -html=cover.out -o cover.html
.PHONY: clean
clean:
go clean
rm -rf cover/cover*.out cover.html cover.out
.PHONY: install
install:
glide --version || go get github.com/Masterminds/glide
glide install
##############################################################################
# CI
.PHONY: install_ci
install_ci: install
go get -u -f golang.org/x/lint/golint
go get -u -f github.com/kisielk/errcheck
go get -u github.com/mattn/goveralls
go get -u golang.org/x/tools/cmd/cover
go install .
.PHONY: build_ci
build_ci: build
.PHONY: lint_ci
lint_ci: lint
.PHONY: test_ci
test_ci: build_ci verifyversion cover