英文:
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
这是可能的。我刚刚在我的覆盖层中创建了一个链接。这有点痛苦,但它可以工作。
有几件重要的事情需要做。
- 如果您的系统中没有添加go-overlay,请在您的存储库中创建golang eclasses。
GOLANG_PKG_IMPORTPATH
变量指定了一个GitHub配置文件,从中将下载源代码。GOLANG_PKG_DEPENDENCIES
变量指定了所有依赖项的GitHub存储库和特定提交。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.
- Create golang eclasses in your repository, if you don't have go-overlay added in your system.
GOLANG_PKG_IMPORTPATH
variable specifies a GitHub profile, from which will be downloaded source code.GOLANG_PKG_DEPENDENCIES
variable specifies GitHub repositories and particular commits of all dependencies.inherit golang-single
imports mentioned eclass and at the same time addsdev-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="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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论