-
Notifications
You must be signed in to change notification settings - Fork 27
Expand file tree
/
Copy pathmakefile
More file actions
175 lines (154 loc) · 5.67 KB
/
makefile
File metadata and controls
175 lines (154 loc) · 5.67 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
# start project configuration
name := amboy
buildDir := build
packages := $(name) dependency job registry pool queue rest logger management cli
compilePackages := $(subst $(name),,$(subst -,/,$(foreach target,$(packages),./$(target))))
orgPath := github.com/mongodb
projectPath := $(orgPath)/$(name)
# end project configuration
# start environment setup
gobin := go
ifneq ($(GOROOT),)
gobin := $(GOROOT)/bin/go
endif
goCache := $(GOCACHE)
ifeq (,$(goCache))
goCache := $(abspath $(buildDir)/.cache)
endif
goModCache := $(GOMODCACHE)
ifeq (,$(goModCache))
goModCache := $(abspath $(buildDir)/.mod-cache)
endif
lintCache := $(GOLANGCI_LINT_CACHE)
ifeq (,$(lintCache))
lintCache := $(abspath $(buildDir)/.lint-cache)
endif
ifeq ($(OS),Windows_NT)
gobin := $(shell cygpath $(gobin))
goCache := $(shell cygpath -m $(goCache))
goModCache := $(shell cygpath -m $(goModCache))
lintCache := $(shell cygpath -m $(lintCache))
export GOROOT := $(shell cygpath -m $(GOROOT))
endif
ifneq ($(goCache),$(GOCACHE))
export GOCACHE := $(goCache)
endif
ifneq ($(goModCache),$(GOMODCACHE))
export GOMODCACHE := $(goModCache)
endif
ifneq ($(lintCache),$(GOLANGCI_LINT_CACHE))
export GOLANGCI_LINT_CACHE := $(lintCache)
endif
ifneq (,$(RACE_DETECTOR))
# cgo is required for using the race detector.
export CGO_ENABLED := 1
else
export CGO_ENABLED := 0
endif
# end environment setup
# Ensure the build directory exists, since most targets require it.
$(shell mkdir -p $(buildDir))
.DEFAULT_GOAL := compile
# start lint setup targets
$(buildDir)/golangci-lint:
@curl --retry 10 --retry-max-time 60 -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(buildDir) v1.64.5 >/dev/null 2>&1
$(buildDir)/run-linter: cmd/run-linter/run-linter.go $(buildDir)/golangci-lint
@$(gobin) build -o $@ $<
# end lint setup targets
# start output files
testOutput := $(foreach target,$(packages),$(buildDir)/output.$(target).test)
testOutput := $(foreach target,$(packages),$(buildDir)/output.$(target).lint)
coverageOutput := $(foreach target,$(packages),$(buildDir)/output.$(target).coverage)
htmlCoverageOutput := $(foreach target,$(packages),$(buildDir)/output.$(target).coverage.html)
.PRECIOUS: $(testOutput) $(lintOutput) $(coverageOutput) $(htmlCoverageOutput)
# end output files
# start basic development targets
compile:
$(gobin) build $(compilePackages)
test: $(foreach target,$(packages),$(buildDir)/output.$(target).test)
lint: $(foreach target,$(packages),$(buildDir)/output.$(target).lint)
coverage: $(coverageOutput)
html-coverage: $(htmlCoverageOutput)
phony := compile lint test coverage html-coverage
# start convenience targets for running tests and coverage tasks on a
# specific package.
test-%: $(buildDir)/output.%.test
coverage-%: $(buildDir)/output.%.coverage
html-coverage-%: $(buildDir)/output.%.coverage.html
lint-%: $(buildDir)/output.%.lint
# end convenience targets
# end basic development targets
# start test and coverage artifacts
testArgs := -v -timeout=1h
ifneq (,$(RUN_TEST))
testArgs += -run='$(RUN_TEST)'
endif
ifneq (,$(RUN_COUNT))
testArgs += -count='$(RUN_COUNT)'
endif
ifneq (,$(RACE_DETECTOR))
testArgs += -race
endif
ifneq (,$(SKIP_LONG))
testArgs += -short
endif
$(buildDir)/output.%.test: .FORCE
$(gobin) test $(testArgs) ./$(if $(subst $(name),,$*),$(subst -,/,$*),) | tee $@
@grep -s -q "^PASS" $@
$(buildDir)/output.%.coverage: .FORCE
$(gobin) test $(testArgs) ./$(if $(subst $(name),,$*),$(subst -,/,$*),) -coverprofile $@ | tee $(buildDir)/output.$*.test
@-[ -f $@ ] && $(gobin) tool cover -func=$@ | sed 's%$(projectPath)/%%' | column -t
@grep -s -q -e "^PASS" $(subst coverage,test,$@)
$(buildDir)/output.%.coverage.html: $(buildDir)/output.%.coverage
$(gobin) tool cover -html=$< -o $@
ifneq (go,$(gobin))
# We have to handle the PATH specially for linting in CI, because if the PATH has a different version of the Go
# binary in it, the linter won't work properly.
lintEnvVars := PATH="$(shell dirname $(gobin)):$(PATH)"
endif
$(buildDir)/output.%.lint: $(buildDir)/run-linter .FORCE
@$(lintEnvVars) ./$< --output=$@ --lintBin=$(buildDir)/golangci-lint --packages='$*'
# end test and coverage artifacts
# start mongodb targets
mongodb/.get-mongodb:
rm -rf mongodb
mkdir -p mongodb
cd mongodb && curl "$(MONGODB_URL)" -o mongodb.tgz && $(MONGODB_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
mongodb/.get-mongosh:
rm -rf mongosh
mkdir -p mongosh
cd mongosh && curl "$(MONGOSH_URL)" -o mongosh.tgz && $(MONGOSH_DECOMPRESS) mongosh.tgz && chmod +x ./mongosh-*/bin/*
cd mongosh && mv ./mongosh-*/bin/* .
get-mongodb: mongodb/.get-mongodb
@touch $<
get-mongosh: mongodb/.get-mongosh
@touch $<
start-mongod: mongodb/.get-mongodb
./mongodb/mongod --dbpath ./mongodb/db_files --port 27017 --replSet amboy
@echo "waiting for mongod to start up"
check-mongod: mongodb/.get-mongodb mongodb/.get-mongosh
./mongosh/mongosh --nodb ./scripts/waitForMongo.js
@echo "mongod is up"
init-rs: mongodb/.get-mongodb mongodb/.get-mongosh
./mongosh/mongosh --eval 'rs.initiate()'
phony += get-mongodb get-mongosh start-mongod check-mongod init-rs
# end mongodb targets
# start module management targets
mod-tidy:
$(gobin) mod tidy
# Check if go.mod and go.sum are clean. If they're clean, then mod tidy should not produce a different result.
verify-mod-tidy:
$(gobin) run cmd/verify-mod-tidy/verify-mod-tidy.go -goBin="$(gobin)"
phony += mod-tidy verify-mod-tidy
# end module management targets
# start cleanup targets
clean:
rm -rf $(buildDir)
clean-results:
rm -rf $(buildDir)/output.*
phony += clean clean-results
# end cleanup targets
# configure phony targets
.FORCE:
.PHONY: $(phony)