-
Notifications
You must be signed in to change notification settings - Fork 0
/
makefile
143 lines (126 loc) · 5.1 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
buildDir := build
projectPath := github.com/evergreen-ci/pail
packages := pail
# start environment setup
ifneq (,${GO_BIN_PATH})
gobin := ${GO_BIN_PATH}
else
gobin := go
endif
gopath := $(GOPATH)
ifeq ($(OS),Windows_NT)
gopath := $(shell cygpath -m $(gopath))
userProfile := $(shell cygpath -m $(USERPROFILE))
endif
goEnv := GOPATH=$(gopath) $(if ${GO_BIN_PATH},PATH="$(shell dirname ${GO_BIN_PATH}):${PATH}")
# end environment setup
# start lint setup targets
lintDeps := $(buildDir)/.lintSetup $(buildDir)/run-linter $(buildDir)/golangci-lint
$(buildDir)/.lintSetup:$(buildDir)/golangci-lint
@touch $@
$(buildDir)/golangci-lint:$(buildDir)
@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 $(buildDir)
@$(goEnv) $(gobin) build -o $@ $<
# end lint setup targets
testArgs := -v
ifneq (,$(RUN_TEST))
testArgs += -run='$(RUN_TEST)'
endif
ifneq (,$(RUN_COUNT))
WORK_DIR: ${workdir}
testArgs += -count='$(RUN_COUNT)'
endif
ifneq (,$(SKIP_LONG))
testArgs += -short
endif
ifneq (,$(DISABLE_COVERAGE))
testArgs += -cover
endif
ifneq (,$(RACE_DETECTOR))
testArgs += -race
endif
ifneq (,$(TEST_TIMEOUT))
testArgs += -timeout=$(TEST_TIMEOUT)
else
testArgs += -timeout=30m
endif
# test execution and output handlers
$(buildDir)/output.%.test:$(buildDir)/ .FORCE
export USERPROFILE=$(userProfile)
$(goEnv) $(gobin) test $(testArgs) ./$(if $(subst $(name),,$*),$*,) | tee $@
@! grep -s -q -e "^FAIL" $@ && ! grep -s -q "^WARNING: DATA RACE" $@
$(buildDir)/output.test:$(buildDir)/ .FORCE
export USERPROFILE=$(userProfile)
$(goEnv) $(gobin) test $(testArgs) ./... | tee $@
@! grep -s -q -e "^FAIL" $@ && ! grep -s -q "^WARNING: DATA RACE" $@
$(buildDir)/output.%.coverage:$(buildDir)/ .FORCE
export USERPROFILE=$(userProfile)
$(goEnv) $(gobin) test $(testArgs) ./$(if $(subst $(name),,$*),$*,) -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)'
# targets to process and generate coverage reports
# end test and coverage artifacts
# userfacing targets for basic build and development operations
compile:
$(goEnv) $(gobin) build ./
test:$(buildDir)/test.out
$(buildDir)/test.out:.FORCE
export USERPROFILE=$(userProfile)
@mkdir -p $(buildDir)
$(goEnv) $(gobin) test $(testArgs) ./ | tee $@
@grep -s -q -e "^PASS" $@
coverage:$(buildDir)/cover.out
@$(goEnv) $(gobin) tool cover -func=$< | sed -E 's%$(projectPath)/%%' | column -t
coverage-html:$(buildDir)/cover.html
benchmark:
$(goEnv) $(gobin) test -v -benchmem -bench=. -run="Benchmark.*" -timeout=20m
lint:$(foreach target,$(packages),$(buildDir)/output.$(target).lint)
phony += lint build race test coverage coverage-html
.PRECIOUS:$(foreach target,$(packages),$(buildDir)/output.$(target).lint)
.PRECIOUS:$(buildDir)/output.lint
# end front-ends
$(buildDir): compile
@mkdir -p $@
$(buildDir)/cover.out:$(buildDir) .FORCE
export USERPROFILE=$(userProfile)
$(goEnv) $(gobin) test $(testArgs) -covermode=count -coverprofile $@ -cover ./
$(buildDir)/cover.html:$(buildDir)/cover.out
$(goEnv) $(gobin) tool cover -html=$< -o $@
vendor-clean:
find vendor/ -name "*.gif" -o -name "*.gz" -o -name "*.png" -o -name "*.ico" -o -name "*testdata*" | xargs rm -rf
rm -rf vendor/github.com/mongodb/grip/vendor/github.com/stretchr/testify
rm -rf vendor/go.mongodb.org/mongo-driver/vendor/github.com/pmezard
rm -rf vendor/go.mongodb.org/mongo-driver/vendor/github.com/stretchr
rm -rf vendor/go.mongodb.org/mongo-driver/vendor/github.com/davecgh
rm -rf vendor/go.mongodb.org/mongo-driver/vendor/github.com/montanaflynn
rm -rf vendor/github.com/mongodb/grip/vendor/github.com/montanaflynn
rm -rf vendor/github.com/mongodb/grip/vendor/github.com/pkg/errors
phony += vendor-clean
clean:
rm -rf $(lintDeps)
phony += clean
# 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
@echo "waiting for mongod to start up"
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
# configure phony targets
.FORCE:
.PHONY:$(phony) .FORCE