Go项目的Ebuild示例

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

Ebuild example for project in Go

问题

我打算为一个用Go语言编写的项目创建一个Gentoo ebuild,并且我想知道之前是否已经有人做过这个。

由于从源代码构建和安装Go项目与其他编程语言的项目相比有很大的不同,所以对我来说,比较现有的ebuild以找出最佳实践是很有用的。

然而,在当前的portage树中,我找不到任何依赖于"dev-lang/go"的软件包。也许有这样一个ebuild,可能在一个overlay中。

英文:

I intend to create a Gentoo ebuild for a project written in Go, and I'm wondering whether this has been done before.

As building and installing a Go project from source seems sufficiently different compared to projects in other programming languages, it would be useful for me to compare to an existing ebuild for figuring out best practices.

However, in the current portage tree I can't find any package that would depend on "dev-lang/go". Is there such an ebuild, perhaps in an overlay?

答案1

得分: 1

如何使用go-overlay来查找示例ebuilds?他们编写了一个特殊的ebuild类,用于在几行代码中构建Go应用程序和库。让我以他们的dev-util/flint-0.0.4 ebuild为例(所有注释都是我的):

EAPI=6

GOLANG_PKG_IMPORTPATH="github.com/pengwynn"
GOLANG_PKG_VERSION="c3a5d8d9a2e04296fba560d9a22f763cff68eb75"

# 许多Go项目不固定其依赖项的版本,
# 所以可能需要在这里进行固定。如果上游已经使用了'godep'或类似的工具,则可能不需要此步骤。
GOLANG_PKG_DEPENDENCIES=(
	"github.com/codegangsta/cli:142e6cd241"
	"github.com/fatih/color:1b35f289c4"
	"github.com/octokit/go-octokit:4408b5393e"
	"github.com/fhs/go-netrc:4422b68c9c"
	"github.com/jingweno/go-sawyer:1999ae5763"
	"github.com/shiena/ansicolor:264b056680"
	"github.com/jtacoma/uritemplates:0a85813eca"
)

# 由于许多项目不需要自定义构建步骤,
# 这一行可能就足够了。
inherit golang-single

# 这些变量没有特别之处。    
DESCRIPTION="Check your project for common sources of contributor friction"
HOMEPAGE="https://${GOLANG_PKG_IMPORTPATH}/${PN}"    
LICENSE="MIT"
KEYWORDS="amd64 x86 arm"

# 防止与'dev-go/flint'同时安装。
# 老实说,我在互联网上找不到这个软件包。
SLOT="0"
DEPEND="!dev-go/${PN}"
英文:

How about go-overlay to look for example ebuilds? They wrote a special ebuild class for building Go apllications and libraries in a few lines. Let me use their dev-util/flint-0.0.4 ebuild as an illustration (all comments are mine):

EAPI=6

GOLANG_PKG_IMPORTPATH="github.com/pengwynn"
GOLANG_PKG_VERSION="c3a5d8d9a2e04296fba560d9a22f763cff68eb75"

# Many Go projects don't pin versions of their dependencies,
# so it may has to be done here. You might not need this step if
# the upstream already uses 'godep' or simular tool.
GOLANG_PKG_DEPENDENCIES=(
	"github.com/codegangsta/cli:142e6cd241"
	"github.com/fatih/color:1b35f289c4"
	"github.com/octokit/go-octokit:4408b5393e"
	"github.com/fhs/go-netrc:4422b68c9c"
	"github.com/jingweno/go-sawyer:1999ae5763"
	"github.com/shiena/ansicolor:264b056680"
	"github.com/jtacoma/uritemplates:0a85813eca"
)

# Since many projects don't require custom build steps,
# this single line may be enough.
inherit golang-single

# Nothing special about these variables.    
DESCRIPTION="Check your project for common sources of contributor friction"
HOMEPAGE="https://${GOLANG_PKG_IMPORTPATH}/${PN}"    
LICENSE="MIT"
KEYWORDS="amd64 x86 arm"

# Prevent simulateneous installing with 'dev-go/flint'.
# Honestly, I was unable to this package on the Internet.
SLOT="0"
DEPEND="!dev-go/${PN}"

答案2

得分: 0

这是一个安装Go项目的工作示例的ebuild:

https://github.com/timboudreau/gentoo/blob/master/net-misc/syncthing/syncthing-0.11.7.ebuild

英文:

Here is a working example of an ebuild which installs a go project:

https://github.com/timboudreau/gentoo/blob/master/net-misc/syncthing/syncthing-0.11.7.ebuild

答案3

得分: 0

这是可能的。我刚刚在我的覆盖层中创建了一个链接。这有点痛苦,但它可以工作。

有几件重要的事情需要做。

  1. 如果您的系统中没有添加go-overlay,请在您的存储库中创建golang eclasses
  2. GOLANG_PKG_IMPORTPATH变量指定了一个GitHub配置文件,从中将下载源代码。
  3. GOLANG_PKG_DEPENDENCIES变量指定了所有依赖项的GitHub存储库和特定提交。
  4. inherit golang-single导入了上述的eclass,并同时将dev-lang/go添加到依赖项中。
英文:

It is possible. I just made one in my overlay. It was a little bit painful, but it works.

There are a few important things, that have to be done.

  1. Create golang eclasses in your repository, if you don't have go-overlay added in your system.
  2. GOLANG_PKG_IMPORTPATH variable specifies a GitHub profile, from which will be downloaded source code.
  3. GOLANG_PKG_DEPENDENCIES variable specifies GitHub repositories and particular commits of all dependencies.
  4. inherit golang-single imports mentioned eclass and at the same time adds dev-lang/go into dependencies.

答案4

得分: -1

看起来有一个现有的、可工作的ebuild。

来自:https://gist.github.com/matsuu/233858(也可以在http://git.overlays.gentoo.org/gitweb/?p=proj/glentoo-overlay.git;a=blob_plain;f=dev-lang/golang-platform/golang-platform-9999.ebuild;hb=HEAD找到)

# 版权 1999-2009 Gentoo 基金会
# 根据 GNU 通用公共许可证 v2 的条款分发
# $Header: $

EAPI="2"
inherit elisp-common eutils mercurial toolchain-funcs

DESCRIPTION="Go 编程语言"
HOMEPAGE="http://golang.org/"
SRC_URI=""
EHG_REPO_URI="https://go.googlecode.com/hg/"
EHG_REVISION="release"

LICENSE="BSD"
SLOT="0"
KEYWORDS="~amd64 ~x86"
IUSE="emacs vim-syntax"

RESTRICT="test"

RDEPEND="sys-devel/gcc"
DEPEND="${RDEPEND}
    emacs? ( virtual/emacs )
    sys-devel/bison
    sys-apps/ed"

S="${WORKDIR}/hg"

ENVFILE="${WORKDIR}/50${PN}"

src_prepare() {
    GOBIN="${WORKDIR}/bin"
    mkdir -p "${GOBIN}" || die

    sed -i \
        -e "/^GOBIN=/s:=.*:=${GOBIN}:" \
        -e "/MAKEFLAGS=/s:=.*:=${MAKEOPTS}:" \
        src/make.bash || die

    sed -i \
        -e "/^CFLAGS=/s:-O2:${CFLAGS}:" \
        src/Make.conf || die

    case ${ARCH} in
    x86)
        GOARCH="386"
        ;;
    *)
        GOARCH="${ARCH}"
        ;;
    esac

    case ${CHOST} in
    *-darwin*)
        GOOS="darwin"
        ;;
    *)
        GOOS="linux"
        ;;
    esac
#    *-nacl*)
#        GOOS="nacl"
#        ;;

    cat > "${ENVFILE}" <<EOF
GOROOT="/usr/$(get_libdir)/${PN}"
GOARCH="${GOARCH}"
GOOS="${GOOS}"
EOF
    . "${ENVFILE}"

    export GOBIN GOROOT GOARCH GOOS
}

src_compile() {
    cd src
    PATH="${GOBIN}:${PATH}" GOROOT="${S}" CC="$(tc-getCC)" ./make.bash || die
    if use emacs ; then
        elisp-compile "${S}"/misc/emacs/*.el || die
    fi
}

src_test() {
    cd src
    PATH="${GOBIN}:${PATH}" GOROOT="${S}" CC="$(tc-getCC)" ./run.bash || die
}

src_install() {
    dobin "${GOBIN}"/* || die

    insinto "${GOROOT}"
    doins -r pkg || die

    if use emacs ; then
        elisp-install ${PN} "${S}"/misc/emacs/*.el* || die "elisp-install failed"
    fi

    if use vim-syntax ; then
        insinto /usr/share/vim/vimfiles/plugin
        doins "${S}"/misc/vim/go.vim || die
    fi

    doenvd "${ENVFILE}" || die

    dodoc AUTHORS CONTRIBUTORS README || die
    dohtml -r doc/* || die
}

pkg_postinst() {
    elog "请不要忘记加载 /etc/profile"
}

抱歉,我没有测试过,因为我现在没有运行的 Gentoo 实例。希望它能正常工作。

英文:

It looks like there's an existing, working ebuild.

From: https://gist.github.com/matsuu/233858 (and also found at http://git.overlays.gentoo.org/gitweb/?p=proj/glentoo-overlay.git;a=blob_plain;f=dev-lang/golang-platform/golang-platform-9999.ebuild;hb=HEAD)

# Copyright 1999-2009 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Header: $
 
EAPI=&quot;2&quot;
inherit elisp-common eutils mercurial toolchain-funcs
 
DESCRIPTION=&quot;The Go Programming Language&quot;
HOMEPAGE=&quot;http://golang.org/&quot;
SRC_URI=&quot;&quot;
EHG_REPO_URI=&quot;https://go.googlecode.com/hg/&quot;
EHG_REVISION=&quot;release&quot;
 
LICENSE=&quot;BSD&quot;
SLOT=&quot;0&quot;
KEYWORDS=&quot;~amd64 ~x86&quot;
IUSE=&quot;emacs vim-syntax&quot;
 
RESTRICT=&quot;test&quot;
 
RDEPEND=&quot;sys-devel/gcc&quot;
DEPEND=&quot;${RDEPEND}
	emacs? ( virtual/emacs )
	sys-devel/bison
	sys-apps/ed&quot;
 
S=&quot;${WORKDIR}/hg&quot;
 
ENVFILE=&quot;${WORKDIR}/50${PN}&quot;
 
src_prepare() {
	GOBIN=&quot;${WORKDIR}/bin&quot;
	mkdir -p &quot;${GOBIN}&quot; || die
 
	sed -i \
		-e &quot;/^GOBIN=/s:=.*:=${GOBIN}:&quot; \
		-e &quot;/MAKEFLAGS=/s:=.*:=${MAKEOPTS}:&quot; \
		src/make.bash || die
 
	sed -i \
		-e &quot;/^CFLAGS=/s:-O2:${CFLAGS}:&quot; \
		src/Make.conf || die
	
	case ${ARCH} in
	x86)
		GOARCH=&quot;386&quot;
		;;
	*)
		GOARCH=&quot;${ARCH}&quot;
		;;
	esac
 
	case ${CHOST} in
	*-darwin*)
		GOOS=&quot;darwin&quot;
		;;
	*)
		GOOS=&quot;linux&quot;
		;;
	esac
#	*-nacl*)
#		GOOS=&quot;nacl&quot;
#		;;
 
	cat &gt; &quot;${ENVFILE}&quot; &lt;&lt;EOF
GOROOT=&quot;/usr/$(get_libdir)/${PN}&quot;
GOARCH=&quot;${GOARCH}&quot;
GOOS=&quot;${GOOS}&quot;
EOF
	. &quot;${ENVFILE}&quot;
 
	export GOBIN GOROOT GOARCH GOOS
}
 
src_compile() {
	cd src
	PATH=&quot;${GOBIN}:${PATH}&quot; GOROOT=&quot;${S}&quot; CC=&quot;$(tc-getCC)&quot; ./make.bash || die
	if use emacs ; then
		elisp-compile &quot;${S}&quot;/misc/emacs/*.el || die
	fi
}
 
src_test() {
	cd src
	PATH=&quot;${GOBIN}:${PATH}&quot; GOROOT=&quot;${S}&quot; CC=&quot;$(tc-getCC)&quot; ./run.bash || die
}
 
src_install() {
	dobin &quot;${GOBIN}&quot;/* || die
 
	insinto &quot;${GOROOT}&quot;
	doins -r pkg || die
 
	if use emacs ; then
		elisp-install ${PN} &quot;${S}&quot;/misc/emacs/*.el* || die &quot;elisp-install failed&quot;
	fi
 
	if use vim-syntax ; then
		insinto /usr/share/vim/vimfiles/plugin
		doins &quot;${S}&quot;/misc/vim/go.vim || die
	fi
 
	doenvd &quot;${ENVFILE}&quot; || die
 
	dodoc AUTHORS CONTRIBUTORS README || die
	dohtml -r doc/* || die
}
 
pkg_postinst() {
	elog &quot;please don&#39;t forget to source /etc/profile&quot;
}

Sorry, I haven't tested it as I don't have a running Gentoo instance right now. Hope it works.

huangapple
  • 本文由 发表于 2013年5月19日 19:42:39
  • 转载请务必保留本文链接:https://go.coder-hub.com/16634291.html
匿名

发表评论

匿名网友

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

确定