All,

we are starting to get more go packages in the tree, so we need an
eclass that properly deals with go live ebuilds.

Attached you will find my proposal for this eclass. I will commit it on
6 Jun UTC if there is no feedback, so let me know what you think.

Thanks,

William

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

# @ECLASS: go-live.eclass
# @MAINTAINER:
# William Hubbs <willi...@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.

case "${EAPI:-0}" in
        5)
                ;;
        *)
                die "${ECLASS}: Unsupported eapi (EAPI=${EAPI})"
                ;;
esac

EXPORT_FUNCTIONS src_unpack

if [[ ! ${_GO_LIVE} ]]; then

_GO_LIVE=1

DEPEND=">=dev-lang/go-1.4.2"

# @ECLASS-VARIABLE: EGO_PN
# @REQUIRED
# @DESCRIPTION:
# This is the import path for the go package. Please emerge dev-lang/go
# and read "go help importpath" for syntax.
#
# Example:
# @CODE
# EGO_PN="github.com/user/project"
# @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: _go-live_env_setup
# @INTERNAL
# @DESCRIPTION:
# Create EGO_STORE_DIR if necessary and set GOPATH.
_go-live_env_setup() {
        debug-print-function ${FUNCNAME} "$@"

        local distdir=${PORTAGE_ACTUAL_DISTDIR:-${DISTDIR}}
        : ${EGO_STORE_DIR:=${distdir}/go-src}

        local saved_umask
        if [[ ${EVCS_UMASK} ]]; then
                saved_umask=$(umask)
                umask "${EVCS_UMASK}" ||
                        die "${ECLASS}: bad options to umask: ${EVCS_UMASK}"
        fi

        if [[ ! -d ${EGO_STORE_DIR} ]]; then
                (
                        addwrite /
                        mkdir -p "${EGO_STORE_DIR}" || die
                ) || die "${ECLASS}: unable to create ${EGO_STORE_DIR}"
        fi

        addwrite "${EGO_STORE_DIR}"
        export GOPATH="${EGO_STORE_DIR}"

        if [[ ${saved_umask} ]]; then
                umask "${saved_umask}" ||
                        die "${ECLASS}: unable to restore saved umask"
        fi
        mkdir -p "${S}" ||
                die "${ECLASS}: unable to create ${S}"
}

# @FUNCTION: _go-live_fetch
# @INTERNAL
# @DESCRIPTION:
# Retrieve the EGO_PN go package along with its dependencies.
_go-live_fetch() {
        debug-print-function ${FUNCNAME} "$@"

        [[ ${EGO_PN} ]] ||
                die "${ECLASS}: EGO_PN is not set"

        if [[ ${EVCS_OFFLINE} ]]; then
                export GOPATH="${S}:${GOPATH}"
                return
        fi

        local saved_umask
        if [[ ${EVCS_UMASK} ]]; then
                saved_umask=$(umask)
                umask "${EVCS_UMASK}" ||
                        die "${ECLASS}: Bad options to umask: ${EVCS_UMASK}"
        fi

        go get -d -t -u -v -x "$EGO_PN"
        [[ ! -d "${EGO_STORE_DIR}/src/${EGO_PN}" ]] &&
                die "${ECLASS}: unable to retrieve ${EGO_PN} or a dependency"

        if [[ ${saved_umask} ]]; then
                umask "${saved_umask}" ||
                        die "${ECLASS}: unable to restore saved umask"
        fi
        export GOPATH="${S}:${GOPATH}"
}

go-live_src_fetch() {
        debug-print-function ${FUNCNAME} "$@"

        _go-live_env_setup
        _go-live_fetch
}

go-live_src_unpack() {
        debug-print-function ${FUNCNAME} "$@"

        go-live_src_fetch
}

fi

Attachment: signature.asc
Description: Digital signature

Reply via email to