diff options
author | Ben Kochie <superq@gmail.com> | 2019-01-04 16:58:53 +0100 |
---|---|---|
committer | Johannes 'fish' Ziemke <github@freigeist.org> | 2019-01-04 15:58:53 +0000 |
commit | 070e4b2e17750941e38ebb4037d67da3a05a6788 (patch) | |
tree | 34ec9a52a095916551636381520ce7e3ae69f28f /Makefile.common | |
parent | 085d872aafdca918069bb1fdf767cf52b15ee961 (diff) | |
download | prometheus_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.common | 40 |
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 | |||
29 | GOFMT ?= $(GO)fmt | 29 | GOFMT ?= $(GO)fmt |
30 | FIRST_GOPATH := $(firstword $(subst :, ,$(shell $(GO) env GOPATH))) | 30 | FIRST_GOPATH := $(firstword $(subst :, ,$(shell $(GO) env GOPATH))) |
31 | GOOPTS ?= | 31 | GOOPTS ?= |
32 | GOHOSTOS ?= $(shell $(GO) env GOHOSTOS) | ||
33 | GOHOSTARCH ?= $(shell $(GO) env GOHOSTARCH) | ||
32 | 34 | ||
33 | GO_VERSION ?= $(shell $(GO) version) | 35 | GO_VERSION ?= $(shell $(GO) version) |
34 | GO_VERSION_NUMBER ?= $(word 3, $(GO_VERSION)) | 36 | GO_VERSION_NUMBER ?= $(word 3, $(GO_VERSION)) |
@@ -62,8 +64,6 @@ PROMU := $(FIRST_GOPATH)/bin/promu | |||
62 | STATICCHECK := $(FIRST_GOPATH)/bin/staticcheck | 64 | STATICCHECK := $(FIRST_GOPATH)/bin/staticcheck |
63 | pkgs = ./... | 65 | pkgs = ./... |
64 | 66 | ||
65 | GOHOSTOS ?= $(shell $(GO) env GOHOSTOS) | ||
66 | GOHOSTARCH ?= $(shell $(GO) env GOHOSTARCH) | ||
67 | ifeq (arm, $(GOHOSTARCH)) | 67 | ifeq (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 | ||
74 | PROMU_VERSION ?= 0.2.0 | 74 | PROMU_VERSION ?= 0.2.0 |
75 | PROMU_URL := https://github.com/prometheus/promu/releases/download/v$(PROMU_VERSION)/promu-$(PROMU_VERSION).$(GO_BUILD_PLATFORM).tar.gz | 75 | PROMU_URL := https://github.com/prometheus/promu/releases/download/v$(PROMU_VERSION)/promu-$(PROMU_VERSION).$(GO_BUILD_PLATFORM).tar.gz |
76 | STATICCHECK_VERSION ?= 2019.1 | ||
77 | STATICCHECK_URL := https://github.com/dominikh/go-tools/releases/download/$(STATICCHECK_VERSION)/staticcheck_$(GOHOSTOS)_$(GOHOSTARCH) | ||
76 | 78 | ||
77 | PREFIX ?= $(shell pwd) | 79 | PREFIX ?= $(shell pwd) |
78 | BIN_DIR ?= $(shell pwd) | 80 | BIN_DIR ?= $(shell pwd) |
79 | DOCKER_IMAGE_TAG ?= $(subst /,-,$(shell git rev-parse --abbrev-ref HEAD)) | 81 | DOCKER_IMAGE_TAG ?= $(subst /,-,$(shell git rev-parse --abbrev-ref HEAD)) |
80 | DOCKER_REPO ?= prom | 82 | DOCKER_REPO ?= prom |
81 | 83 | ||
84 | ifeq ($(GOHOSTARCH),amd64) | ||
85 | ifeq ($(GOHOSTOS),$(filter $(GOHOSTOS),linux freebsd darwin windows)) | ||
86 | # Only supported on amd64 | ||
87 | test-flags := -race | ||
88 | endif | ||
89 | endif | ||
90 | |||
82 | .PHONY: all | 91 | .PHONY: all |
83 | all: precheck style staticcheck unused build test | 92 | all: precheck style staticcheck unused build test |
84 | 93 | ||
@@ -116,7 +125,7 @@ common-test-short: | |||
116 | .PHONY: common-test | 125 | .PHONY: common-test |
117 | common-test: | 126 | common-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 |
122 | common-format: | 131 | common-format: |
@@ -131,8 +140,12 @@ common-vet: | |||
131 | .PHONY: common-staticcheck | 140 | .PHONY: common-staticcheck |
132 | common-staticcheck: $(STATICCHECK) | 141 | common-staticcheck: $(STATICCHECK) |
133 | @echo ">> running staticcheck" | 142 | @echo ">> running staticcheck" |
143 | chmod +x $(STATICCHECK) | ||
134 | ifdef GO111MODULE | 144 | ifdef 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) | ||
136 | else | 149 | else |
137 | $(STATICCHECK) -ignore "$(STATICCHECK_IGNORE)" $(pkgs) | 150 | $(STATICCHECK) -ignore "$(STATICCHECK_IGNORE)" $(pkgs) |
138 | endif | 151 | endif |
@@ -146,8 +159,9 @@ else | |||
146 | ifdef GO111MODULE | 159 | ifdef 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 |
162 | ifeq (,$(wildcard vendor)) | ||
149 | @git diff --exit-code -- go.sum go.mod | 163 | @git diff --exit-code -- go.sum go.mod |
150 | ifneq (,$(wildcard vendor)) | 164 | else |
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): |
197 | ifdef 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}; | ||
207 | else | ||
208 | GOOS= GOARCH= GO111MODULE=off $(GO) get -u honnef.co/go/tools/cmd/staticcheck | ||
209 | endif | ||
210 | 212 | ||
211 | ifdef GOVENDOR | 213 | ifdef GOVENDOR |
212 | .PHONY: $(GOVENDOR) | 214 | .PHONY: $(GOVENDOR) |