From 356521195cb56a5b9d831bd10373b96c241dbe7a Mon Sep 17 00:00:00 2001 From: Zhilong Wang <61194591+rayowang@users.noreply.github.com> Date: Fri, 20 May 2022 16:45:31 +0800 Subject: [PATCH] fix: goimports failed in make all (#583) --- make/golang.mk | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/make/golang.mk b/make/golang.mk index 07145ccde1..d995eba4bb 100644 --- a/make/golang.mk +++ b/make/golang.mk @@ -120,12 +120,35 @@ go.style: go.format.verify: ifeq ($(shell which goimports), ) @echo "===========> Installing missing goimports" - @GO111MODULE=off $(GO) get -u golang.org/x/tools/cmd/goimports + @mkdir -p $(GOPATH)/src/github.com/golang + @mkdir -p $(GOPATH)/src/golang.org/x +ifeq ($(shell if [ -d $(GOPATH)/src/github.com/golang/tools ]; then echo "exist"; else echo ""; fi;), ) + @git clone https://github.com/golang/tools.git $(GOPATH)/src/github.com/golang/tools +endif +ifeq ($(shell if [ -d $(GOPATH)/src/golang.org/x/tools ]; then echo "exist"; else echo ""; fi;), ) + @ln -s $(GOPATH)/src/github.com/golang/tools $(GOPATH)/src/golang.org/x/tools +endif + +ifeq ($(shell if [ -d $(GOPATH)/src/github.com/golang/mod ]; then echo "exist"; else echo ""; fi;), ) + @git clone https://github.com/golang/mod.git $(GOPATH)/src/github.com/golang/mod +endif +ifeq ($(shell if [ -d $(GOPATH)/src/golang.org/x/mod ]; then echo "exist"; else echo ""; fi;), ) + @ln -s $(GOPATH)/src/github.com/golang/mod $(GOPATH)/src/golang.org/x/mod +endif + +ifeq ($(shell if [ -d $(GOPATH)/src/github.com/golang/sys ]; then echo "exist"; else echo ""; fi;), ) + @git clone https://github.com/golang/sys.git $(GOPATH)/src/github.com/golang/sys +endif +ifeq ($(shell if [ -d $(GOPATH)/src/golang.org/x/sys ]; then echo "exist"; else echo ""; fi;), ) + @ln -s $(GOPATH)/src/github.com/golang/sys $(GOPATH)/src/golang.org/x/sys +endif + @GO111MODULE=off $(GO) build $(GOPATH)/src/golang.org/x/tools/cmd/goimports + @GO111MODULE=off $(GO) install $(GOPATH)/src/golang.org/x/tools/cmd/goimports endif .PHONY: go.format go.format: go.format.verify @echo "===========> Running go codes format" $(GO_FMT) -s -w . - $(GO_IMPORTS) -w -local $(GO_MODULE) . + $(GOPATH)/bin/$(GO_IMPORTS) -w -local $(GO_MODULE) . $(GO) mod tidy