我想为一个用go
它构建的OSS项目做贡献,但我很难编译它.看起来好像我错过了一些明显的东西.
我认为这个问题与go
我的计算机上安装的方式有关,而不是与项目本身有关,因此我在StackOverflow上发布它,而不是项目的"问题"部分.
以下是我正在做的事情.
我安装go
使用homebrew
:
$ brew install go
Updating Homebrew...
==> Auto-updated Homebrew!
Updated 1 tap (homebrew/core).
==> Updated Formulae
libebml
==> Downloading https://homebrew.bintray.com/bottles/go-1.8.3.sierra.bottle.tar.gz
Already downloaded: /Users/gmile/Library/Caches/Homebrew/go-1.8.3.sierra.bottle.tar.gz
==> Pouring go-1.8.3.sierra.bottle.tar.gz
==> Caveats
A valid GOPATH is required to use the `go get` command.
If $GOPATH is not specified, $HOME/go will be used by default:
https://golang.org/doc/code.html#GOPATH
You may wish to add the GOROOT-based install location to your PATH:
export PATH=$PATH:/usr/local/opt/go/libexec/bin
==> Summary
/usr/local/Cellar/go/1.8.3: 7,035 files, 282.0MB
$
Run Code Online (Sandbox Code Playgroud)然后我克隆了回购:
$ hub clone lucapette/fakedata
Run Code Online (Sandbox Code Playgroud)我跑make setup
(按指令),最初没有成功完成:
$ make setup
go get -u github.com/alecthomas/gometalinter
gometalinter --install
make: gometalinter: No such file or directory
make: *** [setup] Error 1
$
Run Code Online (Sandbox Code Playgroud)
我想这是因为gometalinter
我无处可去$PATH
,所以加了它(我用的是鱼壳):
$ set fish_user_paths /Users/gmile/go/bin
Run Code Online (Sandbox Code Playgroud)跑步make setup
似乎现在已经成功了.这是输出:
$ make setup
go get -u github.com/alecthomas/gometalinter
gometalinter --install
Installing:
aligncheck
deadcode
dupl
errcheck
gas
goconst
gocyclo
goimports
golint
gosimple
gotype
ineffassign
interfacer
lll
megacheck
misspell
safesql
staticcheck
structcheck
unconvert
unparam
unused
varcheck
$
Run Code Online (Sandbox Code Playgroud)运行make build
失败:
$ make build
go build
main.go:11:2: cannot find package"github.com/lucapette/fakedata/pkg/fakedata" in any of:
/usr/local/Cellar/go/1.8.3/libexec/src/github.com/lucapette/fakedata/pkg/fakedata (from $GOROOT)
/Users/gmile/go/src/github.com/lucapette/fakedata/pkg/fakedata (from $GOPATH)
main.go:12:2: cannot find package "github.com/spf13/pflag" in any of:
/usr/local/Cellar/go/1.8.3/libexec/src/github.com/spf13/pflag (from $GOROOT)
/Users/gmile/go/src/github.com/spf13/pflag (from $GOPATH)
make: *** [build] Error 1
$
Run Code Online (Sandbox Code Playgroud)因此,任何贡献指南都是不完整的,或者我遗漏了一些关于安装和管理go包的明显事实.
克隆源代码时的路径必须在golang PATH上:
/home/gujarat/golang/src/github.com/lucapette/fakedata
你可以看到我的golang路径是:/home/gujarat/golang/
.您还可以输入以下命令在终端中打印golang路径:$GOPATH
.
并且git clone
应该在下面的路径中如下:src/github.com/lucapette/
.
cd $GOPATH/src/github.com/
mkdir lucaptte
cd lucapette
git clone https://github.com/lucapette/fakedata.git
Run Code Online (Sandbox Code Playgroud)
当您运行make
触发go build
此命令的命令时,将查看$GOPATH
您和您的$GOROOT
文件夹.