aboutsummaryrefslogtreecommitdiff
path: root/Makefile.common
diff options
context:
space:
mode:
authorBen Kochie <superq@gmail.com>2019-01-04 16:58:53 +0100
committerJohannes 'fish' Ziemke <github@freigeist.org>2019-01-04 15:58:53 +0000
commit070e4b2e17750941e38ebb4037d67da3a05a6788 (patch)
tree34ec9a52a095916551636381520ce7e3ae69f28f /Makefile.common
parent085d872aafdca918069bb1fdf767cf52b15ee961 (diff)
downloadprometheus_node_collector-070e4b2e17750941e38ebb4037d67da3a05a6788.tar.bz2
prometheus_node_collector-070e4b2e17750941e38ebb4037d67da3a05a6788.tar.xz
prometheus_node_collector-070e4b2e17750941e38ebb4037d67da3a05a6788.zip
Update Makefile.common (#1220)
* Update Makefile.common Update to new staticcheck method[0]. [0]: https://github.com/prometheus/prometheus/pull/5057 Signed-off-by: Ben Kochie <superq@gmail.com> * Fix staticcheck errors. Signed-off-by: Ben Kochie <superq@gmail.com>
Diffstat (limited to 'Makefile.common')
-rw-r--r--Makefile.common40
1 files changed, 21 insertions, 19 deletions
diff --git a/Makefile.common b/Makefile.common
index f26a788..fff85f9 100644
--- a/Makefile.common
+++ b/Makefile.common
@@ -29,6 +29,8 @@ GO ?= go
29GOFMT ?= $(GO)fmt 29GOFMT ?= $(GO)fmt
30FIRST_GOPATH := $(firstword $(subst :, ,$(shell $(GO) env GOPATH))) 30FIRST_GOPATH := $(firstword $(subst :, ,$(shell $(GO) env GOPATH)))
31GOOPTS ?= 31GOOPTS ?=
32GOHOSTOS ?= $(shell $(GO) env GOHOSTOS)
33GOHOSTARCH ?= $(shell $(GO) env GOHOSTARCH)
32 34
33GO_VERSION ?= $(shell $(GO) version) 35GO_VERSION ?= $(shell $(GO) version)
34GO_VERSION_NUMBER ?= $(word 3, $(GO_VERSION)) 36GO_VERSION_NUMBER ?= $(word 3, $(GO_VERSION))
@@ -62,8 +64,6 @@ PROMU := $(FIRST_GOPATH)/bin/promu
62STATICCHECK := $(FIRST_GOPATH)/bin/staticcheck 64STATICCHECK := $(FIRST_GOPATH)/bin/staticcheck
63pkgs = ./... 65pkgs = ./...
64 66
65GOHOSTOS ?= $(shell $(GO) env GOHOSTOS)
66GOHOSTARCH ?= $(shell $(GO) env GOHOSTARCH)
67ifeq (arm, $(GOHOSTARCH)) 67ifeq (arm, $(GOHOSTARCH))
68 GOHOSTARM ?= $(shell GOARM= $(GO) env GOARM) 68 GOHOSTARM ?= $(shell GOARM= $(GO) env GOARM)
69 GO_BUILD_PLATFORM ?= $(GOHOSTOS)-$(GOHOSTARCH)v$(GOHOSTARM) 69 GO_BUILD_PLATFORM ?= $(GOHOSTOS)-$(GOHOSTARCH)v$(GOHOSTARM)
@@ -73,12 +73,21 @@ endif
73 73
74PROMU_VERSION ?= 0.2.0 74PROMU_VERSION ?= 0.2.0
75PROMU_URL := https://github.com/prometheus/promu/releases/download/v$(PROMU_VERSION)/promu-$(PROMU_VERSION).$(GO_BUILD_PLATFORM).tar.gz 75PROMU_URL := https://github.com/prometheus/promu/releases/download/v$(PROMU_VERSION)/promu-$(PROMU_VERSION).$(GO_BUILD_PLATFORM).tar.gz
76STATICCHECK_VERSION ?= 2019.1
77STATICCHECK_URL := https://github.com/dominikh/go-tools/releases/download/$(STATICCHECK_VERSION)/staticcheck_$(GOHOSTOS)_$(GOHOSTARCH)
76 78
77PREFIX ?= $(shell pwd) 79PREFIX ?= $(shell pwd)
78BIN_DIR ?= $(shell pwd) 80BIN_DIR ?= $(shell pwd)
79DOCKER_IMAGE_TAG ?= $(subst /,-,$(shell git rev-parse --abbrev-ref HEAD)) 81DOCKER_IMAGE_TAG ?= $(subst /,-,$(shell git rev-parse --abbrev-ref HEAD))
80DOCKER_REPO ?= prom 82DOCKER_REPO ?= prom
81 83
84ifeq ($(GOHOSTARCH),amd64)
85 ifeq ($(GOHOSTOS),$(filter $(GOHOSTOS),linux freebsd darwin windows))
86 # Only supported on amd64
87 test-flags := -race
88 endif
89endif
90
82.PHONY: all 91.PHONY: all
83all: precheck style staticcheck unused build test 92all: precheck style staticcheck unused build test
84 93
@@ -116,7 +125,7 @@ common-test-short:
116.PHONY: common-test 125.PHONY: common-test
117common-test: 126common-test:
118 @echo ">> running all tests" 127 @echo ">> running all tests"
119 GO111MODULE=$(GO111MODULE) $(GO) test -race $(GOOPTS) $(pkgs) 128 GO111MODULE=$(GO111MODULE) $(GO) test $(test-flags) $(GOOPTS) $(pkgs)
120 129
121.PHONY: common-format 130.PHONY: common-format
122common-format: 131common-format:
@@ -131,8 +140,12 @@ common-vet:
131.PHONY: common-staticcheck 140.PHONY: common-staticcheck
132common-staticcheck: $(STATICCHECK) 141common-staticcheck: $(STATICCHECK)
133 @echo ">> running staticcheck" 142 @echo ">> running staticcheck"
143 chmod +x $(STATICCHECK)
134ifdef GO111MODULE 144ifdef GO111MODULE
135 GO111MODULE=$(GO111MODULE) $(STATICCHECK) -ignore "$(STATICCHECK_IGNORE)" -checks "SA*" $(pkgs) 145# 'go list' needs to be executed before staticcheck to prepopulate the modules cache.
146# Otherwise staticcheck might fail randomly for some reason not yet explained.
147 GO111MODULE=$(GO111MODULE) $(GO) list -e -compiled -test=true -export=false -deps=true -find=false -tags= -- ./... > /dev/null
148 GO111MODULE=$(GO111MODULE) $(STATICCHECK) -ignore "$(STATICCHECK_IGNORE)" $(pkgs)
136else 149else
137 $(STATICCHECK) -ignore "$(STATICCHECK_IGNORE)" $(pkgs) 150 $(STATICCHECK) -ignore "$(STATICCHECK_IGNORE)" $(pkgs)
138endif 151endif
@@ -146,8 +159,9 @@ else
146ifdef GO111MODULE 159ifdef GO111MODULE
147 @echo ">> running check for unused/missing packages in go.mod" 160 @echo ">> running check for unused/missing packages in go.mod"
148 GO111MODULE=$(GO111MODULE) $(GO) mod tidy 161 GO111MODULE=$(GO111MODULE) $(GO) mod tidy
162ifeq (,$(wildcard vendor))
149 @git diff --exit-code -- go.sum go.mod 163 @git diff --exit-code -- go.sum go.mod
150ifneq (,$(wildcard vendor)) 164else
151 @echo ">> running check for unused packages in vendor/" 165 @echo ">> running check for unused packages in vendor/"
152 GO111MODULE=$(GO111MODULE) $(GO) mod vendor 166 GO111MODULE=$(GO111MODULE) $(GO) mod vendor
153 @git diff --exit-code -- go.sum go.mod vendor/ 167 @git diff --exit-code -- go.sum go.mod vendor/
@@ -192,21 +206,9 @@ proto:
192 @echo ">> generating code from proto files" 206 @echo ">> generating code from proto files"
193 @./scripts/genproto.sh 207 @./scripts/genproto.sh
194 208
195.PHONY: $(STATICCHECK)
196$(STATICCHECK): 209$(STATICCHECK):
197ifdef GO111MODULE 210 mkdir -p $(FIRST_GOPATH)/bin
198# Get staticcheck from a temporary directory to avoid modifying the local go.{mod,sum}. 211 curl -s -L $(STATICCHECK_URL) > $(STATICCHECK)
199# See https://github.com/golang/go/issues/27643.
200# For now, we are using the next branch of staticcheck because master isn't compatible yet with Go modules.
201 tmpModule=$$(mktemp -d 2>&1) && \
202 mkdir -p $${tmpModule}/staticcheck && \
203 cd "$${tmpModule}"/staticcheck && \
204 GO111MODULE=on $(GO) mod init example.com/staticcheck && \
205 GO111MODULE=on GOOS= GOARCH= $(GO) get -u honnef.co/go/tools/cmd/staticcheck@next && \
206 rm -rf $${tmpModule};
207else
208 GOOS= GOARCH= GO111MODULE=off $(GO) get -u honnef.co/go/tools/cmd/staticcheck
209endif
210 212
211ifdef GOVENDOR 213ifdef GOVENDOR
212.PHONY: $(GOVENDOR) 214.PHONY: $(GOVENDOR)