summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWilliam Hubbs <williamh@gentoo.org>2015-06-16 21:40:51 +0000
committerWilliam Hubbs <williamh@gentoo.org>2015-06-16 21:40:51 +0000
commit563e8512ab1f09263401cb12a24eff83234ba5d3 (patch)
tree62a61bddbed97120db528f8496d38d60245fc5bb
parentMinor changes to reduce diff with qt5-build.eclass (diff)
downloadgentoo-2-563e8512ab1f09263401cb12a24eff83234ba5d3.tar.gz
gentoo-2-563e8512ab1f09263401cb12a24eff83234ba5d3.tar.bz2
gentoo-2-563e8512ab1f09263401cb12a24eff83234ba5d3.zip
Add golang-vcs.eclass to retrieve go packages from vcs repositories for software written in the Go programming language
-rw-r--r--eclass/ChangeLog6
-rw-r--r--eclass/golang-vcs.eclass138
2 files changed, 143 insertions, 1 deletions
diff --git a/eclass/ChangeLog b/eclass/ChangeLog
index 37fb99a1a5d0..999ae0e36b03 100644
--- a/eclass/ChangeLog
+++ b/eclass/ChangeLog
@@ -1,6 +1,10 @@
# ChangeLog for eclass directory
# Copyright 1999-2015 Gentoo Foundation; Distributed under the GPL v2
-# $Header: /var/cvsroot/gentoo-x86/eclass/ChangeLog,v 1.1668 2015/06/16 21:38:00 pesa Exp $
+# $Header: /var/cvsroot/gentoo-x86/eclass/ChangeLog,v 1.1669 2015/06/16 21:40:51 williamh Exp $
+
+ 16 Jun 2015; William Hubbs <williamh@gentoo.org> +golang-vcs.eclass:
+ Add golang-vcs.eclass to retrieve go packages from vcs repositories
+ for live ebuilds of software written in the Go programming language.
16 Jun 2015; Davide Pesavento <pesa@gentoo.org> qt4-build-multilib.eclass:
Minor changes to reduce diff with qt5-build.eclass
diff --git a/eclass/golang-vcs.eclass b/eclass/golang-vcs.eclass
new file mode 100644
index 000000000000..d3364ffc9371
--- /dev/null
+++ b/eclass/golang-vcs.eclass
@@ -0,0 +1,138 @@
+# Copyright 1999-2015 Gentoo Foundation
+# Distributed under the terms of the GNU General Public License v2
+# $Header: /var/cvsroot/gentoo-x86/eclass/golang-vcs.eclass,v 1.1 2015/06/16 21:40:51 williamh Exp $
+
+# @ECLASS: golang-vcs.eclass
+# @MAINTAINER:
+# William Hubbs <williamh@gentoo.org>
+# @BLURB: Eclass for fetching and unpacking go repositories.
+# @DESCRIPTION:
+# This eclass is written to ease the maintenance of live ebuilds
+# of software written in the Go programming language.
+
+inherit eutils
+
+case "${EAPI:-0}" in
+ 5)
+ ;;
+ *)
+ die "${ECLASS}: Unsupported eapi (EAPI=${EAPI})"
+ ;;
+esac
+
+EXPORT_FUNCTIONS src_unpack
+
+if [[ -z ${_GOLANG_VCS} ]]; then
+
+_GOLANG_VCS=1
+
+DEPEND=">=dev-lang/go-1.4.2"
+
+# @ECLASS-VARIABLE: EGO_PN
+# @REQUIRED
+# @DESCRIPTION:
+# This is the import path for the go package(s). Please emerge dev-lang/go
+# and read "go help importpath" for syntax.
+#
+# Example:
+# @CODE
+# EGO_PN="github.com/user/package"
+# EGO_PN="github.com/user1/package1 github.com/user2/package2"
+# @CODE
+
+# @ECLASS-VARIABLE: EGO_STORE_DIR
+# @DESCRIPTION:
+# Storage directory for Go sources.
+#
+# This is intended to be set by the user in make.conf. Ebuilds must not set
+# it.
+#
+# EGO_STORE_DIR=${DISTDIR}/go-src
+
+# @ECLASS-VARIABLE: EVCS_OFFLINE
+# @DEFAULT_UNSET
+# @DESCRIPTION:
+# If non-empty, this variable prevents any online operations.
+
+# @ECLASS-VARIABLE: EVCS_UMASK
+# @DEFAULT_UNSET
+# @DESCRIPTION:
+# Set this variable to a custom umask. This is intended to be set by
+# users. By setting this to something like 002, it can make life easier
+# for people who do development as non-root (but are in the portage
+# group) and use FEATURES=userpriv.
+
+# @FUNCTION: _golang-vcs_env_setup
+# @INTERNAL
+# @DESCRIPTION:
+# Create EGO_STORE_DIR if necessary and set GOPATH.
+_golang-vcs_env_setup() {
+ debug-print-function ${FUNCNAME} "$@"
+
+ local distdir=${PORTAGE_ACTUAL_DISTDIR:-${DISTDIR}}
+ : ${EGO_STORE_DIR:=${distdir}/go-src}
+
+ [[ -n ${EVCS_UMASK} ]] && eumask_push $EVCS_UMASK
+
+ if [[ ! -d ${EGO_STORE_DIR} ]]; then
+ (
+ addwrite /
+ mkdir -p "${EGO_STORE_DIR}"
+ ) || die "${ECLASS}: unable to create ${EGO_STORE_DIR}"
+ fi
+
+ addwrite "${EGO_STORE_DIR}"
+ export GOPATH="${EGO_STORE_DIR}"
+
+ [[ -n ${EVCS_UMASK} ]] && eumask_pop
+ mkdir -p "${S}" ||
+ die "${ECLASS}: unable to create ${S}"
+ return 0
+}
+
+# @FUNCTION: _golang-vcs_fetch
+# @INTERNAL
+# @DESCRIPTION:
+# Retrieve the EGO_PN go package along with its dependencies.
+_golang-vcs_fetch() {
+ debug-print-function ${FUNCNAME} "$@"
+
+ [[ -z ${EGO_PN} ]] &&
+ die "${ECLASS}: EGO_PN is not set"
+
+ if [[ -n ${EVCS_OFFLINE} ]]; then
+ export GOPATH="${S}:${GOPATH}"
+ return 0
+ fi
+
+ [[ -n ${EVCS_UMASK} ]] && eumask_push ${EVCS_UMASK}
+
+ set -- go get -d -t -u -v -x "${EGO_PN}"
+ echo "$@"
+ "$@" || die
+ # The above dies if you pass repositories in EGO_PN instead of
+ # packages, e.g. golang.org/x/tools instead of golang.org/x/tools/cmd/vet.
+ # This is being discussed in the following upstream issue:
+ # https://github.com/golang/go/issues/11090
+ # I am hoping this will be fixed so "go get -d" is successful if
+ # downloading the top level repository is successful.
+
+ [[ -n ${EVCS_UMASK} ]] && eumask_pop
+ export GOPATH="${S}:${EGO_STORE_DIR}"
+ return 0
+}
+
+golang-vcs_src_fetch() {
+ debug-print-function ${FUNCNAME} "$@"
+
+ _golang-vcs_env_setup
+ _golang-vcs_fetch
+}
+
+golang-vcs_src_unpack() {
+ debug-print-function ${FUNCNAME} "$@"
+
+ golang-vcs_src_fetch
+}
+
+fi