英文:
Build a go project from source
问题
你可以按照以下步骤从源代码构建Go项目,而不是使用go get domain.com/dir/project
。例如,不使用go get github.com/kr/godep
,而是从源代码构建:
git clone https://github.com/kr/godep.git
cd godep
GOPATH=/tmp/godep go build
上述命令会导致以下错误:
dep.go:4:2: cannot find package "code.google.com/p/go.tools/go/vcs" in any of:
/usr/local/Cellar/go/1.2/libexec/src/pkg/code.google.com/p/go.tools/go/vcs (from $GOROOT)
/Users/hanxue/Source/godep/godep/src/code.google.com/p/go.tools/go/vcs (from $GOPATH)
save.go:5:2: cannot find package "github.com/kr/fs" in any of:
/usr/local/Cellar/go/1.2/libexec/src/pkg/github.com/kr/fs (from $GOROOT)
/Users/hanxue/Source/godep/godep/src/github.com/kr/fs (from $GOPATH)
注意:go 1.2已安装在/usr/local/Cellar/go/1.2
,并且/usr/local/Cellar/go/1.2/bin/go
链接到/usr/local/bin/go
。
英文:
How can I build a Go project from source, instead of using go get domain.com/dir/project
? For example, instead of
go get github.com/kr/godep
I want to build from the source:
git clone https://github.com/kr/godep.git
cd godep
GOPATH=/tmp/godep go build
The commands above will result in
dep.go:4:2: cannot find package "code.google.com/p/go.tools/go/vcs" in any of:
/usr/local/Cellar/go/1.2/libexec/src/pkg/code.google.com/p/go.tools/go/vcs (from $GOROOT)
/Users/hanxue/Source/godep/godep/src/code.google.com/p/go.tools/go/vcs (from $GOPATH)
save.go:5:2: cannot find package "github.com/kr/fs" in any of:
/usr/local/Cellar/go/1.2/libexec/src/pkg/github.com/kr/fs (from $GOROOT)
/Users/hanxue/Source/godep/godep/src/github.com/kr/fs (from $GOPATH)
Note: go 1.2 is installed in /usr/local/Cellar/go/1.2 with a link from /usr/local/Cellar/go/1.2/bin/go
to /usr/local/bin/go
答案1
得分: 6
你需要正确配置GOPATH。有时候一个项目不需要在它期望的“子路径”中进行检出,但通常情况下,依赖于它的项目会期望在那里找到它。所以,你可以使用以下命令代替"go get":
mkdir -p /tmp/go/src
export GOPATH=/tmp/go
cd $GOPATH/src
mkdir -p github.com/kr/godep
cd github.com/kr/godep/..
git clone http://github.com/kr/godep.git
cd godep
go build
... 现在对于每个依赖项都要重复上述步骤!
cd $GOPATH/src
mkdir -p code.google.com/p/
cd code.google.com/p
hg clone https://code.google.com/p/go.tools/
是的,vcs依赖项在"go.tools"中,并且需要使用hg进行克隆。我花了一些时间浏览网页才找到这个方法。好吧,我想你可以理解为什么手动操作会很烦人了。
我会把剩下的依赖项留给你自己解决,或者你可以直接使用"go get"命令。:-)
还有一个额外的提示,也许这才是你真正想要的:在检出第一个项目后,你可以在该目录中使用"go get"命令下载项目的依赖项。如果有一些无法使用"go get"命令获取的依赖项,这个方法可能会很有用。
英文:
You need the GOPATH configured correctly. Sometimes a project doesn't have to be checked out in the "sub path" it expects, but often it does and certainly things that depend on it will expect to find it there. So instead of "go get" you can
mkdir -p /tmp/go/src
export GOPATH=/tmp/go
cd $GOPATH/src
mkdir -p github.com/kr/godep
cd github.com/kr/godep/..
git clone http://github.com/kr/godep.git
cd godep
go build
... now rinse and repeat for each dependency!
cd $GOPATH/src
mkdir -p code.google.com/p/
cd code.google.com/p
hg clone https://code.google.com/p/go.tools/
Yes, the vcs dependency was in "go.tools" and needed to be cloned with hg instead. It took a bit of web browsing to figure out. Okay, I think you can see why that's annoying to do by hand.
I'll leave the rest of the dependencies as an exercise for the reader, or you can just use "go get".
A bonus tip that might be what you are really looking for: After checking out the first project, you can use "go get" in that directory to download the dependencies of the project. Sometimes if you have something that's not "go get'able" that's useful if the dependencies are.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论