Go中项目的Ebuild示例

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?

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

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

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

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