@@ -160,6 +160,24 @@ $$(TOOLS_HOST_DIR)/$(1)-v$(2): |$$(TOOLS_HOST_DIR)
160160 @$$(OK ) go get $(3 )
161161endef # tool.go.get
162162
163+ # Creates a target for installing a go tool from source
164+ # 1 tool, 2 version, 3 tool url, 4 go env vars
165+ define tool.go.install
166+ $(call tool,$(1 ) ,$(2 ) )
167+
168+ $$(TOOLS_HOST_DIR ) /$(1 ) -v$(2 ) : |$$(TOOLS_HOST_DIR )
169+ @echo ${TIME} ${BLUE}[TOOL]${CNone} go install $(3 ) @$(2 )
170+ @mkdir -p $$(TOOLS_HOST_DIR ) /tmp-$(1 ) -v$(2 ) || $$(FAIL )
171+ @mkdir -p $$(TOOLS_DIR ) /go/$(1 ) -v$(2 ) / && cd $$(TOOLS_DIR ) /go/$(1 ) -v$(2 ) / && $(GOHOST ) mod init tools && \
172+ $(4 ) GO111MODULE=on GOPATH=$$(TOOLS_HOST_DIR ) /tmp-$(1 ) -v$(2 ) $(GOHOST ) install $(3 ) @$(2 ) || $$(FAIL )
173+ @find $$(TOOLS_HOST_DIR ) /tmp-$(1 ) -v$(2 ) -type f -print0 | xargs -0 chmod 0644 || $$(FAIL )
174+ @find $$(TOOLS_HOST_DIR ) /tmp-$(1 ) -v$(2 ) -type d -print0 | xargs -0 chmod 0755 || $$(FAIL )
175+ @mv $$(TOOLS_HOST_DIR ) /tmp-$(1 ) -v$(2 ) /bin/$(1 ) $$@ || $$(FAIL )
176+ @chmod +x $$@
177+ @rm -rf $$(TOOLS_HOST_DIR ) /tmp-$(1 ) -v$(2 )
178+ @$$(OK ) go install $(3 )
179+ endef # tool.go.install
180+
163181# Creates a target for compiling a vendored go tool
164182# 1 tool, 2 package
165183define tool.go.vendor.install
@@ -187,12 +205,12 @@ $(eval $(call tool.download.tar.gz,golangci-lint,$(GOLANGCI_LINT_VERSION),$(GOLA
187205ifneq ($(LANGUAGES ) ,)
188206GO_XGETTEXT_VERSION ?= v0.0.0-20180127124228-c366ce0fe48d
189207GO_XGETTEXT_URL ?= github.com/presslabs/gettext/go-xgettext
190- $(eval $(call tool.go.get ,go-xgettext,$(GO_XGETTEXT_VERSION),$(GO_XGETTEXT_URL)))
208+ $(eval $(call tool.go.install ,go-xgettext,$(GO_XGETTEXT_VERSION),$(GO_XGETTEXT_URL)))
191209endif
192210
193211# we use a consistent version of gofmt even while running different go compilers.
194212# see https://github.com/golang/go/issues/26397 for more details
195- GOFMT_VERSION ?= 1.16
213+ GOFMT_VERSION ?= 1.16.6
196214GOFMT_DOWNLOAD_URL ?= https://dl.google.com/go/go$(GOFMT_VERSION ) .$(HOSTOS ) -$(HOSTARCH ) .tar.gz
197215ifneq ($(findstring $(GOFMT_VERSION ) ,$(GO_VERSION ) ) ,)
198216GOFMT := $(shell which gofmt)
@@ -202,16 +220,16 @@ endif
202220
203221GOIMPORTS_VERSION ?= v0.1.5
204222GOIMPORTS_URL ?= golang.org/x/tools/cmd/goimports
205- $(eval $(call tool.go.get ,goimports,$(GOIMPORTS_VERSION),$(GOIMPORTS_URL)))
223+ $(eval $(call tool.go.install ,goimports,$(GOIMPORTS_VERSION),$(GOIMPORTS_URL)))
206224
207225ifeq ($(GO_TEST_TOOL ) ,ginkgo)
208226GINKGO_VERSION ?= v1.16.4
209227GINKGO_URL ?= github.com/onsi/ginkgo/ginkgo
210- $(eval $(call tool.go.get ,ginkgo,$(GINKGO_VERSION),$(GINKGO_URL)))
228+ $(eval $(call tool.go.install ,ginkgo,$(GINKGO_VERSION),$(GINKGO_URL)))
211229else # GO_TEST_TOOL != ginkgo
212230GO_JUNIT_REPORT_VERSION ?= v0.9.2-0.20191008195320-984a47ca6b0a
213231GO_JUNIT_REPORT_URL ?= github.com/jstemmer/go-junit-report
214- $(eval $(call tool.go.get ,go-junit-report,$(GO_JUNIT_REPORT_VERSION),$(GO_JUNIT_REPORT_URL),go-junit-report))
232+ $(eval $(call tool.go.install ,go-junit-report,$(GO_JUNIT_REPORT_VERSION),$(GO_JUNIT_REPORT_URL),go-junit-report))
215233endif # GO_TEST_TOOL
216234
217235# ====================================================================================
0 commit comments