How to package go project for homebrew

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

How to package go project for homebrew

问题

我们正在开发runscripts,并尝试支持类似于brew install runscripts的功能。

它是用golang编写的,并且有一些依赖项需要使用go get来获取。现在我不知道如何编写Formula来设置GOPATH并运行go get。我们的项目可以编译成一个二进制文件,但我们需要run --init来安装它。

有人可以给出一个关于go项目的Homebrew Formula的示例吗?

英文:

We're developing runscripts and try to support something like brew install runscripts.

It's written in golang and have some dependencies which required to go get. Now I have no idea to write the Formula to setup GOPATH and run go get. Our project can be compiled into an binary but we need run --init to install it.

Can anyone helps to give an example about a homebrew Formula of go project?

答案1

得分: 5

你可以fork homebrew,查看Library/Formula/consul.rb的内容。你不需要手动生成所有的资源,可以使用homebrew-go-resources。更详细的介绍可以在这里找到。

英文:

Fork homebrew, look at the content of Library/Formula/consul.rb. You don't need to manually generate all the resources. Use homebrew-go-resources. A more complete intro could be found here.

答案2

得分: 1

我参考了termshare.rb,看起来我们可以简单地使用go get,Homebrew会处理关于GOPATH的一切。

这太好了,我觉得我的问题解决了。

英文:

I have refer to termshare.rb and it seems we can simply go get and homebrew will handle anything about GOPATH for us.

That's great and I think my problem is solved.

答案3

得分: 1

我找到的最好的方法是将docker-swarm添加到brew中:https://github.com/Homebrew/homebrew/blob/4c6857b0e337b2d5afd49dcf7209b6b5091709f4/Library/Formula/docker-swarm.rb

这个方法相对清晰简单易懂。

英文:

The best I could find is how docker-swarm is added to brew: https://github.com/Homebrew/homebrew/blob/4c6857b0e337b2d5afd49dcf7209b6b5091709f4/Library/Formula/docker-swarm.rb

It's relatively clean and simple to follow.

答案4

得分: 1

你可以使用goreleaser自动生成公式:https://goreleaser.com/customization/homebrew/

英文:

You can use goreleaser to generate the formula automatically: https://goreleaser.com/customization/homebrew/

答案5

得分: 0

这里是一个可能的解决方法,可以在检出目录中创建一个名为build的文件夹作为GOPATH

...
def install
    system "mkdir -p build/src"
    system "ln -s `pwd` build/src/repo"
    system "GOPATH=`pwd`/build go get repo/mytool"
    bin.install "build/bin/mytool"
    ...
end
...
英文:

Here is a possible work around creating a build directory within the checkout as the GOPATH:

...
def install
    system "mkdir -p build/src"
    system "ln -s `pwd` build/src/repo"
    system "GOPATH=`pwd`/build go get repo/mytool"
    bin.install "build/bin/mytool"
    ...
end
...

huangapple
  • 本文由 发表于 2014年11月24日 10:26:30
  • 转载请务必保留本文链接:https://go.coder-hub.com/27097005.html
匿名

发表评论

匿名网友

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

确定