Skip to content

Commit 2baba40

Browse files
committed
Use go install to install tools from source
1 parent 7069e76 commit 2baba40

File tree

1 file changed

+23
-5
lines changed

1 file changed

+23
-5
lines changed

makelib/golang.mk

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,24 @@ $$(TOOLS_HOST_DIR)/$(1)-v$(2): |$$(TOOLS_HOST_DIR)
160160
@$$(OK) go get $(3)
161161
endef # 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
165183
define tool.go.vendor.install
@@ -187,12 +205,12 @@ $(eval $(call tool.download.tar.gz,golangci-lint,$(GOLANGCI_LINT_VERSION),$(GOLA
187205
ifneq ($(LANGUAGES),)
188206
GO_XGETTEXT_VERSION ?= v0.0.0-20180127124228-c366ce0fe48d
189207
GO_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)))
191209
endif
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
196214
GOFMT_DOWNLOAD_URL ?= https://dl.google.com/go/go$(GOFMT_VERSION).$(HOSTOS)-$(HOSTARCH).tar.gz
197215
ifneq ($(findstring $(GOFMT_VERSION),$(GO_VERSION)),)
198216
GOFMT := $(shell which gofmt)
@@ -202,16 +220,16 @@ endif
202220

203221
GOIMPORTS_VERSION ?= v0.1.5
204222
GOIMPORTS_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

207225
ifeq ($(GO_TEST_TOOL),ginkgo)
208226
GINKGO_VERSION ?= v1.16.4
209227
GINKGO_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)))
211229
else # GO_TEST_TOOL != ginkgo
212230
GO_JUNIT_REPORT_VERSION ?= v0.9.2-0.20191008195320-984a47ca6b0a
213231
GO_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))
215233
endif # GO_TEST_TOOL
216234

217235
# ====================================================================================

0 commit comments

Comments
 (0)