hyperledger fabric make error :"goimports: command not found"
Asked Answered
V

7

10

when I build make the hyperledger fabric project ,I have the following error.but I have install the goimports successfully. To find the reason, I run ./scripts/golinter.sh alone, and there is no such error.what is the error reason,when I make the whole fabric project.

LINT: Running code checks.. Checking ./accesscontrol ./scripts/golinter.sh: line 23: goimports: command not found Makefile:148: recipe for target 'linter' failed make: *** [linter] Error 127

enter image description here

Vigil answered 17/4, 2017 at 2:40 Comment(0)
S
14

If you are running go1.17 you may need to use go install instead of of go get:

go install golang.org/x/tools/cmd/goimports@latest
Stimulant answered 10/1, 2022 at 15:14 Comment(1)
Go by default installed it in the $HOME directory. The following would specify the output directory. #GOBIN=/usr/local/go/bin/ go install golang.org/x/tools /cmd/goimports@latestMyrilla
D
7

In macOS:

vi ~/.bashrc
export PATH="$PATH:$HOME/go/bin"
Domingadomingo answered 11/2, 2022 at 7:19 Comment(1)
As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.Minette
L
6

goimports updates your Go import lines, adding missing ones and removing unreferenced ones. Its a tool which user need to

go get golang.org/x/tools/cmd/goimports 

Reference

Linguist answered 12/5, 2020 at 16:48 Comment(0)
P
2

I'm on Mac, I was able to make this work by including $HOME/go/bin in my path (~/.bashrc). Seems to be open in the documentation, something I missed

Propulsion answered 27/8, 2020 at 11:23 Comment(0)
S
1

When you run ./scripts/golinter.sh directly, you are running it on your local system, hence it finds your locally installed goimports utility.

When you run make (or more specifically, make linter), the golinter.sh script is run inside a container based on the hyperledger/fabric-buildenv image. There must be some mismatch, so I recommend that you remove all traces of images tagged with hyperledger/fabric-buildenv and run make buildenv to create new images. Even better would be a make clean followed by make, since there are other images that build on top of hyperledger/fabric-buildenv.

Synchronize answered 4/8, 2017 at 17:56 Comment(0)
T
0

In Makefile

linter: buildenv
@echo "LINT: Running code checks.."
#add this
@echo "$(DOCKER_TAG)"
@$(DRUN) $(DOCKER_NS)/fabric-buildenv:$(DOCKER_TAG) ./scripts/golinter.sh

So you could find the docker image you're using to do the work. it should be like this:

hyperledger/fabric-buildenv    x86_64-1.1.1-snapshot-cd36699   29266298cc73        3 minutes ago       1.43GB

And you could run it:

docker run -it 29266298cc73
#install the cmd in it
$go get golang.org/x/tools/cmd/goimports

And commit the container outside the container

docker container list
#find the container you just install the cmd,supose it's 3cbdd6e3c109
docker commit 3cbdd6e3c109 hyperledger/fabric-buildenv:x86_64-1.1.1-snapshot-cd36699

Now you could run the make again,and it should be ok now.

Anyway it's a bug for release1.1

Thompson answered 11/4, 2018 at 8:55 Comment(1)
What do you mean by "commit the container outside the container"? 'docker' command is not found inside fabric-buildenv. Also, 'docker ps' is empty after exiting fabric-buildenv.Ruffner
C
-1
  1. copy goimports to dir fabric/build/image/buildenv/payload
  2. edit images/buildenv/Dockerfile.in and add COPY payload/goimports usr/local/bin/ to it.

You can read Makefile and learn about the background.

Certain answered 8/6, 2018 at 8:24 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.