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

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
kuku
  • 101
  • 1
  • 1
  • 5

7 Answers7

11

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
Rodolfo
  • 1,091
  • 3
  • 13
  • 35
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

prashant
  • 2,808
  • 5
  • 26
  • 41
6

In macOS:

vi ~/.bashrc
export PATH="$PATH:$HOME/go/bin"
benson23
  • 16,369
  • 9
  • 19
  • 38
user18178301
  • 61
  • 1
  • 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](/help/how-to-answer). – Community Feb 12 '22 at 06:53
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

artfulbeest
  • 1,395
  • 2
  • 16
  • 22
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.

luiss
  • 343
  • 4
  • 9
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

foolcage
  • 1,084
  • 7
  • 9
  • 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. – mahima Jun 13 '18 at 16:51
-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.

Kos
  • 4,890
  • 9
  • 38
  • 42
yangcx
  • 1
  • 2