Cannot get a fork of a repository to build due to

2020-04-20 13:24发布

问题:

I have made a fork of a repository (specifically, github.com/ethereum/go-ethereum) and am trying to make sure that I can build the main application (cmd/geth) before developing on the fork. However, due to the upstream source importing internal packages, the build does not work in my fork.

I have tried this both using GOPATH and Go modules. In each case, when I try to run go install github.com/<me>/go-ethereum/cmd/geth) I get the following error:

cmd/geth/main.go:40:2: use of internal package github.com/ethereum/go-ethereum/internal/debug not allowed

In the Go module approach, I have tried adding a replace directive to use my fork instead:

replace github.com/ethereum/go-ethereum => github.com/<me>/go-ethereum master

But this leads to the same error.

I am happy to provide more information (e.g., build output) if that would be helpful, but it seems like there is something straightforward that I am missing, rather than simply replacing all instances of ethereum/go-ethereum/internal with <me>/go-ethereum/internal.

回答1:

By default, GOPATH is set to $HOME/gopath, and your repository source code is placed in $GOPATH/github.com/user/repo (or $GOPATH/bitbucket.org/user/repo).

When working on a forked repo, in order to import internal packages, the path of the original repo should be added to the go import path.

As an example, on Travis-CI, my forked repo failed on the same problem (use of internal package not allowed). So I just set go_import_path in travis.yml - and it passed.



回答2:

If you are forking you should change the import paths as well.



标签: go