diff --git a/Makefile b/Makefile index 86658d407..9d678ca12 100644 --- a/Makefile +++ b/Makefile @@ -1,45 +1,60 @@ export GO15VENDOREXPERIMENT=1 BENCH_FLAGS ?= -cpuprofile=cpu.pprof -memprofile=mem.pprof -benchmem -PACKAGES ?= $(shell glide novendor) +PKGS ?= $(shell glide novendor) +# Many Go tools take file globs or directories as arguments instead of packages. +PKG_DIRS ?= *.go + +# The linting tools evolve with each Go version, so run them only on the latest +# stable release. +GO_VERSION := $(shell go version | cut -d " " -f 3) +GO_MINOR_VERSION := $(word 2,$(subst ., ,$(GO_VERSION))) +LINTABLE_MINOR_VERSIONS := 6 +ifneq ($(filter $(LINTABLE_MINOR_VERSIONS),$(GO_MINOR_VERSION)),) +SHOULD_LINT := true +endif + .PHONY: all all: lint test .PHONY: dependencies dependencies: + @echo "Installing Glide and locked dependencies..." glide --version || go get -u -f github.com/Masterminds/glide glide install - go install ./vendor/github.com/golang/lint/golint + @echo "Installing test dependencies..." go install ./vendor/github.com/axw/gocov/gocov go install ./vendor/github.com/mattn/goveralls +ifdef SHOULD_LINT + @echo "Installing golint..." + go install ./vendor/github.com/golang/lint/golint +else + @echo "Not installing golint, since we don't expect to lint on" $(GO_VERSION) +endif .PHONY: lint lint: @rm -rf lint.log @echo "Checking formatting..." - @gofmt -d -s *.go benchmarks encoder 2>&1 | tee lint.log + @gofmt -d -s $(PKG_DIRS) 2>&1 | tee lint.log @echo "Checking vet..." - @go tool vet *.go 2>&1 | tee -a lint.log - @go tool vet benchmarks 2>&1 | tee -a lint.log - @go tool vet encoder 2>&1 | tee -a lint.log + @$(foreach dir,$(PKG_DIRS),go tool vet $(dir) 2>&1 | tee -a lint.log;) @echo "Checking lint..." - @golint . 2>&1 | tee -a lint.log - @golint benchmarks 2>&1 | tee -a lint.log - @golint encoder 2>&1 | tee -a lint.log + @$(foreach dir,$(PKG_DIRS),golint $(dir) 2>&1 | tee -a lint.log;) @echo "Checking for unresolved FIXMEs..." @git grep -i fixme | grep -v -e vendor -e Makefile | tee -a lint.log @[ ! -s lint.log ] .PHONY: test test: - go test -race $(PACKAGES) + go test -race $(PKGS) .PHONY: coveralls coveralls: - goveralls -service=travis-ci $(PACKAGES) + goveralls -service=travis-ci $(PKGS) .PHONY: bench BENCH ?= . bench: - go test -bench=$(BENCH) $(BENCH_FLAGS) ./benchmarks + go test -bench=$(BENCH) $(BENCH_FLAGS) .