-
Notifications
You must be signed in to change notification settings - Fork 3
/
common.mk
106 lines (81 loc) · 2.82 KB
/
common.mk
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
# Usage: echo 'include common.mk' > Makefile
TOP_PKG := $(shell go list .)
NAME := $(shell go list . | awk -F/ '{print $$NF}')
PKGS := $(shell go list ./... | grep -v "^$(TOP_PKG)/\(vendor\|prototype\)")
# PKGS := github.com/openacid/slimarray/array \
# github.com/openacid/slimarray/bit \
# github.com/openacid/slimarray/trie \
SRCDIRS := $(shell go list -f '{{.Dir}}' $(PKGS))
# gofmt check vendor dir. we need to skip vendor manually
GOFILES := $(shell find $(SRCDIRS) -not -path "*/vendor/*" -name "*.go")
GO := go
check: test vet gofmt misspell unconvert staticcheck ineffassign unparam
travis: vet gofmt misspell unconvert ineffassign unparam test
test:
# fail fast with severe bugs
$(GO) test -short $(PKGS)
$(GO) test -tags debug $(PKGS)
# test release version and generate coverage data for task `coveralls`.
$(GO) test -covermode=count -coverprofile=coverage.out $(PKGS)
vet:
$(GO) vet $(PKGS)
staticcheck:
$(GO) get honnef.co/go/tools/cmd/staticcheck
# ST1016: methods on the same type should have the same receiver name
# .pb.go have this issue.
staticcheck -checks all,-ST1016 $(PKGS)
misspell:
$(GO) get github.com/client9/misspell/cmd/misspell
find $(SRCDIRS) -name '*.go' -or -name '*.md' | grep -v "\bvendor/" | xargs misspell \
-locale US \
-error
misspell \
-locale US \
-error \
*.md *.go
unconvert:
$(GO) get github.com/mdempsky/unconvert
unconvert -v $(PKGS)
ineffassign:
$(GO) get github.com/gordonklaus/ineffassign
find $(SRCDIRS) -name '*.go' | grep -v "\bvendor/" | xargs ineffassign
pedantic: check errcheck
unparam:
$(GO) get mvdan.cc/unparam
unparam ./...
errcheck:
$(GO) get github.com/kisielk/errcheck
errcheck $(PKGS)
gofmt:
@echo Checking code is gofmted
@test -z "$(shell gofmt -s -l -d -e $(GOFILES) | tee /dev/stderr)"
ben: test
$(GO) test ./... -run=none -bench=. -benchmem
gen:
$(GO) generate ./...
doc:
# build a markdown version of package doc to embed to README.md
# $(GO) get github.com/robertkrimen/godocdown/godocdown
godocdown . > docs/$(NAME).md
# "package" is the first phrase in a go doc.
# "## Usage" is the start of API section.
cat docs/$(NAME).md | awk '/^Package /,/^## Usage/' | grep -v '^## Usage' > docs/$(NAME)-package.md
readme: doc
python ./scripts/build_md.py
# brew install nodejs
# npm install -g doctoc
doctoc --title '' --github README.md
fix:
gofmt -s -w $(GOFILES)
unconvert -v -apply $(PKGS)
# local coverage
coverage:
$(GO) test -covermode=count -coverprofile=coverage.out $(PKGS)
go tool cover -func=coverage.out
# go tool cover -html=coverage.out
# send coverage to coveralls
coveralls:
# this job relies on the output of task test: `-coverprofile=coverage.out`
$(GO) get golang.org/x/tools/cmd/cover
$(GO) get github.com/mattn/goveralls
goveralls -ignore='*.pb.go' -coverprofile=coverage.out -service=travis-ci