diff options
author | 2017-06-20 18:21:20 +0800 | |
---|---|---|
committer | 2017-06-20 18:21:20 +0800 | |
commit | e92afe2c231a22f3f957069aa5d0647c37136e0b (patch) | |
tree | 809e327b733ac4897a3f039d8a14bad80c3b137c /eclass | |
parent | Add sci-libs/mxnet (diff) | |
download | pigfoot-e92afe2c231a22f3f957069aa5d0647c37136e0b.tar.gz pigfoot-e92afe2c231a22f3f957069aa5d0647c37136e0b.tar.bz2 pigfoot-e92afe2c231a22f3f957069aa5d0647c37136e0b.zip |
Update golang eclass
Diffstat (limited to 'eclass')
-rw-r--r-- | eclass/golang-base.eclass | 80 | ||||
-rw-r--r-- | eclass/golang-live.eclass | 157 | ||||
-rw-r--r-- | eclass/golang-single.eclass | 2 |
3 files changed, 201 insertions, 38 deletions
diff --git a/eclass/golang-base.eclass b/eclass/golang-base.eclass index 5fabff6..a605038 100644 --- a/eclass/golang-base.eclass +++ b/eclass/golang-base.eclass @@ -159,7 +159,7 @@ GOLANG_PKG_TAGS="${GOLANG_PKG_TAGS:-}" # Sets additional standard Go workspaces to be appended to the environment # variable GOPATH, as described in http://golang.org/doc/code.html. # This eclass defaults to an empty list. -GOLANG_PKG_VENDOR="${GOLANG_PKG_VENDOR:-}" +GOLANG_PKG_VENDOR=() # @ECLASS-VARIABLE: GOLANG_PKG_STATIK # @DESCRIPTION: @@ -242,6 +242,7 @@ if [[ ${GOLANG_PKG_ARCHIVESUFFIX/.*} == "xz" ]]; then fi # Enables USE 'test' when required by GOLANG_PKG_HAVE_TEST. +IUSE="${IUSE} debug" if [[ -n ${GOLANG_PKG_HAVE_TEST} ]]; then IUSE+=" test" fi @@ -369,6 +370,10 @@ golang_setup() { einfo "Found statik version: ${STATIK_VERSION}" fi + # Enable/Disable frame pointers + local GOEXPERIMENT="noframepointer" + use debug && GOEXPERIMENT="framepointer" + # Sets the build environment inside Portage's WORKDIR. ebegin "Setting up GoLang build environment" @@ -389,6 +394,8 @@ golang_setup() { export GOPATH="$_GOPATH" export GOBIN="$_GOBIN" export CGO_ENABLED + export GOEXPERIMENT + export GO15VENDOREXPERIMENT=0 debug-print "${FUNCNAME}: GOPATH = ${GOPATH}" debug-print "${FUNCNAME}: GOBIN = ${GOBIN}" @@ -514,6 +521,7 @@ golang-base_src_prepare() { local VENDOR="${S}/vendor" if [[ -d "${VENDOR}" ]]; then golang_add_vendor "${VENDOR}" + export GO15VENDOREXPERIMENT=1 fi # Auto-detects the presence of Go's vendored @@ -541,7 +549,7 @@ golang-base_src_prepare() { # (see github.com/tools/godep for more infos). VENDOR="${S}/Godeps/_workspace" if [[ -d "${VENDOR}" ]]; then - GOLANG_PKG_VENDOR+=" ${VENDOR}" + golang_add_vendor "${VENDOR}" fi @@ -670,22 +678,19 @@ golang-base_src_compile() { [[ ${EGO} ]] || die "No GoLang implementation set (golang_setup not called?)." # Populates env variable GOPATH with vendored workspaces (if present). - if [[ -n ${GOLANG_PKG_VENDOR} || "1" == ${GO15VENDOREXPERIMENT} ]]; then + if [[ -n ${GOLANG_PKG_VENDOR} ]]; then einfo "Using vendored dependencies from:" - # Prints Go's vendored directory. - if [[ "1" == ${GO15VENDOREXPERIMENT} ]]; then - einfo "- vendor" - fi - fi - - # Prints user defined vendored directories. - if [[ -n ${GOLANG_PKG_VENDOR} ]]; then for path in "${GOLANG_PKG_VENDOR[@]}"; do [ -d ${path} ] || continue + if [[ ${path//${S}\//} == "vendor" ]]; then + einfo "- vendor/ (native vendoring support)" + continue + fi + debug-print "$FUNCNAME: GOPATH: Adding vendor path ${path}" - ebegin "- ${path//${WORKDIR}\//}" + ebegin "- ${path//${S}\//}" GOPATH="${GOPATH}:$( echo ${path} )" eend done @@ -774,10 +779,10 @@ golang-base_src_install() { # Executes the pre-install phase (go install). if [[ -n ${GOLANG_PKG_IS_MULTIPLE} ]]; then - einfo "${EGO} install -ldflags '$GOLANG_PKG_LDFLAGS' -tags '$GOLANG_PKG_TAGS' ${EGO_BUILD_FLAGS}" + einfo "${EGO} install -ldflags '$GOLANG_PKG_LDFLAGS' -tags '$GOLANG_PKG_TAGS' ${EGO_BUILD_FLAGS} ${EGO_SUBPACKAGES}" ${EGO} install \ - -ldflags "-s -w $( echo ${GOLANG_PKG_LDFLAGS} )" \ - -tags "$( echo ${GOLANG_PKG_TAGS} )" \ + -ldflags "${GOLANG_PKG_LDFLAGS}" \ + -tags "${GOLANG_PKG_TAGS}" \ ${EGO_BUILD_FLAGS} \ "${EGO_SUBPACKAGES}" \ || die @@ -826,7 +831,7 @@ golang-base_src_test() { # Defines sub-packages. local EGO_SUBPACKAGES="${GOLANG_PKG_IMPORTPATH_ALIAS}/${GOLANG_PKG_NAME}${GOLANG_PKG_BUILDPATH}" - [[ -n ${GOLANG_PKG_IS_MULTIPLE} ]] || EGO_SUBPACKAGES="./..." + [[ -z ${GOLANG_PKG_IS_MULTIPLE} ]] || EGO_SUBPACKAGES="./..." # Runs the unit tests. einfo "${EGO} test ${EGO_BUILD_FLAGS} ${EGO_SUBPACKAGES}" @@ -854,18 +859,25 @@ golang_do_build() { [[ ${GOLANG_VERSION} ]] || die "No GoLang implementation set (golang_setup not called?)." - # Filters "=" chars from ldflags declaration - # NOTE: from go1.5+ linker syntax is no more compatible with <go1.4; this hack - # ensures that the old behaviour is honoured. + # Filters "=" chars from ldflags declaration. + # NOTE: from go1.5+ linker syntax is no more compatible with <go1.4; + # this hack ensures that the old behaviour is honoured. if [[ $( get_version_component_range 1-2 ${GOLANG_VERSION} ) == "1.4" ]]; then GOLANG_PKG_LDFLAGS="${GOLANG_PKG_LDFLAGS//=/ }" fi + # Disables debug symbols (DWARF) when not required. + ! use debug && GOLANG_PKG_LDFLAGS="-s -w ${GOLANG_PKG_LDFLAGS}" + + # Sanitizes vars from entra white spaces. + GOLANG_PKG_LDFLAGS="$( echo ${GOLANG_PKG_LDFLAGS} )" + GOLANG_PKG_TAGS="$( echo ${GOLANG_PKG_TAGS} )" + einfo "${EGO} build -ldflags '$GOLANG_PKG_LDFLAGS' -tags '$GOLANG_PKG_TAGS' $*" ${EGO} build \ - -ldflags "-s -w $( echo ${GOLANG_PKG_LDFLAGS} )" \ - -tags "$( echo ${GOLANG_PKG_TAGS} )" \ - $* \ + -ldflags "${GOLANG_PKG_LDFLAGS}" \ + -tags "${GOLANG_PKG_TAGS}" \ + $( echo $* ) \ || die } @@ -888,22 +900,16 @@ golang_add_vendor() { [[ ${GOLANG_VERSION} ]] || die "No Golang implementation set (golang_setup not called?)." - case $( get_version_component_range 1-2 ${GOLANG_VERSION} ) in - 1.4*) - # TODO: traverse $1 and expose all the bundled /vendor - # sub-directories to GOLANG_PKG_VENDOR - if [[ ! -d "${1}"/src ]]; then - ebegin "Fixing $1" - ln -s "${1}" "${1}"/src || die - eend - fi + [[ ! -d "${1}" ]] && return - GOLANG_PKG_VENDOR+=" ${1}" - ;; - 1.5*) - export GO15VENDOREXPERIMENT=1 - ;; - esac + # NOTE: this hack is required by Go v1.4 and older versions. + if [[ ! -d "${1}"/src ]]; then + ebegin "Fixing $1" + ln -s "${1}" "${1}"/src || die + eend + fi + + GOLANG_PKG_VENDOR+=(${1}) } diff --git a/eclass/golang-live.eclass b/eclass/golang-live.eclass new file mode 100644 index 0000000..dce0945 --- /dev/null +++ b/eclass/golang-live.eclass @@ -0,0 +1,157 @@ +# Copyright 1999-2016 Gentoo Foundation +# Distributed under the terms of the GNU General Public License v2 +# $Id$ + +# @ECLASS: golang-live.eclass +# @MAINTAINER: +# Mauro Toffanin <toffanin.mauro@gmail.com> +# @AUTHOR: +# Mauro Toffanin <toffanin.mauro@gmail.com> +# @BLURB: Eclass for fetching and unpacking HEAD shapshot of go repositories +# @DESCRIPTION: +# This eclass is written to ease the maintenance of live ebuilds +# of software written in the Go programming language. + +inherit golang-base + +EXPORT_FUNCTIONS src_prepare src_unpack src_configure src_compile src_install src_test + +if [[ -z ${_GOLANG_LIVE_ECLASS} ]]; then +_GOLANG_LIVE_ECLASS=1 + + +# @ECLASS-VARIABLE: EGO_LIVESTORE_DIR +# @INTERNAL +# @DESCRIPTION: +# Storage directory for Go sources. +# Ebuilds must not set it. + +# @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 then switch over to building with FEATURES=userpriv. +# Or vice-versa. Shouldn't be a security issue here as anyone who has +# portage group write access already can screw the system over in more +# creative ways. + + +# Validates use of GOLANG_PKG_DEPENDENCIES. +# NOTE: a live ebuild should not have go dependencies. +# TODO: check also if GOLANG_PKG_DEPENDENCIES is an array +if [[ -n ${GOLANG_PKG_DEPENDENCIES} ]]; then + eerror "Ebuild ${CATEGORY}/${PF} specifies GOLANG_PKG_DEPENDENCIES." + eerror "Please, fix it by removing GOLANG_PKG_DEPENDENCIES entirely." + die "Banned variable GOLANG_PKG_DEPENDENCIES is set" +fi + + +# @FUNCTION: golang-live_src_fetch +# @DESCRIPTION: +# Fetch a go package along with its dependencies. +golang-live_src_fetch() { + debug-print-function ${FUNCTION} "$@" + + [[ -z ${EGO_LIVESTORE_DIR} ]] && die "No EGO_LIVESTORE_DIR set (golang-live_src_unpack not called?)." + + # Fetch the go package + [[ -n ${EVCS_UMASK} ]] && eumask_push ${EVCS_UMASK} + + set -- env \ + GOPATH="${EGO_LIVESTORE_DIR}" \ + go get -d -u -v -t -tags="${GOLANG_PKG_TAGS}" ${@} + echo "$@" + "$@" || die + + [[ -n ${EVCS_UMASK} ]] && eumask_pop +} + +# @FUNCTION: golang-live_src_unpack +# @DESCRIPTION: +# Unpack the source archive. +golang-live_src_unpack() { + debug-print-function ${FUNCNAME} "$@" + + # Creates EGO_LIVESTORE_DIR if necessary. + local distdir=${PORTAGE_ACTUAL_DISTDIR:-${DISTDIR}} + : EGO_LIVESTORE_DIR=${EGO_LIVESTORE_DIR:=${distdir}/go-${PN}-livesrc} + + [[ -n ${EVCS_UMASK} ]] && eumask_push ${EVCS_UMASK} + + if [[ ! -d ${EGO_LIVESTORE_DIR} ]]; then + ( + addwrite / + mkdir -p "${EGO_LIVESTORE_DIR}" + ) || die "${ECLASS}: unable to create ${EGO_LIVESTORE_DIR}" + fi + + addwrite "${EGO_LIVESTORE_DIR}" + + [[ -n ${EVCS_UMASK} ]] && eumask_pop + + # Retrieves the GOLANG_PKG_IMPORTPATH go package. + golang-live_src_fetch "${GOLANG_PKG_IMPORTPATH}/${GOLANG_PKG_NAME}"/... + + # Creates SOURCE directory. + mkdir -p "${S}" || die +} + + +# @FUNCTION: golang-live_src_prepare +# @DESCRIPTION: +# Prepare source code. +golang-live_src_prepare() { + debug-print-function ${FUNCNAME} "${@}" + + # Sets up GoLang build environment. + golang_setup + + # Imports all go dependencies + ebegin "Importing all the sources in ${GOPATH}" + cp -r "${EGO_LIVESTORE_DIR}/src" "${GOPATH}" || die "Unable to copy sources to ${GOPATH}" + eend + + golang-base_src_prepare +} + + +# @FUNCTION: golang-live_src_configure +# @DESCRIPTION: +# Configure the package. +golang-live_src_configure() { + debug-print-function ${FUNCNAME} "$@" + + golang-base_src_configure +} + +# @FUNCTION: golang-live_src_compile +# @DESCRIPTION: +# Compiles the package. +golang-live_src_compile() { + debug-print-function ${FUNCNAME} "$@" + + golang-base_src_compile +} + +# @FUNCTION: golang-live_src_install +# @DESCRIPTION: +# Installs binaries and documents from DOCS or HTML_DOCS arrays. +golang-live_src_install() { + debug-print-function ${FUNCNAME} "$@" + + golang-base_src_install +} + +# @FUNCTION: golang-live_src_test +# @DESCRIPTION: +# Runs the unit tests for the main package. +golang-live_src_test() { + debug-print-function ${FUNCNAME} "$@" + + golang-base_src_test +} + + +fi diff --git a/eclass/golang-single.eclass b/eclass/golang-single.eclass index 202d5ec..6e3657c 100644 --- a/eclass/golang-single.eclass +++ b/eclass/golang-single.eclass @@ -72,7 +72,7 @@ _GOLANG_SINGLE_ECLASS=1 # This eclass uses GOLANG_PKG_IMPORTPATH to populate SRC_URI. -SRC_URI="https://${GOLANG_PKG_IMPORTPATH}/${GOLANG_PKG_NAME}/archive/${GOLANG_PKG_ARCHIVEPREFIX}${GOLANG_PKG_VERSION}${GOLANG_PKG_ARCHIVESUFFIX} -> ${P}${GOLANG_PKG_ARCHIVESUFFIX}" +SRC_URI="${SRC_URI:="https://${GOLANG_PKG_IMPORTPATH}/${GOLANG_PKG_NAME}/archive/${GOLANG_PKG_ARCHIVEPREFIX}${GOLANG_PKG_VERSION}${GOLANG_PKG_ARCHIVESUFFIX} -> ${P}${GOLANG_PKG_ARCHIVESUFFIX}"}" # This eclass uses GOLANG_PKG_DEPENDENCIES associative array to populate SRC_URI # with the required snapshots of the supplied GoLang dependencies. |