-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmakefile
179 lines (163 loc) · 7.12 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
# start project configuration
name := anser
buildDir := build
packages := $(name) mock model db bsonutil client apm backup
orgPath := github.com/mongodb
projectPath := $(orgPath)/$(name)
# end project configuration
# start environment setup
ifneq (,$(GO_BIN_PATH))
gobin := $(GO_BIN_PATH)
else
gobin := $(shell if [ -x /opt/golang/go1.9/bin/go ]; then echo /opt/golang/go1.9/bin/go; fi)
ifeq (,$(gobin))
gobin := go
endif
endif
gopath := $(GOPATH)
ifeq (,$(gopath))
gopath := $(shell $(gobin) env GOPATH)
endif
ifeq ($(OS),Windows_NT)
gopath := $(shell cygpath -m $(gopath))
endif
goos := $(shell $(gobin) env GOOS)
goarch := $(shell $(gobin) env GOARCH)
goEnv := GOPATH=$(gopath) $(if $(GO_BIN_PATH),PATH="$(shell dirname $(GO_BIN_PATH)):$(PATH)")
# end environment setup
# start dependency installation tools
# implementation details for being able to lazily install dependencies.
# this block has no project specific configuration but defines
# variables that project specific information depends on
testOutput := $(foreach target,$(packages),$(buildDir)/output.$(target).test)
raceOutput := $(foreach target,$(packages),$(buildDir)/output.$(target).race)
testBin := $(foreach target,$(packages),$(buildDir)/test.$(target))
raceBin := $(foreach target,$(packages),$(buildDir)/race.$(target))
lintTargets := $(foreach target,$(packages),lint-$(target))
coverageOutput := $(foreach target,$(packages),$(buildDir)/output.$(target).coverage)
coverageHtmlOutput := $(foreach target,$(packages),$(buildDir)/output.$(target).coverage.html)
testSrcFiles := makefile $(shell find . -name "*.go" -not -path "./$(buildDir)/*" -not -path "*\#*")
# end dependency installation tools
# lint setup targets
lintDeps := $(buildDir)/golangci-lint $(buildDir)/.lintSetup $(buildDir)/run-linter
$(buildDir)/.lintSetup:$(buildDir)/golangci-lint
@mkdir -p $(buildDir)
@touch $@
$(buildDir)/golangci-lint:
@curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/76a82c6ed19784036bbf2d4c84d0228ca12381a4/install.sh | sh -s -- -b $(buildDir) v1.10.2 >/dev/null 2>&1
$(buildDir)/run-linter:cmd/run-linter/run-linter.go $(buildDir)/.lintSetup
@mkdir -p $(buildDir)
$(goEnv) $(gobin) build -o $@ $<
# end lint setup targets
# userfacing targets for basic build and development operations
$(buildDir):
@mkdir -p $(buildDir)
$(goEnv) $(gobin) build $(subst $(name),,$(subst -,/,$(foreach pkg,$(packages),./$(pkg))))
test:$(testOutput)
coverage:$(coverageOutput)
coverage-html:$(coverageHtmlOutput)
lint:$(lintTargets)
list-tests:
@echo -e "test targets:" $(foreach target,$(packages),\\n\\ttest-$(target))
phony := lint build test coverage coverage-html
.PRECIOUS:$(testOutput) $(raceOutput) $(coverageOutput) $(coverageHtmlOutput)
.PRECIOUS:$(foreach target,$(packages),$(buildDir)/test.$(target))
.PRECIOUS:$(foreach target,$(packages),$(buildDir)/output.$(target).lint)
.PRECIOUS:$(buildDir)/output.lint
# end front-ends
# 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 vendoring configuration
vendor-clean:
rm -rf vendor/github.com/mongodb/amboy/vendor/github.com/mongodb/grip/
rm -rf vendor/github.com/mongodb/amboy/vendor/github.com/stretchr/testify/
rm -rf vendor/github.com/mongodb/amboy/vendor/go.mongodb.org/mongo-driver/
rm -rf vendor/github.com/mongodb/ftdc/vendor/github.com/evergreen-ci/birch/
rm -rf vendor/github.com/mongodb/ftdc/vendor/github.com/mongodb/grip/
rm -rf vendor/github.com/mongodb/ftdc/vendor/github.com/pkg/
rm -rf vendor/github.com/mongodb/ftdc/vendor/github.com/stretchr/testify/
rm -rf vendor/github.com/mongodb/ftdc/vendor/go.mongodb.org/mongo-driver/
rm -rf vendor/github.com/mongodb/ftdc/vendor/gopkg.in/mgo.v2/
rm -rf vendor/github.com/mongodb/ftdc/vendor/gopkg.in/mgo.v2/
rm -rf vendor/github.com/mongodb/grip/vendor/github.com/stretchr/testify/
rm -rf vendor/github.com/mongodb/ftdc/vendor/github.com/satori/go.uuid/
rm -rf vendor/gopkg.in/mgo.v2/harness/
find vendor/ -name "*.gif" -o -name "*.gz" -o -name "*.png" -o -name "*.ico" -o -name "*.dat" -o -name "*testdata" | xargs rm -rf
find vendor/ -name '.git' | xargs rm -rf
# add phony targets
phony += vendor-clean
# end vendoring tooling configuration
# start test and coverage artifacts
# This varable includes everything that the tests actually need to
# run. (The "build" target is intentional and makes these targetsb
# rerun as expected.)
testArgs := -v -timeout=10m
ifneq (,$(RUN_TEST))
testArgs += -run='$(RUN_TEST)'
endif
ifneq (,$(RUN_COUNT))
testArgs += -count=$(RUN_COUNT)
endif
ifneq (,$(SKIP_LONG))
testArgs += -short
endif
ifneq (,$(DISABLE_COVERAGE))
testArgs += -cover
endif
ifneq (,$(RACE_DETECTOR))
testArgs += -race
endif
# testing targets
$(buildDir)/output.%.test: .FORCE
@mkdir -p $(buildDir)
$(goEnv) $(gobin) test $(testArgs) ./$(if $(subst $(name),,$*),$(subst -,/,$*),) | tee $@
$(buildDir)/output.%.coverage: $(buildDir) .FORCE
@mkdir -p $(buildDir)
$(goEnv) $(gobin) test $(testArgs) ./$(if $(subst $(name),,$*),$(subst -,/,$*),) -covermode=count -coverprofile $@ | tee $(buildDir)/output.$*.test
@-[ -f $@ ] && $(goEnv) $(gobin) tool cover -func=$@ | sed 's%$(projectPath)/%%' | column -t
$(buildDir)/output.%.coverage.html:$(buildDir)/output.%.coverage
$(goEnv) $(gobin) tool cover -html=$< -o $@
# targets to generate gotest output from the linter.
$(buildDir)/output.%.lint:$(buildDir)/run-linter $(buildDir) .FORCE
@./$< --output=$@ --lintBin="$(buildDir)/golangci-lint" --packages='$*'
$(buildDir)/output.lint:$(buildDir)/run-linter $(buildDir) .FORCE
@./$< --output=$@ --lintBin="$(buildDir)/golangci-lint" --packages='$(packages)'
# end test and coverage artifacts
# mongodb utility targets
mongodb/.get-mongodb:
rm -rf mongodb
mkdir -p mongodb
cd mongodb && curl "$(MONGODB_URL)" -o mongodb.tgz && $(DECOMPRESS) mongodb.tgz && chmod +x ./mongodb-*/bin/*
cd mongodb && mv ./mongodb-*/bin/* . && rm -rf db_files && rm -rf db_logs && mkdir -p db_files && mkdir -p db_logs
get-mongodb: mongodb/.get-mongodb
@touch $<
start-mongod: mongodb/.get-mongodb
./mongodb/mongod --dbpath ./mongodb/db_files --port 27017 --replSet evg --smallfiles --oplogSize 10
@echo "waiting for mongod to start up"
init-rs: mongodb/.get-mongodb
./mongodb/mongo --eval 'rs.initiate()'
check-mongod: mongodb/.get-mongodb
./mongodb/mongo --nodb --eval "assert.soon(function(x){try{var d = new Mongo(\"localhost:27017\"); return true}catch(e){return false}}, \"timed out connecting\")"
@echo "mongod is up"
# end mongodb targets
# clean and other utility targets
clean:
rm -rf $(lintDeps) $(buildDir)/test.* $(buildDir)/coverage.* $(buildDir)/race.* $(clientBuildDir)
clean-results:
rm -rf $(buildDir)/output.*
phony += clean
# end dependency targets
# configure phony targets
.FORCE:
.PHONY:$(phony) .FORCE