4

我打算为一个用 Go 编写的项目创建一个 Gentoo ebuild,我想知道这是否以前做过。

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

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

4

4 回答 4

1

go-overlay来查找例如 ebuilds 怎么样?他们用几行代码编写了一个特殊的 ebuild 类来构建 Go 应用程序和库。让我以他们的dev-util/flint-0.0.4ebuild 为例(所有评论都是我的):

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}"
于 2017-08-09T22:59:32.117 回答
0

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

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

于 2015-05-31T12:17:42.940 回答
0

有可能的。我刚刚在我的叠加层中做了一个。这有点痛苦,但它有效。

有一些重要的事情,必须完成。

  1. 如果您的系统中没有添加go-overlay ,请在您的存储库中创建golang eclass
  2. GOLANG_PKG_IMPORTPATH变量指定 GitHub 配置文件,将从中下载源代码。
  3. GOLANG_PKG_DEPENDENCIES变量指定 GitHub 存储库和所有依赖项的特定提交。
  4. inherit golang-single导入提到的 eclass 并同时添加dev-lang/go到依赖项中。
于 2020-07-26T14:11:03.657 回答
-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 实例。希望它有效。

于 2013-05-19T12:10:25.023 回答