Go中项目的Ebuild示例

时间:2013-05-19 11:42:40

标签: go package-managers gentoo

我打算为Go编写的项目创建一个Gentoo ebuild,我想知道这是否已经完成。

由于与其他编程语言中的项目相比,从源代码构建和安装Go项目似乎有很大的不同,因此与现有的ebuild进行比较以确定最佳实践将非常有用。

但是,在当前的portage树中,我找不到任何依赖于“dev-lang / go”的包。是否有这样的ebuild,也许是叠加?

4 个答案:

答案 0 :(得分:1)

go-overlay如何查找ebuild示例?他们编写了一个特殊的ebuild类,用于在几行中构建Go apllications和库。让我用他们的dev-util/flint-0.0.4 ebuild作为例子(所有评论都是我的):

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}"

答案 1 :(得分:0)

答案 2 :(得分:0)

有可能。我刚刚在叠加层中制作了one。有点痛苦,但是有效。

有一些重要的事情必须要做。

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

答案 3 :(得分:-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找到)

# Copyright 1999-2009 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Header: $

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

DESCRIPTION="The Go Programming Language"
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 "please don't forget to source /etc/profile"
}

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