github.com/justinjmoses/evergreen@v0.0.0-20170530173719-1d50e381ff0d/makefile (about) 1 # start project configuration 2 name := evergreen 3 buildDir := bin 4 packages := $(name) agent db cli archive remote command taskrunner util plugin hostinit plugin-builtin-git 5 packages += plugin-builtin-gotest plugin-builtin-attach plugin-builtin-manifest plugin-builtin-archive 6 packages += plugin-builtin-shell plugin-builtin-s3copy plugin-builtin-expansions plugin-builtin-s3 7 packages += notify thirdparty alerts auth scheduler model hostutil validator service monitor repotracker 8 packages += model-patch model-artifact model-host model-build model-event model-task db-bsonutil 9 packages += plugin-builtin-attach-xunit cloud-providers cloud-providers-ec2 agent-comm 10 packages += rest-data rest-route rest-model 11 orgPath := github.com/evergreen-ci 12 projectPath := $(orgPath)/$(name) 13 # end project configuration 14 15 16 # start evergreen specific configuration 17 unixPlatforms := linux_amd64 linux_386 linux_s390x linux_arm64 linux_ppc64le solaris_amd64 darwin_amd64 18 windowsPlatforms := windows_amd64 windows_386 19 goos := $(shell go env GOOS) 20 goarch := $(shell go env GOARCH) 21 22 agentBuildDir := executables 23 clientBuildDir := clients 24 25 agentBinaries := $(foreach platform,$(unixPlatforms),$(agentBuildDir)/$(platform)/main) 26 agentBinaries += $(foreach platform,$(windowsPlatforms),$(agentBuildDir)/$(platform)/main.exe) 27 clientBinaries := $(foreach platform,$(unixPlatforms) freebsd_amd64,$(clientBuildDir)/$(platform)/evergreen) 28 clientBinaries += $(foreach platform,$(windowsPlatforms),$(clientBuildDir)/$(platform)/evergreen.exe) 29 30 binaries := $(buildDir)/evergreen_ui_server $(buildDir)/evergreen_runner $(buildDir)/evergreen_api_server 31 raceBinaries := $(foreach bin,$(binaries),$(bin).race) 32 33 agentSource := agent/main/agent.go 34 clientSource := cli/main/cli.go 35 36 distArtifacts := ./public ./service/templates ./service/plugins ./alerts/templates ./notify/templates 37 distContents := $(agentBuildDir) $(clientBuildDir) $(distArtifacts) 38 distTestContents := $(foreach pkg,$(packages),$(buildDir)/test.$(pkg) $(buildDir)/race.$(pkg)) 39 40 srcFiles := makefile $(shell find . -name "*.go" -not -path "./$(buildDir)/*" -not -name "*_test.go" -not -path "./scripts/*" ) 41 testSrcFiles := makefile $(shell find . -name "*.go" -not -path "./$(buildDir)/*") 42 43 projectCleanFiles := $(agentBuildDir) $(clientBuildDir) 44 # static rules for rule for building artifacts 45 define crossCompile 46 @$(vendorGopath) ./$(buildDir)/build-cross-compile -buildName=$* -ldflags="-X=github.com/evergreen-ci/evergreen.BuildRevision=`git rev-parse HEAD`" -goBinary="`which go`" -output=$@ 47 endef 48 # end evergreen specific configuration 49 50 51 # start linting configuration 52 # package, testing, and linter dependencies specified 53 # separately. This is a temporary solution: eventually we should 54 # vendorize all of these dependencies. 55 lintDeps := github.com/alecthomas/gometalinter 56 # include test files and give linters 40s to run to avoid timeouts 57 lintArgs := --tests --deadline=20m --vendor --aggregate --sort="line" 58 # gotype produces false positives because it reads .a files which 59 # are rarely up to date. 60 lintArgs += --disable="gotype" --disable="gas" --disable="gocyclo" 61 lintArgs += --disable="aligncheck" --disable="golint" --disable="goconst" 62 lintArgs += --skip="$(buildDir)" --skip="scripts" --skip="$(gopath)" 63 # add and configure additional linters 64 lintArgs += --enable="goimports" --enable="misspell" --enable="unused" --enable="vet" --enable="unparam" 65 # lintArgs += --enable="lll" --line-length=100 66 lintArgs += --dupl-threshold=175 67 # two similar functions triggered the duplicate warning, but they're not. 68 lintArgs += --exclude="file is not goimported" # test files aren't imported 69 # golint doesn't handle splitting package comments between multiple files. 70 # lintArgs += --exclude="package comment should be of the form \"Package .* \(golint\)" 71 # suppress some lint errors (logging methods could return errors, and error checking in defers.) 72 lintArgs += --exclude=".*([mM]ock.*ator|modadvapi32|osSUSE) is unused \((deadcode|unused)\)$$" 73 lintArgs += --exclude=".*(procInfo|sysInfo|metricsCollector\).start|testSorter).*is unused.*\(unused|deadcode\)$$" 74 lintArgs += --exclude="error return value not checked \(defer.* \(errcheck\)$$" 75 lintArgs += --exclude="defers in this range loop.* \(staticcheck\)$$" 76 lintArgs += --exclude=".*should use time.Until instead of t.Sub\(time.Now\(\)\).* \(gosimple\)$$" 77 lintArgs += --exclude="suspect or:.*\(vet\)$$" 78 # end lint configuration 79 80 81 ###################################################################### 82 ## 83 ## Build rules and instructions for building evergreen binaries and targets. 84 ## 85 ###################################################################### 86 87 88 # start rules for binding agents 89 # build the server binaries: 90 plugins:$(buildDir)/.plugins 91 $(buildDir)/.plugins:Plugins install_plugins.sh 92 ./install_plugins.sh 93 @touch $@ 94 evergreen_api_server:$(buildDir)/evergreen_api_server 95 $(buildDir)/evergreen_api_server:service/api_main/apiserver.go $(buildDir)/build-cross-compile $(srcFiles) 96 $(crossCompile) -directory=$(buildDir) -source=$< 97 evergreen_ui_server:$(buildDir)/evergreen_ui_server 98 $(buildDir)/evergreen_ui_server:service/ui_main/ui.go $(buildDir)/build-cross-compile $(srcFiles) 99 $(crossCompile) -directory=$(buildDir) -source=$< 100 evergreen_runner:$(buildDir)/evergreen_runner 101 $(buildDir)/evergreen_runner:runner/main/runner.go $(buildDir)/build-cross-compile $(srcFiles) 102 $(crossCompile) -directory=$(buildDir) -source=$< 103 # build the server binaries with the race detector: 104 $(buildDir)/evergreen_api_server.race:service/api_main/apiserver.go $(buildDir)/build-cross-compile $(srcFiles) 105 $(crossCompile) -race -directory=$(buildDir) -source=$< 106 $(buildDir)/evergreen_runner.race:runner/main/runner.go $(buildDir)/build-cross-compile $(srcFiles) 107 $(crossCompile) -race -directory=$(buildDir) -source=$< 108 $(buildDir)/evergreen_ui_server.race:service/ui_main/ui.go $(buildDir)/build-cross-compile $(srcFiles) 109 $(crossCompile) -race -directory=$(buildDir) -source=$< 110 phony += $(binaries) $(raceBinaries) 111 # end rules for building server binaries 112 113 114 # start rules for building agents and clis 115 ifeq ($(OS),Windows_NT) 116 agent:$(agentBuildDir)/$(goos)_$(goarch)/main.exe 117 cli:$(clientBuildDir)/$(goos)_$(goarch)/evergreen.exe 118 else 119 agent:$(agentBuildDir)/$(goos)_$(goarch)/main 120 cli:$(clientBuildDir)/$(goos)_$(goarch)/evergreen 121 endif 122 agents:$(agentBinaries) 123 clis:$(clientBinaries) 124 $(agentBuildDir)/%/main $(agentBuildDir)/%/main.exe:$(buildDir)/build-cross-compile $(agentBuildDir)/version $(srcFiles) 125 $(crossCompile) -directory=$(agentBuildDir) -source=$(agentSource) 126 $(clientBuildDir)/%/evergreen $(clientBuildDir)/%/evergreen.exe:$(buildDir)/build-cross-compile $(srcFiles) 127 $(crossCompile) -directory=$(clientBuildDir) -source=$(clientSource) -output=$@ 128 $(agentBuildDir)/version: 129 @mkdir -p $(dir $@) 130 git rev-parse HEAD >| $@ 131 phony += agents agent $(agentBuildDir)/version cli clis 132 # end agent build directives 133 134 135 ###################################################################### 136 ## 137 ## Build, Test, and Dist targets and mechisms. 138 ## 139 ###################################################################### 140 141 # most of the targets and variables in this section are generic 142 # instructions for go programs of all kinds, and are not particularly 143 # specific to evergreen; though the dist targets are more specific than the rest. 144 145 # start dependency installation tools 146 # implementation details for being able to lazily install dependencies. 147 # this block has no project specific configuration but defines 148 # variables that project specific information depends on 149 gopath := $(shell go env GOPATH) 150 ifeq ($(OS),Windows_NT) 151 gopath := $(shell cygpath -m $(gopath)) 152 endif 153 testOutput := $(foreach target,$(packages),$(buildDir)/output.$(target).test) 154 raceOutput := $(foreach target,$(packages),$(buildDir)/output.$(target).race) 155 testBin := $(foreach target,$(packages),$(buildDir)/test.$(target)) 156 raceBin := $(foreach target,$(packages),$(buildDir)/race.$(target)) 157 lintTargets := $(foreach target,$(packages),lint-$(target)) 158 coverageOutput := $(foreach target,$(packages),$(buildDir)/output.$(target).coverage) 159 coverageHtmlOutput := $(foreach target,$(packages),$(buildDir)/output.$(target).coverage.html) 160 $(gopath)/src/%: 161 @-[ ! -d $(gopath) ] && mkdir -p $(gopath) || true 162 go get $(subst $(gopath)/src/,,$@) 163 # end dependency installation tools 164 165 166 # lint setup targets 167 lintDeps := $(addprefix $(gopath)/src/,$(lintDeps)) 168 $(buildDir)/.lintSetup:$(lintDeps) 169 @-$(gopath)/bin/gometalinter --install >/dev/null && touch $@ 170 $(buildDir)/run-linter:scripts/run-linter.go $(buildDir)/.lintSetup 171 $(vendorGopath) go build -o $@ $< 172 # end lint setup targets 173 174 175 # distribution targets and implementation 176 $(buildDir)/build-cross-compile:scripts/build-cross-compile.go makefile 177 @mkdir -p $(buildDir) 178 @GOOS="" GOOARCH="" go build -o $@ $< 179 @echo go build -o $@ $< 180 $(buildDir)/make-tarball:scripts/make-tarball.go $(buildDir)/render-gopath 181 $(vendorGopath) go build -o $@ $< 182 dist:$(buildDir)/dist.tar.gz 183 dist-test:$(buildDir)/dist-test.tar.gz 184 dist-race: $(buildDir)/dist-race.tar.gz 185 dist-source:$(buildDir)/dist-source.tar.gz 186 $(buildDir)/dist.tar.gz:$(buildDir)/make-tarball plugins agents clis $(binaries) 187 ./$< --name $@ --prefix $(name) $(foreach item,$(binaries) $(distContents),--item $(item)) 188 $(buildDir)/dist-race.tar.gz:$(buildDir)/make-tarball plugins makefile $(raceBinaries) $(agentBinaries) $(clientBinaries) 189 ./$< -name $@ --prefix $(name)-race $(foreach item,$(raceBinaries) $(distContents),--item $(item)) 190 $(buildDir)/dist-test.tar.gz:$(buildDir)/make-tarball plugins makefile $(binaries) $(raceBinaries) 191 ./$< -name $@ --prefix $(name)-tests $(foreach item,$(distContents) $(distTestContents),--item $(item)) $(foreach item,,--item $(item)) 192 $(buildDir)/dist-source.tar.gz:$(buildDir)/make-tarball $(srcFiles) $(testSrcFiles) makefile 193 ./$< --name $@ --prefix $(name) $(subst $(name),,$(foreach pkg,$(packages),--item ./$(subst -,/,$(pkg)))) --item ./scripts --item makefile --exclude "$(name)" --exclude "^.git/" --exclude "$(buildDir)/" 194 # end main build 195 196 197 # userfacing targets for basic build and development operations 198 build:$(binaries) cli agent 199 build-race:$(raceBinaries) 200 lint:$(buildDir)/output.lint 201 test:$(foreach target,$(packages),test-$(target)) 202 race:$(foreach target,$(packages),race-$(target)) 203 coverage:$(coverageOutput) 204 coverage-html:$(coverageHtmlOutput) 205 list-tests: 206 @echo -e "test targets:" $(foreach target,$(packages),\\n\\ttest-$(target)) 207 list-race: 208 @echo -e "test (race detector) targets:" $(foreach target,$(packages),\\n\\trace-$(target)) 209 phony += lint lint-deps build build-race race test coverage coverage-html list-race list-tests 210 .PRECIOUS:$(testOutput) $(raceOutput) $(coverageOutput) $(coverageHtmlOutput) 211 .PRECIOUS:$(foreach target,$(packages),$(buildDir)/test.$(target)) 212 .PRECIOUS:$(foreach target,$(packages),$(buildDir)/race.$(target)) 213 .PRECIOUS:$(foreach target,$(packages),$(buildDir)/output.$(target).lint) 214 .PRECIOUS:$(buildDir)/output.lint 215 # end front-ends 216 217 218 # convenience targets for runing tests and coverage tasks on a 219 # specific package. 220 race-%:$(buildDir)/output.%.race 221 @grep -s -q -e "^PASS" $< && ! grep -s -q "^WARNING: DATA RACE" $< 222 test-%:$(buildDir)/output.%.test 223 @grep -s -q -e "^PASS" $< 224 coverage-%:$(buildDir)/output.%.coverage 225 @grep -s -q -e "^PASS" $(subst coverage,test,$<) 226 html-coverage-%:$(buildDir)/output.%.coverage $(buildDir)/output.%.coverage.html 227 @grep -s -q -e "^PASS" $(subst coverage,test,$<) 228 lint-%:$(buildDir)/output.%.lint 229 @grep -v -s -q "^--- FAIL" $< 230 # end convienence targets 231 232 233 # start vendoring configuration 234 # begin with configuration of dependencies 235 vendorDeps := github.com/Masterminds/glide 236 vendorDeps := $(addprefix $(gopath)/src/,$(vendorDeps)) 237 vendor-deps:$(vendorDeps) 238 # this allows us to store our vendored code in vendor and use 239 # symlinks to support vendored code both in the legacy style and with 240 # new-style vendor directories. When this codebase can drop support 241 # for go1.4, we can delete most of this. 242 -include $(buildDir)/makefile.vendor 243 # nested vendoring is used to support projects that have 244 nestedVendored := vendor/github.com/mongodb/grip 245 nestedVendored := $(foreach project,$(nestedVendored),$(project)/build/vendor) 246 $(buildDir)/makefile.vendor:$(buildDir)/render-gopath makefile 247 @mkdir -p $(buildDir) 248 @echo "vendorGopath := \$$(shell \$$(buildDir)/render-gopath $(nestedVendored))" >| $@ 249 # targets for the directory components and manipulating vendored files. 250 vendor-sync:$(vendorDeps) 251 rm -rf vendor 252 glide install -s 253 rm vendor/github.com/fsouza/go-dockerclient/external/github.com/Sirupsen/logrus/terminal_freebsd.go 254 vendor-clean: 255 rm -rf vendor/github.com/stretchr/testify/vendor/ 256 change-go-version: 257 rm -rf $(buildDir)/make-vendor $(buildDir)/render-gopath 258 @$(MAKE) $(makeArgs) vendor > /dev/null 2>&1 259 vendor:$(buildDir)/vendor/src 260 $(MAKE) $(makeArgs) -C vendor/github.com/mongodb/grip $@ 261 $(buildDir)/vendor/src:$(buildDir)/make-vendor $(buildDir)/render-gopath 262 @./$(buildDir)/make-vendor 263 # targets to build the small programs used to support vendoring. 264 $(buildDir)/make-vendor:scripts/make-vendor.go 265 @mkdir -p $(buildDir) 266 go build -o $@ $< 267 $(buildDir)/render-gopath:scripts/render-gopath.go 268 @mkdir -p $(buildDir) 269 go build -o $@ $< 270 # define dependencies for scripts 271 scripts/make-vendor.go:scripts/vendoring/vendoring.go 272 scripts/render-gopath.go:scripts/vendoring/vendoring.go 273 # add phony targets 274 phony += vendor vendor-deps vendor-clean vendor-sync change-go-version 275 # end vendoring tooling configuration 276 277 278 # start test and coverage artifacts 279 # This varable includes everything that the tests actually need to 280 # run. (The "build" target is intentional and makes these targetsb 281 # rerun as expected.) 282 testRunDeps := $(name) 283 testTimeout := --test.timeout=10m 284 testArgs := -test.v $(testTimeout) 285 testRunEnv := EVGHOME=$(shell pwd) 286 ifeq ($(OS),Windows_NT) 287 testRunEnv := EVGHOME=$(shell cygpath -m `pwd`) 288 endif 289 ifneq (,$(SETTINGS_OVERRIDE)) 290 testRunEnv += SETTINGS_OVERRIDE=$(SETTINGS_OVERRIDE) 291 endif 292 ifneq (,$(RUN_TEST)) 293 testArgs += -test.run='$(RUN_TEST)' 294 endif 295 # targets to compile 296 $(buildDir)/test.%:$(testSrcFiles) 297 $(vendorGopath) go test $(if $(DISABLE_COVERAGE),,-covermode=count) -c -o $@ ./$(subst -,/,$*) 298 $(buildDir)/race.%:$(testSrcFiles) 299 $(vendorGopath) go test -race -c -o $@ ./$(subst -,/,$*) 300 # targets to run any tests in the top-level package 301 $(buildDir)/test.$(name):$(testSrcFiles) 302 $(vendorGopath) go test $(if $(DISABLE_COVERAGE),,-covermode=count) -c -o $@ ./ 303 $(buildDir)/race.$(name):$(testSrcFiles) 304 $(vendorGopath) go test -race -c -o $@ ./ 305 # targets to run the tests and report the output 306 $(buildDir)/output.%.test:$(buildDir)/test.% .FORCE 307 $(testRunEnv) ./$< $(testArgs) 2>&1 | tee $@ 308 $(buildDir)/output.%.race:$(buildDir)/race.% .FORCE 309 $(testRunEnv) ./$< $(testArgs) 2>&1 | tee $@ 310 # targets to generate gotest output from the linter. 311 $(buildDir)/output.%.lint:$(buildDir)/run-linter $(testSrcFiles) .FORCE 312 @./$< --output=$@ --lintArgs='$(lintArgs)' --packages='$*' 313 $(buildDir)/output.lint:$(buildDir)/run-linter .FORCE 314 @./$< --output="$@" --lintArgs='$(lintArgs)' --packages="$(packages)" 315 # targets to process and generate coverage reports 316 $(buildDir)/output.%.coverage:$(buildDir)/test.% .FORCE 317 $(testRunEnv) ./$< $(testArgs) -test.coverprofile=./$@ 2>&1 | tee $(subst coverage,test,$@) 318 @-[ -f $@ ] && go tool cover -func=$@ | sed 's%$(projectPath)/%%' | column -t 319 $(buildDir)/output.%.coverage.html:$(buildDir)/output.%.coverage 320 $(vendorGopath) go tool cover -html=$< -o $@ 321 # end test and coverage artifacts 322 323 324 # clean and other utility targets 325 clean: 326 rm -rf $(lintDeps) $(buildDir)/test.* $(buildDir)/coverage.* $(buildDir)/race.* $(projectCleanFiles) 327 phony += clean 328 # end dependency targets 329 330 # configure phony targets 331 .FORCE: 332 .PHONY:$(phony) .FORCE