@@ -36,29 +36,6 @@ GO_VERSION ?= $(shell $(GO) version)
3636GO_VERSION_NUMBER ?= $(word 3, $(GO_VERSION))
3737PRE_GO_111 ?= $(shell echo $(GO_VERSION_NUMBER) | grep -E 'go1\.(10|[0-9])\.')
3838
39- GOVENDOR :=
40- GO111MODULE :=
41- ifeq (, $(PRE_GO_111))
42- ifneq (,$(wildcard go.mod))
43- # Enforce Go modules support just in case the directory is inside GOPATH (and for Travis CI).
44- GO111MODULE := on
45-
46- ifneq (,$(wildcard vendor))
47- # Always use the local vendor/ directory to satisfy the dependencies.
48- GOOPTS := $(GOOPTS) -mod=vendor
49- endif
50- endif
51- else
52- ifneq (,$(wildcard go.mod))
53- ifneq (,$(wildcard vendor))
54- $(warning This repository requires Go >= 1.11 because of Go modules)
55- $(warning Some recipes may not work as expected as the current Go runtime is '$(GO_VERSION_NUMBER)')
56- endif
57- else
58- # This repository isn't using Go modules (yet).
59- GOVENDOR := $(FIRST_GOPATH)/bin/govendor
60- endif
61- endif
6239PROMU := $(FIRST_GOPATH)/bin/promu
6340pkgs = ./...
6441
@@ -83,7 +60,7 @@ PROMU_URL := https://github.com/prometheus/promu/releases/download/v$(PROMU_
8360
8461GOLANGCI_LINT :=
8562GOLANGCI_LINT_OPTS ?=
86- GOLANGCI_LINT_VERSION ?= v1.42.0
63+ GOLANGCI_LINT_VERSION ?= v1.45.2
8764# golangci-lint only supports linux, darwin and windows platforms on i386/amd64.
8865# windows isn't included here because of the path separator being different.
8966ifeq ($(GOHOSTOS),$(filter $(GOHOSTOS),linux darwin))
@@ -139,87 +116,63 @@ common-style:
139116.PHONY: common-deps
140117common-deps:
141118 @echo ">> getting dependencies"
142- ifdef GO111MODULE
143- GO111MODULE=$(GO111MODULE) $(GO) mod download
144- else
145- $(GO) get $(GOOPTS) -t ./...
146- endif
119+ $(GO) mod download
147120
148121.PHONY: update-go-deps
149122update-go-deps:
150123 @echo ">> updating Go dependencies"
151124 @for m in $$($(GO) list -mod=readonly -m -f '{{ if and (not .Indirect) (not .Main)}}{{.Path}}{{end}}' all); do \
152125 $(GO) get -d $$m; \
153126 done
154- GO111MODULE=$(GO111MODULE) $(GO) mod tidy
155- ifneq (,$(wildcard vendor))
156- GO111MODULE=$(GO111MODULE) $(GO) mod vendor
157- endif
127+ $(GO) mod tidy
158128
159129.PHONY: common-test-short
160130common-test-short: $(GOTEST_DIR)
161131 @echo ">> running short tests"
162- GO111MODULE=$(GO111MODULE) $(GOTEST) -short $(GOOPTS) $(pkgs)
132+ $(GOTEST) -short $(GOOPTS) $(pkgs)
163133
164134.PHONY: common-test
165135common-test: $(GOTEST_DIR)
166136 @echo ">> running all tests"
167- GO111MODULE=$(GO111MODULE) $(GOTEST) $(test-flags) $(GOOPTS) $(pkgs)
137+ $(GOTEST) $(test-flags) $(GOOPTS) $(pkgs)
168138
169139$(GOTEST_DIR):
170140 @mkdir -p $@
171141
172142.PHONY: common-format
173143common-format:
174144 @echo ">> formatting code"
175- GO111MODULE=$(GO111MODULE) $(GO) fmt $(pkgs)
145+ $(GO) fmt $(pkgs)
176146
177147.PHONY: common-vet
178148common-vet:
179149 @echo ">> vetting code"
180- GO111MODULE=$(GO111MODULE) $(GO) vet $(GOOPTS) $(pkgs)
150+ $(GO) vet $(GOOPTS) $(pkgs)
181151
182152.PHONY: common-lint
183153common-lint: $(GOLANGCI_LINT)
184154ifdef GOLANGCI_LINT
185155 @echo ">> running golangci-lint"
186- ifdef GO111MODULE
187156# 'go list' needs to be executed before staticcheck to prepopulate the modules cache.
188157# Otherwise staticcheck might fail randomly for some reason not yet explained.
189- GO111MODULE=$(GO111MODULE) $(GO) list -e -compiled -test=true -export=false -deps=true -find=false -tags= -- ./... > /dev/null
190- GO111MODULE=$(GO111MODULE) $(GOLANGCI_LINT) run $(GOLANGCI_LINT_OPTS) $(pkgs)
191- else
192- $(GOLANGCI_LINT) run $(pkgs)
193- endif
158+ $(GO) list -e -compiled -test=true -export=false -deps=true -find=false -tags= -- ./... > /dev/null
159+ $(GOLANGCI_LINT) run $(GOLANGCI_LINT_OPTS) $(pkgs)
194160endif
195161
196162# For backward-compatibility.
197163.PHONY: common-staticcheck
198164common-staticcheck: lint
199165
200166.PHONY: common-unused
201- common-unused: $(GOVENDOR)
202- ifdef GOVENDOR
203- @echo ">> running check for unused packages"
204- @$(GOVENDOR) list +unused | grep . && exit 1 || echo 'No unused packages'
205- else
206- ifdef GO111MODULE
167+ common-unused:
207168 @echo ">> running check for unused/missing packages in go.mod"
208- GO111MODULE=$(GO111MODULE) $(GO) mod tidy
209- ifeq (,$(wildcard vendor))
169+ $(GO) mod tidy
210170 @git diff --exit-code -- go.sum go.mod
211- else
212- @echo ">> running check for unused packages in vendor/"
213- GO111MODULE=$(GO111MODULE) $(GO) mod vendor
214- @git diff --exit-code -- go.sum go.mod vendor/
215- endif
216- endif
217- endif
218171
219172.PHONY: common-build
220173common-build: promu
221174 @echo ">> building binaries"
222- GO111MODULE=$(GO111MODULE) $(PROMU) build --prefix $(PREFIX) $(PROMU_BINARIES)
175+ $(PROMU) build --prefix $(PREFIX) $(PROMU_BINARIES)
223176
224177.PHONY: common-tarball
225178common-tarball: promu
@@ -275,12 +228,6 @@ $(GOLANGCI_LINT):
275228 | sh -s -- -b $(FIRST_GOPATH)/bin $(GOLANGCI_LINT_VERSION)
276229endif
277230
278- ifdef GOVENDOR
279- .PHONY: $(GOVENDOR)
280- $(GOVENDOR):
281- GOOS= GOARCH= $(GO) get -u github.com/kardianos/govendor
282- endif
283-
284231.PHONY: precheck
285232precheck::
286233
0 commit comments