forked from mongodb/amboy
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmakefile
More file actions
207 lines (188 loc) · 9.14 KB
/
makefile
File metadata and controls
207 lines (188 loc) · 9.14 KB
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
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
# start project configuration
name := amboy
buildDir := build
packages := $(name) dependency job registry pool queue rest logger reporting
orgPath := github.com/mongodb
projectPath := $(orgPath)/$(name)
# end project configuration
# start linting configuration
# package, testing, and linter dependencies specified
# separately. This is a temporary solution: eventually we should
# vendorize all of these dependencies.
lintDeps := github.com/alecthomas/gometalinter
# include test files and give linters 40s to run to avoid timeouts
lintArgs := --tests --deadline=5m --vendor
# gotype produces false positives because it reads .a files which
# are rarely up to date.
lintArgs += --disable="gotype" --disable="gas" --enable="goimports"
lintArgs += --skip="$(buildDir)" --skip="buildscripts"
# add and configure additional linters
lintArgs += --line-length=100 --dupl-threshold=175 --cyclo-over=30
# two similar functions triggered the duplicate warning, but they're not.
lintArgs += --exclude="duplicate of registry.go"
lintArgs += --exclude="don.t use underscores.*_DependencyState.*"
lintArgs += --exclude="file is not goimported" # test files aren't imported
# golint doesn't handle splitting package comments between multiple files.
lintArgs += --exclude="package comment should be of the form \"Package .* \(golint\)"
# no need to check the error of closer read operations in defer cases
lintArgs += --exclude="error return value not checked \(defer.*"
lintArgs += --exclude="should check returned error before deferring .*\.Close"
# end lint suppressions
######################################################################
##
## Everything below this point is generic, and does not contain
## project specific configuration. (with one noted case in the "build"
## target for library-only projects)
##
######################################################################
# start dependency installation tools
# implementation details for being able to lazily install dependencies
gopath := $(shell go env GOPATH)
lintDeps := $(addprefix $(gopath)/src/,$(lintDeps))
srcFiles := makefile $(shell find . -name "*.go" -not -path "./$(buildDir)/*" -not -name "*_test.go")
testSrcFiles := makefile $(shell find . -name "*.go" -not -path "./$(buildDir)/*")
testBin := $(foreach target,$(packages),$(buildDir)/test.$(target))
raceBin := $(foreach target,$(packages),$(buildDir)/race.$(target))
testOutput := $(foreach target,$(packages),$(buildDir)/output.$(target).test)
raceOutput := $(foreach target,$(packages),$(buildDir)/output.$(target).race)
coverageOutput := $(foreach target,$(packages),$(buildDir)/output.$(target).coverage)
coverageHtmlOutput := $(foreach target,$(packages),$(buildDir)/output.$(target).coverage.html)
$(gopath)/src/%:
@-[ ! -d $(gopath) ] && mkdir -p $(gopath) || true
go get $(subst $(gopath)/src/,,$@)
$(buildDir)/run-linter:buildscripts/run-linter.go $(buildDir)/.lintSetup
go build -o $@ $<
$(buildDir)/.lintSetup:$(lintDeps)
@mkdir -p $(buildDir)
@-$(gopath)/bin/gometalinter --install >/dev/null && touch $@
# end dependency installation tools
# userfacing targets for basic build and development operations
lint:$(buildDir)/output.lint
build:$(deps) $(srcFiles) $(gopath)/src/$(projectPath)
go build $(subst $(name),,$(subst -,/,$(foreach pkg,$(packages),./$(pkg))))
build-race:$(deps) $(srcFiles) $(gopath)/src/$(projectPath)
go build -race $(subst $(name),,$(subst -,/,$(foreach pkg,$(packages),./$(pkg))))
test:$(testOutput)
race:$(raceOutput)
coverage:$(coverageOutput)
coverage-html:$(coverageHtmlOutput)
phony := lint build build-race race test coverage coverage-html
.PRECIOUS:$(testOutput) $(raceOutput) $(coverageOutput) $(coverageHtmlOutput)
.PRECIOUS:$(foreach target,$(packages),$(buildDir)/test.$(target))
.PRECIOUS:$(foreach target,$(packages),$(buildDir)/race.$(target))
.PRECIOUS:$(foreach target,$(packages),$(buildDir)/output.$(target).lint)
.PRECIOUS:$(buildDir)/output.lint
# end front-ends
# implementation details for building the binary and creating a
# convienent link in the working directory
$(gopath)/src/$(orgPath):
@mkdir -p $@
$(gopath)/src/$(projectPath):$(gopath)/src/$(orgPath)
@[ -L $@ ] || ln -s $(shell pwd) $@
$(name):$(buildDir)/$(name)
@[ -L $@ ] || ln -s $< $@
$(buildDir)/$(name):$(gopath)/src/$(projectPath) $(srcFiles) $(deps)
go build -o $@ main/$(name).go
$(buildDir)/$(name).race:$(gopath)/src/$(projectPath) $(srcFiles) $(deps)
go build -race -o $@ main/$(name).go
# end main build
# convenience targets for runing tests and coverage tasks on a
# specific package.
race-%:$(buildDir)/output.%.race
@grep -s -q -e "^PASS" $< && ! grep -s -q "^WARNING: DATA RACE" $<
test-%:$(buildDir)/output.%.test
@grep -s -q -e "^PASS" $<
coverage-%:$(buildDir)/output.%.coverage
@grep -s -q -e "^PASS" $(subst coverage,test,$<)
html-coverage-%:$(buildDir)/output.%.coverage $(buildDir)/output.%.coverage.html
@grep -s -q -e "^PASS" $(subst coverage,test,$<)
lint-%:$(buildDir)/output.%.lint
@grep -v -s -q "^--- FAIL" $<
# end convienence targets
# start test and coverage artifacts
# tests have compile and runtime deps. This varable has everything
# that the tests actually need to run. (The "build" target is
# intentional and makes these targets rerun as expected.)
testArgs := -test.v --test.timeout=15m
ifneq (,$(RUN_TEST))
testArgs += -test.run='$(RUN_TEST)'
endif
ifneq (,$(RUN_CASE))
testArgs += -testify.m='$(RUN_CASE)'
endif
ifneq (,$(RUN_COUNT))
testArgs += -test.count='$(RUN_COUNT)'
endif
# to avoid vendoring the coverage tool, install it as needed
coverDeps := $(if $(DISABLE_COVERAGE),,golang.org/x/tools/cmd/cover)
coverDeps := $(addprefix $(gopath)/src/,$(coverDeps))
# implementation for package coverage and test running,mongodb to produce
# and save test output.
$(buildDir)/test.%:$(testSrcFiles) $(coverDeps)
go test $(if $(DISABLE_COVERAGE),,-covermode=count) -c -o $@ ./$(subst -,/,$*)
$(buildDir)/race.%:$(testSrcFiles)
go test -race -c -o $@ ./$(subst -,/,$*)
# targets to run any tests in the top-level package
$(buildDir)/test.$(name):$(testSrcFiles) $(coverDeps)
go test $(if $(DISABLE_COVERAGE),,-covermode=count) -c -o $@ ./
$(buildDir)/race.$(name):$(testSrcFiles)
go test -race -c -o $@ ./
# targets to run the tests and report the output
$(buildDir)/output.%.test:$(buildDir)/test.% .FORCE
$(testRunEnv) ./$< $(testArgs) 2>&1 | tee $@
$(buildDir)/output.%.race:$(buildDir)/race.% .FORCE
$(testRunEnv) ./$< $(testArgs) 2>&1 | tee $@
# targets to generate gotest output from the linter.
$(buildDir)/output.%.lint:$(buildDir)/run-linter $(testSrcFiles) .FORCE
@./$< --output=$@ --lintArgs='$(lintArgs)' --packages='$*'
$(buildDir)/output.lint:$(buildDir)/run-linter .FORCE
@./$< --output="$@" --lintArgs='$(lintArgs)' --packages="$(packages)"
# targets to process and generate coverage reports
$(buildDir)/output.%.coverage:$(buildDir)/test.% .FORCE $(coverDeps)
$(testRunEnv) ./$< $(testArgs) -test.coverprofile=$@ | tee $(subst coverage,test,$@)
@-[ -f $@ ] && go tool cover -func=$@ | sed 's%$(projectPath)/%%' | column -t
$(buildDir)/output.%.coverage.html:$(buildDir)/output.%.coverage $(coverDeps)
go tool cover -html=$< -o $@
# end test and coverage artifacts
# start vendoring configuration
# begin with configuration of dependencies
vendorDeps := github.com/Masterminds/glide
vendorDeps := $(addprefix $(gopath)/src/,$(vendorDeps))
vendor-deps:$(vendorDeps)
# this allows us to store our vendored code in vendor and use
# symlinks to support vendored code both in the legacy style and with
# new-style vendor directories. When this codebase can drop support
# for go1.4, we can delete most of this.
# targets for the directory components and manipulating vendored files.
vendor-sync:$(vendorDeps)
glide install -s
vendor-clean:
rm -rf vendor/gopkg.in/mgo.v2/harness/
rm -rf vendor/github.com/evergreen-ci/gimlet/vendor/github.com/stretchr/testify/
rm -rf vendor/github.com/evergreen-ci/gimlet/vendor/github.com/mongodb/grip/
rm -rf vendor/github.com/mongodb/grip/vendor/github.com/stretchr/testify/
rm -rf vendor/gopkg.in/mgo.v2/harness/
rm -rf vendor/gopkg.in/mgo.v2/testdb/
rm -rf vendor/gopkg.in/mgo.v2/testserver/
rm -rf vendor/gopkg.in/mgo.v2/internal/json/testdata
rm -rf vendor/gopkg.in/mgo.v2/.git/
rm -rf vendor/gopkg.in/mgo.v2/txn/
rm -rf vendor/github.com/mongodb/mongo-go-driver/vendor/gopkg.in/yaml.v2
rm -rf vendor/github.com/mongodb/mongo-go-driver/vendor/github.com/davecgh/
rm -rf vendor/github.com/mongodb/mongo-go-driver/vendor/github.com/stretchr/testify/
rm -rf vendor/github.com/mongodb/mongo-go-driver/data/
rm -rf vendor/github.com/mongodb/mongo-go-driver/vendor/github.com/pmezard/
rm -rf vendor/github.com/mongodb/mongo-go-driver/vendor/github.com/google/go-cmp/
rm -rf vendor/github.com/mongodb/mongo-go-driver/vendor/github.com/kr/
find vendor/ -name "*.gif" -o -name "*.gz" -o -name "*.png" -o -name "*.ico" -o -name "*.dat" -o -name "*testdata" | xargs rm -rf
# define dependencies for buildscripts
phony += vendor-deps vendor-clean
# end vendoring tooling configuration
# clean and other utility targets
clean:
rm -rf $(name) $(lintDeps) $(buildDir)/test.* $(buildDir)/coverage.* $(buildDir)/race.*
phony += clean
# end dependency targets
# configure phony targets
.FORCE:
.PHONY:$(phony)