All,

this replaces my previous golang.eclass and will provide basic
src_compile/install/test functions for Go software.

Take a look and let me know what you think.

William

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

# @ECLASS: golang-build.eclass
# @MAINTAINER:
# William Hubbs <willi...@gentoo.org>
# @BLURB: Eclass for compiling go packages.
# @DESCRIPTION:
# This eclass provides default  src_compile, src_test and src_install
# functions for software written in the Go programming language.

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

# Note that src_install is not exported. This is deliberate. You should
# run this function from your src_install function then follow up with
# installing everything in the image.
EXPORT_FUNCTIONS src_compile src_test

if [[ -z ${_GOLANG} ]]; then

_GOLANG=1

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

# @ECLASS-VARIABLE: EGO_PN_BUILD
# @REQUIRED
# @DESCRIPTION:
# This is the import path for the go package(s) to build. Please emerge
# dev-lang/go and read "go help importpath" for syntax.
#
# If it is not set, we try to set it to EGO_PN assuming that you used
# the golang-vcs eclass.
#
# Example:
# @CODE
# EGO_PN_BUILD=github.com/user/package
# @CODE

# @FUNCTION: _golang-build_setup
# @INTERNAL
# @DESCRIPTION:
# Add ${WORKDIR}/${P} to the front of GOPATH if necessary and make sure
# EGO_PN_BUILD has a value.
_golang-build_setup() {
        case "$GOPATH" in
                ${WORKDIR}/${P}*) ;;
                *) [[ -n "${GOPATH}" ]] &&
                        export GOPATH="${WORKDIR}/${P}:${GOPATH}" ||
                        export GOPATH="${WORKDIR}/${P}"
                        ;;
        esac

        [ -z "${EGO_PN_BUILD}" ] &&
                [ -n "${EGO_PN}" ] &&
                EGO_PN_BUILD="${EGO_PN}"
        [ -z "${EGO_PN_BUILD}" ] &&
                die "${ECLASS}.eclass: EGO_PN_BUILD is not set"
        return 0
}

golang-build_src_compile() {
        debug-print-function ${FUNCNAME} "$@"

        _golang-build_setup
        set -- go build -d -v -work -x "${EGO_PN_BUILD}"
        echo "$@"
        "$@" || die
}

golang-build_src_install() {
        debug-print-function ${FUNCNAME} "$@"

        _golang-build_setup
        set -- go install -d -v -work -x "${EGO_PN_BUILD}"
        echo "$@"
        "$@" || die
}

golang-build_src_test() {
        debug-print-function ${FUNCNAME} "$@"

        _golang-build_setup
        set -- go test -v -x ${EGO_PN_BUILD}
        echo "$@"
        "$@" || die
}

fi

Attachment: signature.asc
Description: Digital signature

Reply via email to