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