使用gomake/gotest来处理具有外部依赖的包。

huangapple go评论91阅读模式
英文:

Using gomake/gotest for a package with external dependencies

问题

我有以下的包Makefile:

include ${GOROOT}/src/Make.inc

TARG=gorilla.googlecode.com/hg/gorilla/mux

GOFILES=\ 
        doc.go\
        mux.go\

DEPS=\ 
        gorilla.googlecode.com/hg/gorilla/context

include ${GOROOT}/src/Make.pkg

我今天更改了TARG和DEPS,将它们指向了上面显示的Google代码仓库,遵循了这个建议。

问题是:我可以使用goinstall安装该包并安装依赖项,但我无法再使用gotest或gomake;我得到了以下错误(使用Go r59):

moraes@yukon:~/dev/repos/gorilla/gorilla/mux$ gotest
rm -f _test/gorilla.googlecode.com/hg/gorilla/mux.a
make -C gorilla.googlecode.com/hg/gorilla/context install
make: *** gorilla.googlecode.com/hg/gorilla/context: 没有那个文件或目录。 停止。
make: *** [gorilla.googlecode.com/hg/gorilla/context.make] 错误 2
gotest: "/home/moraes/dev/repos/go/go.r59/bin/gomake testpackage GOTESTFILES=mux_test.go" 失败:退出状态 2

我尝试先goinstall依赖项(goinstall gorilla.googlecode.com/hg/gorilla/context),它在$GOROOT/pkg中正确安装,但是gotest/gomake出现了相同的错误。

我觉得我可能漏掉了一些非常基本的东西。我应该如何继续使用上面的Makefile进行gomake/gotest?这个是否应该完全工作,还是我应该使用不同的Makefile进行开发?

英文:

I have the following package Makefile:

include ${GOROOT}/src/Make.inc

TARG=gorilla.googlecode.com/hg/gorilla/mux

GOFILES=\
        doc.go\
        mux.go\

DEPS=\
        gorilla.googlecode.com/hg/gorilla/context

include ${GOROOT}/src/Make.pkg

I changed TARG and DEPS today to point to the Google code repository as shown above, following this advice.

The problem is: I can goinstall the package and it will install the dependency, but I cannot use gotest or gomake anymore; I get the following error (using Go r59):

moraes@yukon:~/dev/repos/gorilla/gorilla/mux$ gotest
rm -f _test/gorilla.googlecode.com/hg/gorilla/mux.a
make -C gorilla.googlecode.com/hg/gorilla/context install
make: *** gorilla.googlecode.com/hg/gorilla/context: No such file or directory.  Stop.
make: *** [gorilla.googlecode.com/hg/gorilla/context.make] Error 2
gotest: "/home/moraes/dev/repos/go/go.r59/bin/gomake testpackage GOTESTFILES=mux_test.go" failed: exit status 2

I tried goinstalling the dependency first (goinstall gorilla.googlecode.com/hg/gorilla/context), and it installs correctly in $GOROOT/pkg but the same error occurs with gotest/gomake.

I think I'm missing something pretty basic. How should I proceed to use gomake/gotest with the Makefile above? Is this supposed to work at all, or should I use a different one for development?

答案1

得分: 1

goinstall不使用Makefile。相反,它将直接从您的.go文件中解析依赖项。

要指定依赖项,请使用“规范化”的引用注释您的导入行。例如:

import (
  gorilla_context "gorilla.googlecode.com/hg/gorilla/context"
...

但是,gomake不会自动解析依赖项,因此您需要手动安装它们。

类似地,对于使用goinstall安装cgo源代码,您可以在注释指令中指定CFLAGS和LDFLAGS。例如:

/*
#cgo CFLAGS: -I/usr/local/include
#cgo LDFLAGS: -L/usr/local/lib -lzmq
#include <zmq.h>
*/
import "C"
英文:

goinstall doesn't use the Makefile at all. Instead, it will parse dependencies directly from your .go files.

To specify dependencies, annotate your import lines with a "normalised" reference to the dependency. eg.

import (
  gorilla_context &quot;gorilla.googlecode.com/hg/gorilla/context&quot;
...

gomake doesn't automatically resolve dependencies though, so you'll have to manually install them.

Similarly, for installing cgo source with goinstall, you can specify CFLAGS and LDFLAGS in comment directives. eg.

/*
#cgo CFLAGS: -I/usr/local/include
#cgo LDFLAGS: -L/usr/local/lib -lzmq
#include &lt;zmq.h&gt;
*/
import &quot;C&quot;

答案2

得分: 0

我认为Makefile正在尝试在当前目录中找到文件gorilla.googlecode.com/hg/gorilla/context。另外,为什么你想要在Makefile中指定它,而不是从源文件中导入它呢?

英文:

I think the Makefile is trying to find the file gorilla.googlecode.com/hg/gorilla/context in the current directory. Also, why would you want to specify it in a make file as opposed to importing it from within the Source?

huangapple
  • 本文由 发表于 2011年9月6日 22:57:22
  • 转载请务必保留本文链接:https://go.coder-hub.com/7321946.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定