diff --git a/eclass/golang-common.eclass b/eclass/golang-common.eclass new file mode 100644 index 00000000..4357ef55 --- /dev/null +++ b/eclass/golang-common.eclass @@ -0,0 +1,1034 @@ +# Copyright 1999-2017 Gentoo Foundation +# Distributed under the terms of the GNU General Public License v2 +# $Id$ + +# @ECLASS: golang-utils.eclass +# @MAINTAINER: +# Mauro Toffanin +# @AUTHOR: +# Mauro Toffanin +# @BLURB: Base eclass for GoLang packages +# @SUPPORTED_EAPIS: 7 +# @DESCRIPTION: +# This eclass provides functionalities which are used by golang-single.eclass, +# golang-live.eclass, and as well as from ebuilds. +# +# This eclass should not be inherited directly from an ebuild. +# Instead, you should inherit golang-single or golang-live for GoLang packages. + +inherit eutils multiprocessing + +if [[ -z ${_GOLANG_BASE_ECLASS} ]]; then +_GOLANG_BASE_ECLASS=1 + +# Silences repoman warnings. +case "${EAPI:-0}" in + 7) + case "${GOLANG_PKG_DEPEND_ON_GO_SUBSLOT:-yes}" in + yes) + GO_DEPEND="dev-lang/go:0=" + ;; + *) + GO_DEPEND="dev-lang/go:*" + ;; + esac + ;; + *) + die "${ECLASS}: EAPI=${EAPI:-0} is not supported" ;; +esac + +DEPEND+=" ${GO_DEPEND}" + +RESTRICT+=" mirror strip" + +QA_FLAGS_IGNORED="usr/bin/.* + usr/sbin/.*" + +# @ECLASS-VARIABLE: GOLANG_PKG_NAME +# @DESCRIPTION: +# Sets the GoLang name for the generated package. +# GOLANG_PKG_NAME="${PN}" +GOLANG_PKG_NAME="${GOLANG_PKG_NAME:-${PN}}" + +# @ECLASS-VARIABLE: GOLANG_PKG_VERSION +# @DESCRIPTION: +# Sets the GoLang version for the generated package. +# GOLANG_PKG_VERSION="${PV}" +GOLANG_PKG_VERSION="${GOLANG_PKG_VERSION:-${PV/_pre/.pre}}" + +# @ECLASS-VARIABLE: GOLANG_PKG_IMPORTPATH +# @DESCRIPTION: +# Sets the remote import path for the generated package. +# GOLANG_PKG_IMPORTPATH="github.com/captObvious/" +GOLANG_PKG_IMPORTPATH="${GOLANG_PKG_IMPORTPATH:-}" + +# @ECLASS-VARIABLE: GOLANG_PKG_IMPORTPATH_ALIAS +# @DESCRIPTION: +# Sets an alias of the remote import path for the generated package. +# GOLANG_PKG_IMPORTPATH_ALIAS="privaterepo.com/captObvious/" +GOLANG_PKG_IMPORTPATH_ALIAS="${GOLANG_PKG_IMPORTPATH_ALIAS:=${GOLANG_PKG_IMPORTPATH}}" + +# @ECLASS-VARIABLE: GOLANG_PKG_ARCHIVEPREFIX +# @DESCRIPTION: +# Sets the archive prefix for the file URI of the package. +# Most projects hosted on GitHub's mirrors provide archives with prefix as +# 'v' or 'source-', other hosted services offer different archive formats. +# This eclass defaults to an empty prefix. +GOLANG_PKG_ARCHIVEPREFIX="${GOLANG_PKG_ARCHIVEPREFIX:-}" + +# @ECLASS-VARIABLE: GOLANG_PKG_ARCHIVESUFFIX +# @DESCRIPTION: +# Sets the archive suffix for the file URI of the package. +# Most projects hosted on GitHub's mirrors provide archives with suffix as +# '.tar.gz' or '.zip', other hosted services offer different archive formats. +# This eclass defaults to '.tar.gz'. +GOLANG_PKG_ARCHIVESUFFIX="${GOLANG_PKG_ARCHIVESUFFIX:=".tar.gz"}" + +# @ECLASS-VARIABLE: GOLANG_PKG_OUTPUT_NAME +# @DESCRIPTION: +# Specifies the output file name of the package. +# If not set, it derives from the name of the package, such as $GOLANG_PKG_NAME. +# This eclass defaults to $PN. +GOLANG_PKG_OUTPUT_NAME="${GOLANG_PKG_OUTPUT_NAME:=${PN}}" + +# @ECLASS-VARIABLE: GOLANG_PKG_BUILDPATH +# @DESCRIPTION: +# Specifies a go source file to be compiled as a single main package. +# This eclass defaults to an empty value. +# This eclass defaults to "/..." when the user declares GOLANG_PKG_IS_MULTIPLE=1 +GOLANG_PKG_BUILDPATH="${GOLANG_PKG_BUILDPATH:-}" + +# @ECLASS-VARIABLE: GOLANG_PKG_INSTALLPATH +# @DESCRIPTION: +# Sets the root path into which a binary, or a list of binaries, will be +# installed (e.x.: ${GOLANG_PKG_INSTALLPATH}/bin). +# This eclass defaults to "/usr" +GOLANG_PKG_INSTALLPATH="${GOLANG_PKG_INSTALLPATH:="/usr"}" + +# @ECLASS-VARIABLE: GOLANG_PKG_INSTALLSUFFIX +# @DESCRIPTION: +# Sets a suffix to use in the name of the package installation directory. +# This eclass defaults to an empty install suffix. +GOLANG_PKG_INSTALLSUFFIX="${GOLANG_PKG_INSTALLSUFFIX:-}" + +# @ECLASS-VARIABLE: GOLANG_PKG_IS_MULTIPLE +# @DESCRIPTION: +# Set to enable the building of multiple packages from a single import path. + +# @ECLASS-VARIABLE: GOLANG_PKG_HAVE_TEST +# @DEFAULT_UNSET +# @DESCRIPTION: +# Set to enable the execution of automated testing. + +# @ECLASS-VARIABLE: GOLANG_PKG_HAVE_TEST_RACE +# @DEFAULT_UNSET +# @DESCRIPTION: +# Set to enable the execution of automated testing with support for +# data race detection. + +# @ECLASS-VARIABLE: GOLANG_PKG_USE_CGO +# @DEFAULT_UNSET +# @DESCRIPTION: +# Set to enable the compilation of the package with CGO. + +# @ECLASS-VARIABLE: GOLANG_PKG_USE_GENERATE +# @DEFAULT_UNSET +# @DESCRIPTION: +# Set to run commands described by directives within existing golang files. + +# @ECLASS-VARIABLE: GOLANG_PKG_DEPEND_ON_GO_SUBSLOT +# @DESCRIPTION: +# Set to ensure the package does depend on the dev-lang/go subslot value. +# Possible values: {yes,no} +# This eclass defaults to "no" +GOLANG_PKG_DEPEND_ON_GO_SUBSLOT=${GOLANG_PKG_DEPEND_ON_GO_SUBSLOT:="no"} + +# @ECLASS-VARIABLE: GOLANG_PKG_LDFLAGS +# @DESCRIPTION: +# Sets the linker arguments to pass to 5l, 6l, or 8l. +# This eclass defaults to an empty list. +GOLANG_PKG_LDFLAGS="${GOLANG_PKG_LDFLAGS:-}" + +# @ECLASS-VARIABLE: GOLANG_PKG_TAGS +# @DESCRIPTION: +# Sets the list of build tags during the build. +# This eclass defaults to an empty list. +GOLANG_PKG_TAGS="${GOLANG_PKG_TAGS:-}" + +# @ECLASS-VARIABLE: GOLANG_PKG_VENDOR +# @DESCRIPTION: +# 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=() + +# @ECLASS-VARIABLE: GOLANG_PKG_STATIK +# @DESCRIPTION: +# Sets the arguments to pass to dev-go/statik. +# This eclass defaults to an empty list. +GOLANG_PKG_STATIK="${GOLANG_PKG_STATIK:-}" + +# @ECLASS-VARIABLE: GOLANG_PKG_USE_MODULES +# @DESCRIPTION: +# Set to enable the compilation of the package with Go modules support. + + +# @ECLASS-VARIABLE: GO +# @DEFAULT_UNSET +# @DESCRIPTION: +# The absolute path to the current GoLang interpreter. +# +# This variable is set automatically after calling golang_setup(). +# +# Default value: +# @CODE +# /usr/bin/go +# @CODE + +# @ECLASS-VARIABLE: EGO +# @DEFAULT_UNSET +# @DESCRIPTION: +# The executable name of the current GoLang interpreter. +# +# This variable is set automatically after calling golang_setup(). +# +# Default value: +# @CODE +# go +# @CODE + +# @ECLASS-VARIABLE: PATCHES +# @DEFAULT_UNSET +# @DESCRIPTION: +# Array variable containing all the patches to be applied. This variable +# is expected to be defined in the global scope of ebuilds. Make sure to +# specify the full path. This variable is used in src_prepare phase. +# +# Example: +# @CODE +# PATCHES=( +# "${FILESDIR}/mypatch.patch" +# "${FILESDIR}/mypatch2.patch" +# ) +# @CODE + + + +# Adds gccgo as a compile-time dependency when GOLANG_PKG_USE_CGO is set. +#[[ -n ${GOLANG_PKG_USE_CGO} ]] && DEPEND+=" >=sys-devel/gcc-4.8.4[go]" + +# Adds dev-go/statik as a compile-time dependency when GOLANG_PKG_STATIK is set. +[[ -n ${GOLANG_PKG_STATIK} ]] && DEPEND+=" dev-go/statik" + +# Validates GOLANG_PKG_IMPORTPATH. +if [[ -z ${GOLANG_PKG_IMPORTPATH} ]]; then + eerror "The remote import path for this package has not been declared" + die "Mandatory variable GOLANG_PKG_IMPORTPATH is unset" +fi + +# Forces a multiple package build when user specifies GOLANG_PKG_IS_MULTIPLE=1. +if [[ -n ${GOLANG_PKG_IS_MULTIPLE} && -z ${GOLANG_PKG_BUILDPATH} ]]; then + GOLANG_PKG_BUILDPATH="/..." +fi + +# Validates use of GOLANG_PKG_BUILDPATH combined with GOLANG_PKG_IS_MULTIPLE +# FIX: makes sure user isn't overriding GOLANG_PKG_BUILDPATH with inane values. +if [[ -n ${GOLANG_PKG_IS_MULTIPLE} && ${GOLANG_PKG_BUILDPATH##*/} != "..." ]]; then + ewarn "Ebuild ${CATEGORY}/${PF} specifies GOLANG_PKG_IS_MULTIPLE=1," + ewarn "but then GOLANG_PKG_BUILDPATH is overridden with \"${GOLANG_PKG_BUILDPATH}\"." + ewarn "Please, fix it by appending \"/...\" to your GOLANG_PKG_BUILDPATH." + ewarn "If in doubt, remove GOLANG_PKG_BUILDPATH entirely." +fi + +# Even though xz-utils are in @system, they must still be added to DEPEND; see +# http://archives.gentoo.org/gentoo-dev/msg_a0d4833eb314d1be5d5802a3b710e0a4.xml +if [[ ${GOLANG_PKG_ARCHIVESUFFIX/.*} == "xz" ]]; then + DEPEND+=" app-arch/xz-utils" +fi + +# Defines common USE flags +IUSE="${IUSE} debug pie" +# Enables USE 'test' when required by GOLANG_PKG_HAVE_TEST. +if [[ -n ${GOLANG_PKG_HAVE_TEST} ]]; then + IUSE+=" test" +fi + +# Defines HOMEPAGE. +[ -z "$HOMEPAGE" ] && HOMEPAGE="https://${GOLANG_PKG_IMPORTPATH}/${PN}" + +# Defines SOURCE directory. +S="${WORKDIR}/gopath/src/${GOLANG_PKG_IMPORTPATH_ALIAS}/${GOLANG_PKG_NAME}" + + +# @FUNCTION: _factorize_dependency_entities +# @INTERNAL +# @DESCRIPTION: +# Factorizes the dependency declaration in specific tokens such as the import +# path, the import path alias, the host name, the author name, the project name, +# and the revision tag. +_factorize_dependency_entities() { + debug-print-function ${FUNCNAME} "${@}" + + local -A dependency=() + local key_list=(importpathalias importpath host project_name author_name revision) + + # Strips all the white spaces from the supplied argument. + local raw_dependency="${1//\ /}" + + # Determines the alias of the import path (if present). + dependency[importpathalias]="${raw_dependency##*->}" + + # Strips the import path alias from the supplied argument. + raw_dependency="${raw_dependency%%->*}" + + # Determines the import path. + dependency[importpath]="${raw_dependency%:*}" + + # When the importpath alias is not specified, then this eclass sets the + # alias as equal to the import path minus the project name. + if [[ "${raw_dependency}" == "${dependency[importpathalias]}" ]]; then + dependency[importpathalias]="${dependency[importpath]%/*}" + fi + + # Determines the host. + dependency[host]="${dependency[importpath]%%/*}" + + # Determines the project name. + dependency[project_name]="${dependency[importpath]##*/}" + + # Determines the author name. + dependency[author_name]="${dependency[importpath]#*/}" + dependency[author_name]="${dependency[author_name]%/*}" + + # Determines the revision. + dependency[revision]="${raw_dependency#*:}" + + # Exports all the dependency tokens as an associated list. + for key in ${key_list[@]}; do + echo "${key} ${dependency[${key}]}" + done +} + + +# @FUNCTION: golang_setup +# @DESCRIPTION: +# Determines where is the GoLang implementation and then set-up the +# GoLang build environment. +golang_setup() { + debug-print-function ${FUNCNAME} "${@}" + + # NOTE: Keep /usr/bin/go as index [0] and never overwrite it, + # always append other binary paths after the index [0] + local GOLANG_BINS=( + /usr/bin/go + /usr/bin/gofmt + ) + + [[ -n ${GOLANG_PKG_STATIK} ]] && GOLANG_BINS+=(/usr/bin/statik) + + # Reset GoLang environment variables + unset EGO + unset EGOFMT + unset ESTATIK + unset GO + unset GOPATH + unset GOBIN + + # Determine is the GoLang interpreter is working + local IS_EXECUTABLE=1 + for binary in "${GOLANG_BINS[@]}"; do + debug-print "${FUNCNAME}: Checking ... ${binary}" + + [[ -x "${EPREFIX}/${binary}" ]] && continue + IS_EXECUTABLE=0 + ewarn "It seems that the binary '${binary}' is not executable." + done + + # dev-lang/go isn't installed or one of its binaries aren't executable. + # Either way, the Gentoo box is screwed; no need to set up the GoLang environment + [[ ${IS_EXECUTABLE} == 0 ]] && exit + + # dev-lang/go is available and working. + # Exports GO/EGO/EGOFMT global variables. + export GO="${GOLANG_BINS[0]}" + export EGO="${GOLANG_BINS[0]##*/}" + export EGOFMT="${GOLANG_BINS[1]}" + + # dev-go/statik is available and working. + # Exports ESTATIK global variable. + [[ -n ${GOLANG_PKG_STATIK} ]] && export ESTATIK="${GOLANG_BINS[2]##*/}" + + debug-print "${FUNCNAME}: GO = ${GO}" + debug-print "${FUNCNAME}: EGO = ${EGO}" + debug-print "${FUNCNAME}: EGOFMT = ${EGOFMT}" + debug-print "${FUNCNAME}: ESTATIK = ${ESTATIK}" + + # Determines go interpreter version. + GOLANG_VERSION="$( ${GO} version )" + GOLANG_VERSION="${GOLANG_VERSION/go\ version\ go}" + export GOLANG_VERSION="${GOLANG_VERSION%\ *}" + einfo "Found GoLang version: ${GOLANG_VERSION}" + + # Determines statik interpreter version. + # TODO: add version detection when statik will provide a -version option. + if [[ -n ${GOLANG_PKG_STATIK} ]]; then + local STATIK_VERSION="" + 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" + + # Prepares CGO_ENABLED. + CGO_ENABLED=0 + [[ -z ${GOLANG_PKG_USE_CGO} ]] || CGO_ENABLED=1 + use pie && CGO_ENABLED=1 # PIE requires CGO + + # Prepares gopath / gobin directories inside WORKDIR. + local _GOPATH="${WORKDIR}/gopath" + local _GOBIN="${WORKDIR}/gobin" + mkdir -p "${_GOBIN}" || die + mkdir -p "${_GOPATH}"/src || die + + # Exports special env variable EGO_SRC. + export EGO_SRC="${_GOPATH}/src" + + # Exports GoLang env variables. + export GOPATH="$_GOPATH" + export GOBIN="$_GOBIN" + export CGO_ENABLED + #export GOEXPERIMENT + #export GO15VENDOREXPERIMENT=0 + + GO111MODULE="off" + [[ -z ${GOLANG_PKG_USE_MODULES} ]] || GO111MODULE="on" + export GO111MODULE + + debug-print "${FUNCNAME}: GOPATH = ${GOPATH}" + debug-print "${FUNCNAME}: GOBIN = ${GOBIN}" + debug-print "${FUNCNAME}: EGO_SRC = ${EGO_SRC}" + debug-print "${FUNCNAME}: CGO_ENABLED = ${CGO_ENABLED}" + eend +} + + +# @FUNCTION: golang-common_src_prepare +# @DESCRIPTION: +# Prepare source code. +golang-common_src_prepare() { + debug-print-function ${FUNCNAME} "${@}" + + pushd "${WORKDIR}" > /dev/null || die + einfo "Preparing GoLang build environment in ${GOPATH}/src" + + # If the ebuild declares an importpath alias, then its path was + # already created during the src_unpack phase. That means the eclass + # needs to create the missing original import path (GOLANG_PKG_IMPORTPATH) + # as a simbolic link pointing to the alias. + if [[ "${GOLANG_PKG_IMPORTPATH}" != "${GOLANG_PKG_IMPORTPATH_ALIAS}" ]]; then + + # If the ebuild declares a GOLANG_PKG_NAME different from PN, then + # the latter will be used as the simbolic link target. + local TARGET="${GOLANG_PKG_NAME}" + [[ "${PN}" != "${GOLANG_PKG_NAME}" ]] && TARGET="${PN}" + + golang_fix_importpath_alias \ + "${GOLANG_PKG_IMPORTPATH_ALIAS}/${TARGET}" \ + "${GOLANG_PKG_IMPORTPATH}/${GOLANG_PKG_NAME}" + fi + + # If the ebuild declares some GoLang dependencies, then they need to be + # correctly installed into the sand-boxed GoLang build environment which + # was set up automatically during src_unpack) phase. + if [[ ${#GOLANG_PKG_DEPENDENCIES[@]} -gt 0 ]]; then + + for i in ${!GOLANG_PKG_DEPENDENCIES[@]} ; do + + # Collects all the tokens of the dependency. + local -A DEPENDENCY=() + while read -r -d $'\n' key value; do + [[ -z ${key} ]] && continue + DEPENDENCY[$key]="${value}" + done <<-EOF + $( _factorize_dependency_entities "${GOLANG_PKG_DEPENDENCIES[$i]}" ) + EOF + + # Debug + debug-print "${FUNCNAME}: DEPENDENCY = ${GOLANG_PKG_DEPENDENCIES[$i]}" + debug-print "${FUNCNAME}: importpath = ${DEPENDENCY[importpath]}" + debug-print "${FUNCNAME}: importpathalias = ${DEPENDENCY[importpathalias]}" + debug-print "${FUNCNAME}: host = ${DEPENDENCY[host]}" + debug-print "${FUNCNAME}: author = ${DEPENDENCY[author_name]}" + debug-print "${FUNCNAME}: project = ${DEPENDENCY[project_name]}" + debug-print "${FUNCNAME}: revision = ${DEPENDENCY[revision]}" + + local message="Importing ${DEPENDENCY[importpath]}" + local destdir + + # Prepares GOPATH structure. + case ${DEPENDENCY[importpathalias]} in + gopkg.in*) + message+=" as ${DEPENDENCY[importpathalias]}" + destdir="${DEPENDENCY[importpathalias]}" + + # Creates the import path in GOPATH. + mkdir -p "${GOPATH}/src/${DEPENDENCY[importpathalias]%/*}" || die + #einfo "\n${GOPATH}/src/${DEPENDENCY[importpathalias]%/*}" + ;; + *) + [[ "${DEPENDENCY[importpath]}" != "${DEPENDENCY[importpathalias]}/${DEPENDENCY[project_name]}" ]] && message+=" as ${DEPENDENCY[importpathalias]}/${DEPENDENCY[project_name]}" + destdir="${DEPENDENCY[importpathalias]}/${DEPENDENCY[project_name]}" + + # Creates the import path in GOPATH. + mkdir -p "${GOPATH}/src/${DEPENDENCY[importpathalias]}" || die + #einfo "\n${GOPATH}/src/${DEPENDENCY[importpathalias]}" + ;; + esac + + # Moves sources from WORKDIR into GOPATH. + case ${DEPENDENCY[host]} in + github*) + ebegin "${message}" + mv ${DEPENDENCY[project_name]}-${DEPENDENCY[revision]}* "${GOPATH}"/src/${destdir} || die + eend + + # FIX: sometimes the source code inside an importpath alias + # (such as gopkg.in/mylib.v1) invokes imports from + # the original import path instead of using the alias, + # thus we need a symbolic link between the alias and + # the original import path to avoid compilation issues. + # Example: gopkg.in/Shopify/sarama.v1 erroneously + # invokes imports from github.com/shopify/sarama + if [[ ${destdir} != ${DEPENDENCY[importpath]} ]]; then + golang_fix_importpath_alias ${destdir} ${DEPENDENCY[importpath]} + fi + ;; + bitbucket*) + #einfo "path: ${DEPENDENCY[author_name]}-${DEPENDENCY[project_name]}-${DEPENDENCY[revision]}" + ebegin "${message}" + mv ${DEPENDENCY[author_name]}-${DEPENDENCY[project_name]}-${DEPENDENCY[revision]}* "${GOPATH}"/src/${destdir} || die + eend + ;; + code.google*) + ebegin "${message}" + mv ${DEPENDENCY[project_name]}-${DEPENDENCY[revision]}* "${GOPATH}"/src/${destdir} || die + eend + ;; + *) die "Function 'golang-common_src_prepare' doesn't support '${DEPENDENCY[importpath]}'" ;; + esac + done + + fi + + popd > /dev/null || die + + + # Auto-detects the presence of Go's vendored + # dependencies inside $S/vendor. + local VENDOR="${S}/vendor" + if [[ -d "${VENDOR}" ]]; then + golang_add_vendor "${VENDOR}" + export GO15VENDOREXPERIMENT=1 + fi + + # Auto-detects the presence of Go's vendored + # dependencies inside $S/*/vendor + if [[ -n ${GOLANG_PKG_BUILDPATH} && ${GOLANG_PKG_BUILDPATH##*/} != "..." ]]; then + while read -r -d $' ' path; do + # Trims leading slash (if any). + path="${path/\//}" + + # Extracts the root path. + path="${path%%/*}" + + # Ignores $path when it's empty or a string of white spaces. + [[ -n $path ]] || continue + + local vendor="${S}/${path}/vendor" + if [[ -d "${vendor}" ]]; then + golang_add_vendor "${vendor}" + fi + done <<< "$( echo ${GOLANG_PKG_BUILDPATH}) " + fi + + + # Auto-detects the presence of Godep's workspace + # (see github.com/tools/godep for more infos). + VENDOR="${S}/Godeps/_workspace" + if [[ -d "${VENDOR}" ]]; then + golang_add_vendor "${VENDOR}" + fi + + # Evaluates PATCHES array. + default_src_prepare +} + + +# @FUNCTION: golang-common_src_configure +# @DESCRIPTION: +# Configure the package. +golang-common_src_configure() { + debug-print-function ${FUNCNAME} "${@}" + + [[ ${EGO} ]] || die "No GoLang implementation set (golang_setup not called?)." + + # Defines the level of verbosity. + local EGO_VERBOSE="-v" + [[ -z ${PORTAGE_VERBOSE} ]] || EGO_VERBOSE+=" -x" + + # GoLang doesn't have a configure phase, + # so instead this eclass prints the output of 'go env'. + local -a GOLANG_ENV=() + while read -r line; do + GOLANG_ENV+=("${line}") + done <<-EOF + $( ${GO} env ) + EOF + + # Prints an error when 'go env' output is missing. + if [[ ${#GOLANG_ENV[@]} -eq 1 ]]; then + eerror "Your GoLang environment should be more verbose" + fi + + # Prints GoLang environment summary. + einfo " ${EGO} env" + for env in "${GOLANG_ENV[@]}"; do + einfo " - ${env}" + done + + + # Removes GoLang object files from package source directories (pkg/) + # and temporary directories (_obj/ _test*/). + local EGO_SUBPACKAGES="${GOLANG_PKG_IMPORTPATH_ALIAS}/${GOLANG_PKG_NAME}" + case $( ver_cut 1-2 ${GOLANG_VERSION} ) in + 1.4*) ;; + *) + EGO_SUBPACKAGES+="/..." + ;; + esac +# einfo "${EGO} clean -i ${EGO_VERBOSE} ${EGO_SUBPACKAGES}" +# ${EGO} clean -i \ +# ${EGO_VERBOSE} \ +# "${EGO_SUBPACKAGES}" \ +# || die + + # Removes GoLang objects files from all the dependencies too. +# if [[ ${#GOLANG_PKG_DEPENDENCIES[@]} -gt 0 ]]; then +# +# for i in ${!GOLANG_PKG_DEPENDENCIES[@]} ; do +# +# # Collects all the tokens of the dependency. +# local -A DEPENDENCY=() +# while read -r -d $'\n' key value; do +# [[ -z ${key} ]] && continue +# DEPENDENCY[$key]="${value}" +# done <<-EOF +# $( _factorize_dependency_entities "${GOLANG_PKG_DEPENDENCIES[$i]}" ) +# EOF +# +# [[ ! -d ${DEPENDENCY[importpath]} ]] && continue +# +# # Debug +# debug-print "${FUNCNAME}: DEPENDENCY = ${GOLANG_PKG_DEPENDENCIES[$i]}" +# debug-print "${FUNCNAME}: importpath = ${DEPENDENCY[importpath]}" +# +# # Cleans object files of the dependency. +# einfo "${EGO} clean -i ${EGO_VERBOSE} ${DEPENDENCY[importpath]}" +# ${EGO} clean \ +# -i ${EGO_VERBOSE} \ +# "${DEPENDENCY[importpath]}" \ +# || die +# done +# fi + + # Before to compile Godep's dependencies it's wise to wipe out + # all pre-built object files from Godep's package source directories. + if [[ -d "${S}"/Godeps/_workspace/pkg ]]; then + ebegin "Cleaning up pre-built object files in Godep workspace" + rm -r "${S}"/Godeps/_workspace/pkg || die + eend + fi + if [[ -d "${S}"/Godeps/_workspace/bin ]]; then + ebegin "Cleaning up executables in Godep workspace" + rm -r "${S}"/Godeps/_workspace/bin || die + eend + fi + + + # Executes 'go generate'. + # NOTE: generate should never run automatically. It must be run explicitly. + if [[ -n ${GOLANG_PKG_USE_GENERATE} ]]; then + pushd "${GOPATH}/src/${GOLANG_PKG_IMPORTPATH_ALIAS}/${GOLANG_PKG_NAME}" > /dev/null || die + einfo "${EGO} generate ${EGO_VERBOSE} ${GOLANG_PKG_IMPORTPATH_ALIAS}/${GOLANG_PKG_NAME}/..." + ${EGO} generate \ + ${EGO_VERBOSE} \ + ./... \ + || die + popd > /dev/null || die + fi + + + # Executes 'statik' when explicitly asked. + if [[ -n ${GOLANG_PKG_STATIK} ]]; then + ebegin "${ESTATIK} $GOLANG_PKG_STATIK" + ${ESTATIK} $GOLANG_PKG_STATIK || die + eend + fi +} + + +# @FUNCTION: golang-common_src_compile +# @DESCRIPTION: +# Compiles the package. +golang-common_src_compile() { + debug-print-function ${FUNCNAME} "${@}" + + [[ ${EGO} ]] || die "No GoLang implementation set (golang_setup not called?)." + + # Populates env variable GOPATH with vendored workspaces (if present). + if [[ -n ${GOLANG_PKG_VENDOR} ]]; then + einfo "Using vendored dependencies from:" + + 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//${S}\//}" + GOPATH="${GOPATH}:$( echo ${path} )" + eend + done + + export GOPATH + fi + + # Enables position-independent executables (PIE) + local EGO_PIE + use pie && EGO_PIE="-buildmode=pie" + + # Defines the install suffix. + local EGO_INSTALLSUFFIX + [[ -z ${GOLANG_PKG_INSTALLSUFFIX} ]] || EGO_INSTALLSUFFIX="-installsuffix=${GOLANG_PKG_INSTALLSUFFIX}" + + # Defines the level of verbosity. + local EGO_VERBOSE="-v" + [[ -z ${PORTAGE_VERBOSE} ]] || EGO_VERBOSE+=" -x" + + # Defines the number of builds that can be run in parallel. + local EGO_PARALLEL="-p $(makeopts_jobs)" + + # Defines extra options. + local EGO_EXTRA_OPTIONS="-a" + + # Prepares build flags for the go toolchain. + local EGO_BUILD_FLAGS="$( echo ${EGO_VERBOSE} ) $( echo ${EGO_PARALLEL} ) $( echo ${EGO_EXTRA_OPTIONS} ) $( echo ${EGO_PIE} )" + [[ -n ${EGO_INSTALLSUFFIX} ]] && EGO_BUILD_FLAGS+=" $( echo ${EGO_INSTALLSUFFIX} )" + + # Detects the total number of packages. + local pkgs=0 ifs_save=${IFS} IFS=$' ' + for path in ${GOLANG_PKG_BUILDPATH[@]} ; do + pkgs=$(( $pkgs + 1 )) + done + [[ ${pkgs} -eq 0 ]] && pkgs=1 # there is always at least 1 package + IFS=${ifs_save} + + # Builds the package + einfo "Compiling ${pkgs} package(s):" + if [[ -n ${GOLANG_PKG_BUILDPATH} && ${GOLANG_PKG_BUILDPATH##*/} != "..." && ${pkgs} -gt 1 ]]; then + + # NOTE: This eclass trims all leading and trailing white spaces from the + # input of the following 'while read' loop, then appends an extra + # trailing space; this is necessary to avoid undefined behaviours + # within the loop when GOLANG_PKG_BUILDPATH is populated with only + # a single element. + while read -r -d $' ' cmd; do + # Ignores $cmd when it's empty or a string of white spaces + #einfo "cmd: |$cmd| cmd: |${cmd##*/}|" + [[ -n $cmd ]] || continue + + golang_do_build \ + ${EGO_BUILD_FLAGS} \ + -o "${GOBIN}/${cmd##*/}" \ + "${GOLANG_PKG_IMPORTPATH_ALIAS}/${GOLANG_PKG_NAME}${cmd}" + done <<< "$( echo ${GOLANG_PKG_BUILDPATH}) " + else + # If the package is a multiple package (/...) + # then this eclass doesn't specify the output name. + [[ ${GOLANG_PKG_BUILDPATH##*/} != "..." ]] && EGO_BUILD_FLAGS+=" -o ${GOBIN}/${GOLANG_PKG_OUTPUT_NAME}" + + golang_do_build \ + ${EGO_BUILD_FLAGS} \ + "${GOLANG_PKG_IMPORTPATH_ALIAS}/${GOLANG_PKG_NAME}${GOLANG_PKG_BUILDPATH}" + fi +} + + +# @FUNCTION: golang-common_src_install +# @DESCRIPTION: +# Installs binaries and documents from DOCS or HTML_DOCS arrays. +golang-common_src_install() { + debug-print-function ${FUNCNAME} "${@}" + + [[ ${EGO} ]] || die "No GoLang implementation set (golang_setup not called?)." + + # Enables position-independent executables (PIE) + local EGO_PIE + use pie && EGO_PIE="-buildmode=pie" + + # Defines the install suffix. + local EGO_INSTALLSUFFIX + [[ -z ${GOLANG_PKG_INSTALLSUFFIX} ]] || EGO_INSTALLSUFFIX="-installsuffix=${GOLANG_PKG_INSTALLSUFFIX}" + + # Defines the level of verbosity. + local EGO_VERBOSE="-v" + [[ -z ${PORTAGE_VERBOSE} ]] || EGO_VERBOSE+=" -x" + + # Defines the number of builds that can be run in parallel. + local EGO_PARALLEL="-p $(makeopts_jobs)" + + # Defines extra options. + local EGO_EXTRA_OPTIONS + + # Prepares build flags for the go toolchain. + local EGO_BUILD_FLAGS="$( echo ${EGO_VERBOSE} ) $( echo ${EGO_PARALLEL} ) $( echo ${EGO_EXTRA_OPTIONS} ) $( echo ${EGO_PIE} )" + [[ -n ${EGO_INSTALLSUFFIX} ]] && EGO_BUILD_FLAGS+=" $( echo ${EGO_INSTALLSUFFIX} )" + + # Defines sub-packages. + local EGO_SUBPACKAGES="${GOLANG_PKG_IMPORTPATH_ALIAS}/${GOLANG_PKG_NAME}${GOLANG_PKG_BUILDPATH}" + + # 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} ${EGO_SUBPACKAGES}" + ${EGO} install \ + -ldflags "${GOLANG_PKG_LDFLAGS}" \ + -tags "${GOLANG_PKG_TAGS}" \ + ${EGO_BUILD_FLAGS} \ + "${EGO_SUBPACKAGES}" \ + || die + fi + + # Installs binaries. + into ${GOLANG_PKG_INSTALLPATH} + for bin in "${GOBIN}"/* ; do + dobin ${bin} + done + + # Installs documentation. + einstalldocs +} + +# @FUNCTION: golang-common_src_test +# @DESCRIPTION: +# Runs the unit tests for the main package. +golang-common_src_test() { + debug-print-function ${FUNCNAME} "${@}" + + [[ ${EGO} ]] || die "No GoLang implementation set (golang_setup not called?)." + + # Appends S and GOBIN to exported main paths. + # FIX: this is necessary for unit tests that need to invoke bins from + # $GOBIN or from within $S/bin. + export PATH="${S}/bin:${GOBIN}:${PATH}" + + # Defines the level of verbosity. + local EGO_VERBOSE="-v" + [[ -z ${PORTAGE_VERBOSE} ]] || EGO_VERBOSE+=" -x" + + # Defines the number of builds that can be run in parallel. + local EGO_PARALLEL="-p $(makeopts_jobs)" + + # Defines extra options. + #local EGO_EXTRA_OPTIONS="-a" + + # Enables data race detection. + local EGO_RACE + [[ -n ${GOLANG_PKG_HAVE_TEST_RACE} ]] && EGO_RACE=" -race" + + # Prepares build flags for the go toolchain. + local EGO_BUILD_FLAGS="$( echo ${EGO_VERBOSE} ) $( echo ${EGO_PARALLEL} ) $( echo ${EGO_EXTRA_OPTIONS} )" + [[ -n ${EGO_RACE} ]] && EGO_BUILD_FLAGS+=" $( echo ${EGO_RACE} )" + + # Sanitizes vars from entra white spaces. + GOLANG_PKG_LDFLAGS="$( echo ${GOLANG_PKG_LDFLAGS} )" + GOLANG_PKG_TAGS="$( echo ${GOLANG_PKG_TAGS} )" + + # Defines sub-packages. + local EGO_SUBPACKAGES="${GOLANG_PKG_IMPORTPATH_ALIAS}/${GOLANG_PKG_NAME}${GOLANG_PKG_BUILDPATH}" + [[ -z ${GOLANG_PKG_IS_MULTIPLE} ]] || EGO_SUBPACKAGES="./..." + + # Detects the total number of packages. + local pkgs=0 ifs_save=${IFS} IFS=$' ' + for path in ${GOLANG_PKG_BUILDPATH[@]} ; do + pkgs=$(( $pkgs + 1 )) + done + [[ ${pkgs} -eq 0 ]] && pkgs=1 # there is always at least 1 package + IFS=${ifs_save} + + # Runs the Unit Tests + einfo "Testing ${pkgs} package(s):" + if [[ -n ${GOLANG_PKG_BUILDPATH} && ${GOLANG_PKG_BUILDPATH##*/} != "..." && ${pkgs} -gt 1 ]]; then + + # NOTE: This eclass trims all leading and trailing white spaces from the + # input of the following 'while read' loop, then appends an extra + # trailing space; this is necessary to avoid undefined behaviours + # within the loop when GOLANG_PKG_BUILDPATH is populated with only + # a single element. + while read -r -d $' ' cmd; do + # Ignores $cmd when it's empty or a string of white spaces + #einfo "cmd: |$cmd| cmd: |${cmd##*/}|" + [[ -n $cmd ]] || continue + + einfo "${EGO} test -ldflags '$GOLANG_PKG_LDFLAGS' -tags '$GOLANG_PKG_TAGS' ${EGO_BUILD_FLAGS} ${GOLANG_PKG_IMPORTPATH_ALIAS}/${GOLANG_PKG_NAME}${cmd}/..." + ${EGO} test \ + -ldflags "${GOLANG_PKG_LDFLAGS}" \ + -tags "${GOLANG_PKG_TAGS}" \ + ${EGO_BUILD_FLAGS} \ + "${GOLANG_PKG_IMPORTPATH_ALIAS}/${GOLANG_PKG_NAME}${cmd}/..." \ + || die + done <<< "$( echo ${GOLANG_PKG_BUILDPATH}) " + else + # It's a single package + einfo "${EGO} test -ldflags '$GOLANG_PKG_LDFLAGS' -tags '$GOLANG_PKG_TAGS' ${EGO_BUILD_FLAGS} ${EGO_SUBPACKAGES}" + ${EGO} test \ + -ldflags "${GOLANG_PKG_LDFLAGS}" \ + -tags "${GOLANG_PKG_TAGS}" \ + ${EGO_BUILD_FLAGS} \ + "${EGO_SUBPACKAGES}" \ + || die + fi +} + + +# @FUNCTION: golang_do_build +# @INTERNAL +# @USAGE: +# @DESCRIPTION: +# +# @CODE +# Example: +# GOLANG_PKG_LDFLAGS="-extldflags=-static" +# GOLANG_PKG_TAGS="netgo" +# +# golang_do_build ${EGO_BUILD_FLAGS} ${GOLANG_PKG_IMPORTPATH}/${GOLANG_PKG_NAME}${GOLANG_PKG_BUILDPATH} +# @CODE +golang_do_build() { + debug-print-function ${FUNCNAME} $* + + [[ ${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 +# @DESCRIPTION: +# +# @CODE +# Example +# +# golang_add_vendor "${S}"/vendor +# golang_add_vendor "${S}"/${PN}/vendor +# @CODE +golang_add_vendor() { + debug-print-function ${FUNCNAME} $* + + [[ ${1} ]] || die "${FUNCNAME}: no paths given" + + [[ ${GOLANG_VERSION} ]] || die "No Golang implementation set (golang_setup not called?)." + + [[ ! -d "${1}" ]] && return + + # 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}) +} + + +# @FUNCTION: golang_fix_importpath_alias +# @USAGE: +# @DESCRIPTION: +# Helper functions for generating a symbolic link for import path as +# . +# +# WARNING: Use this function only if GOLANG_PKG_DEPENDENCIES declaration of +# import path aliases doesn't work (e.g.: the package name differs from both the +# import path and the alias, or if the package name is case sensitive but the +# import path is not). +# +# @CODE +# Example: +# +# src_prepare() { +# golang-single_src_prepare +# +# golang_fix_importpath_alias \ +# "github.com/GoogleCloudPlatform/gcloud-golang" \ +# "google.golang.org/cloud" +# } +# @CODE +golang_fix_importpath_alias() { + debug-print-function ${FUNCNAME} "${@}" + + [[ ${1} ]] || die "${FUNCNAME}: no target specified" + [[ ${2} ]] || die "${FUNCNAME}: no alias specified" + + [[ ${EGO} ]] || die "No GoLang implementation set (golang_setup not called?)." + + + local TARGET="${1}" + local ALIAS="${2}" + + if [[ ${ALIAS%/*} != ${ALIAS} ]]; then + mkdir -p "${GOPATH}/src/${ALIAS%/*}" || die + fi + ebegin "Linking ${TARGET} as ${ALIAS}" + ln -s "${GOPATH}/src/${TARGET}" \ + "${GOPATH}/src/${ALIAS}" \ + || die + eend +} + + +fi diff --git a/eclass/golang-live.eclass b/eclass/golang-live.eclass new file mode 100644 index 00000000..2d8902fe --- /dev/null +++ b/eclass/golang-live.eclass @@ -0,0 +1,157 @@ +# Copyright 1999-2017 Gentoo Foundation +# Distributed under the terms of the GNU General Public License v2 +# $Id$ + +# @ECLASS: golang-live.eclass +# @MAINTAINER: +# Mauro Toffanin +# @AUTHOR: +# Mauro Toffanin +# @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-common + +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-common_src_prepare +} + + +# @FUNCTION: golang-live_src_configure +# @DESCRIPTION: +# Configure the package. +golang-live_src_configure() { + debug-print-function ${FUNCNAME} "$@" + + golang-common_src_configure +} + +# @FUNCTION: golang-live_src_compile +# @DESCRIPTION: +# Compiles the package. +golang-live_src_compile() { + debug-print-function ${FUNCNAME} "$@" + + golang-common_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-common_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-common_src_test +} + + +fi diff --git a/eclass/golang-single.eclass b/eclass/golang-single.eclass new file mode 100644 index 00000000..e8007f76 --- /dev/null +++ b/eclass/golang-single.eclass @@ -0,0 +1,185 @@ +# Copyright 1999-2017 Gentoo Foundation +# Distributed under the terms of the GNU General Public License v2 +# $Id$ + +# @ECLASS: golang-single.eclass +# @MAINTAINER: +# Mauro Toffanin +# @AUTHOR: +# Mauro Toffanin +# @BLURB: An eclass for GoLang packages not installed inside GOPATH/GOBIN. +# @DESCRIPTION: +# This eclass allows to install arbitrary packages written in GoLang which +# don't support being installed inside the Go environment. +# This mostly includes traditional packages (C/C++/GUI) embedding tools written +# in GoLang, and GoLang packages that need to be compiled with GCC instead of +# the standard Go interpreter. +# +# @EXAMPLE: +# Typical ebuild using golang-single.eclass: +# +# @CODE +# EAPI=5 +# +# GOLANG_PKG_IMPORTPATH="github.com/captObvious" +# GOLANG_PKG_ARCHIVESUFFIX=".zip" +# GOLANG_PKG_HAVE_TEST +# inherit golang-single qt4-r2 +# +# DESCRIPTION="Foo bar application" +# HOMEPAGE="http://example.org/foo/" +# +# LICENSE="MIT" +# KEYWORDS="~amd64 ~x86" +# SLOT="0" +# IUSE="doc qt4" +# +# CDEPEND=" +# qt4? ( +# dev-qt/qtcore:4 +# dev-qt/qtgui:4 +# )" +# RDEPEND="${CDEPEND} +# !media-gfx/bar" +# DEPEND="${CDEPEND} +# doc? ( app-doc/doxygen )" +# +# DOCS=(AUTHORS ChangeLog README "Read me.txt" TODO) +# +# PATCHES=( +# "${FILESDIR}/${P}-qt4.patch" # bug 123458 +# "${FILESDIR}/${P}-as-needed.patch" +# ) +# +# src_install() { +# use doc && HTML_DOCS=("${BUILD_DIR}/apidocs/html/") +# autotools-utils_src_install +# if use examples; then +# dobin "${BUILD_DIR}"/foo_example{1,2,3} \\ +# || die 'dobin examples failed' +# fi +# } +# +# @CODE + + +inherit golang-common + +EXPORT_FUNCTIONS src_prepare src_unpack src_configure src_compile src_install src_test + +if [[ -z ${_GOLANG_SINGLE_ECLASS} ]]; then +_GOLANG_SINGLE_ECLASS=1 + + +# This eclass uses GOLANG_PKG_IMPORTPATH to populate SRC_URI. +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. +if [[ ${#GOLANG_PKG_DEPENDENCIES[@]} -gt 0 ]]; then + + for i in ${!GOLANG_PKG_DEPENDENCIES[@]} ; do + + # Collects all the tokens of the dependency. + local -A DEPENDENCY=() + while read -d $'\n' key value; do + [[ -z ${key} ]] && continue + DEPENDENCY[$key]="${value}" + done <<-EOF + $( _factorize_dependency_entities "${GOLANG_PKG_DEPENDENCIES[$i]}" ) + EOF + + # Debug + debug-print "${FUNCNAME}: DEPENDENCY = ${GOLANG_PKG_DEPENDENCIES[$i]}" + debug-print "${FUNCNAME}: importpath = ${DEPENDENCY[importpath]}" + debug-print "${FUNCNAME}: revision = ${DEPENDENCY[revision]}" + + # Downloads the archive. + case ${DEPENDENCY[importpath]} in + github*) + SRC_URI+=" https://${DEPENDENCY[importpath]}/archive/${DEPENDENCY[revision]}${GOLANG_PKG_ARCHIVESUFFIX} -> ${DEPENDENCY[importpath]//\//-}-${DEPENDENCY[revision]}${GOLANG_PKG_ARCHIVESUFFIX}" + ;; + bitbucket*) + SRC_URI+=" https://${DEPENDENCY[importpath]}/get/${DEPENDENCY[revision]}.zip -> ${DEPENDENCY[importpath]//\//-}-${DEPENDENCY[revision]}.zip" + ;; + code.google*) + SRC_URI+=" https://${DEPENDENCY[project_name]}.googlecode.com/archive/${DEPENDENCY[revision]}.tar.gz -> ${DEPENDENCY[importpath]//\//-}-${DEPENDENCY[revision]}.tar.gz" + ;; + *) die "This eclass doesn't support '${DEPENDENCY[importpath]}'" ;; + esac + + done +fi + + +# @FUNCTION: golang-single_src_unpack +# @DESCRIPTION: +# Unpack the source archive. +golang-single_src_unpack() { + debug-print-function ${FUNCNAME} "${@}" + + default + + # Creates S. + mkdir -p "${S%/*}" || die + + # Moves main GoLang package from WORKDIR into GOPATH. + if [[ "${GOLANG_PKG_IMPORTPATH}" != "${GOLANG_PKG_IMPORTPATH_ALIAS}" ]]; then + local alias_abspath="${WORKDIR}/gopath/src/${GOLANG_PKG_IMPORTPATH_ALIAS}/${GOLANG_PKG_NAME}" + mkdir -p "${alias_abspath%/*}" || die + mv "${GOLANG_PKG_NAME}-${GOLANG_PKG_VERSION}" "${alias_abspath}"/ || die + else + mv "${GOLANG_PKG_NAME}-${GOLANG_PKG_VERSION}" "${S}"/ || die + fi +} + + +# @FUNCTION: golang-single_src_prepare +# @DESCRIPTION: +# Prepare source code. +golang-single_src_prepare() { + debug-print-function ${FUNCNAME} "$@" + + # Sets up GoLang build environment. + golang_setup + + golang-common_src_prepare +} + +# @FUNCTION: golang-single_src_configure +# @DESCRIPTION: +# Configure the package. +golang-single_src_configure() { + debug-print-function ${FUNCNAME} "$@" + + golang-common_src_configure +} + +# @FUNCTION: golang-single_src_compile +# @DESCRIPTION: +# Compiles the package. +golang-single_src_compile() { + debug-print-function ${FUNCNAME} "$@" + + golang-common_src_compile +} + +# @FUNCTION: golang-single_src_install +# @DESCRIPTION: +# Installs binaries and documents from DOCS or HTML_DOCS arrays. +golang-single_src_install() { + debug-print-function ${FUNCNAME} "$@" + + golang-common_src_install +} + +# @FUNCTION: golang-single_src_test +# @DESCRIPTION: +# Runs the unit tests for the main package. +golang-single_src_test() { + debug-print-function ${FUNCNAME} "$@" + + golang-common_src_test +} + +fi diff --git a/net-p2p/trezord-go/Manifest b/net-p2p/trezord-go/Manifest new file mode 100644 index 00000000..4eeceac8 --- /dev/null +++ b/net-p2p/trezord-go/Manifest @@ -0,0 +1,9 @@ +DIST github.com-felixge-httpsnoop-33ec42c.tar.gz 10726 SHA256 0d7169a09dee1a5c5e4e2d4bf45bcf782f3bcb031d6fcd057371b63a05d5216d SHA512 c7616b25718e2b50f8c5532da0c9b5ba9a6217d12f459f53b715c966eb4032e25d76533922271a6c0f94eacec91aaddabcdd07e3c0d5c96a3b754a180f57a995 WHIRLPOOL 44814ebed70561f511bf21cf911438ec2d83499d4a5d457ac931ae009e0eb6f2ae6580278f41512cd30d3008486ef77a502c78f0581aa1d3e7213d32b46ff844 +DIST github.com-gorilla-csrf-79c60d0.tar.gz 21853 SHA256 f368d039caca56688af7275a86c0da6e9b1e278060d90b0bbf15a7eadfa0e791 SHA512 85ac6ba263f9d0e870aaabbc41e565e7f840b2b2e42e20020b24632f106416911f6b5a2a50b93715569cc1c7a7f8e8078013c78110ae3ebcdea2b186704279c2 WHIRLPOOL b1f04b044618b30800b15fd40d3e80ec70c90f43046d625e144d71dbf4fce158c9a0e016ba55d1e8d04f4aa4afca7b71787524202a2fae2eaac1c3f40ce02bf3 +DIST github.com-gorilla-handlers-d453eff.tar.gz 20964 SHA256 408ef8b866b420417a12387b7802ed17ec28f208f63cc7b2760d991776661c6d SHA512 01b4e7d19a35a771afc00313dfc623ab1cd4373de8d0cec5d95da92a8d2438e0a591f3de14bdc184ed76efe0060fb88839148e048d75c817556a04bbd37c45eb WHIRLPOOL 7da069ab465810c46ef182be99dcc566727daf942f59c7bae78f699b82d5941da2516ff8fb50d28de084e9a97c63813d2843745cdaadab4c3ef3b85e0b7ee9e8 +DIST github.com-gorilla-mux-98cb6bf.tar.gz 45552 SHA256 5ad53aedce3cbeb0bb410c334745d72296ce5da38477b705915729d049c2bfbc SHA512 cdd399cd470c345eebc87b36e02bc01d513744799ce00aff5575fed90de7b20dfcb311244d8d9b8bd190cfa8699f8f38105edb4f19a938c5767d589f99166da4 WHIRLPOOL bc51594d22c8f005001f7be675f74d2b2e3fa05525c649c835ba61561b7c15d9bf6dbeaaa437528e4512d766f7498d272e01ff21cb1d23286bd142e2c7cc403b +DIST github.com-gorilla-securecookie-e59506c.tar.gz 41294 SHA256 0fc95fb378846a90e805a984d4b2491cc7f12c29170e4e37a7242b7cf1e70d97 SHA512 91495069274558b8fb578d595abc0125402cecd5d26891294103551bfd667804aa9e3e99ceef9f421665d46edacca4dbdeb42388588d16e112376c43ab60c82e WHIRLPOOL d9d5efb33ace7d0a42a91e33d1e13f7ffa7d1b7e0e9500b364a5e30ae4a6bef72b16262c8b4c5f97916569aaff6ed52e5a6ccc47b877e32089dfe9aedfd1ea95 +DIST github.com-natefinch-lumberjack-dd45e6a.tar.gz 11042 SHA256 c760783c5fc93742376a8e5dc566e79416e5d990d91d3f7125fa52934254989f SHA512 e63a6c1deee45ca4a4c3ebcac381fee00fdebde00fd1a7f2a196b7283b9fc08e1c67fc999f56a9783185037ff7ccbec1c77665373c1646097594d7bf459db322 WHIRLPOOL 3fafd7bb18e1f96e00cdbc1bf7481f3cb1c77ab985a0808ace3e85ca431844d6d56ebef81f5870147acf845b124d621c529c2532e432524aa197477064250c73 +DIST github.com-pkg-errors-614d223.tar.gz 13422 SHA256 7d1073edc73a6e0f0bc87df9ab1c44429c967be6900c910ab171717993b7226b SHA512 a4649ab3259eb56519d405365f4e09027c5681cd2d086eaf92ea76c6471043242170ed5cf2240f2ff3f35644b1543f53eb8e77bdc4b3cd78638260948dd19d93 WHIRLPOOL 7a48eb66aea78d298c934fee9f23fa6d1030acd3c82044eb6d477a32f092ec6e9b403c98e0a585599e8d37352fb82ff0920dac6f80b6bb12e31ecf78216e7c3d +DIST trezord-go-2.0.30.tar.gz 5468178 SHA256 9ee13c21e004493071d9ffb649c8b141183749d0d1405dedadc5b5324ef64cd3 SHA512 899c9453cea4a0a7ac2a69fdd889f084f9918a85afa7e33620bf02fdf098a66bcfe9997d0bc3722ae1003dbb8ae5b6fbc7e7d8e7fcb14b2de0aa0a9d5492ec40 WHIRLPOOL e79ebd09d19c7be52a02d7701ad98bb3116395f007f67b30b4416eed63af99f0bfcfd13540051b68a0e4f26f05653197a64c886980d52c37696ca38b6ef21a34 +EBUILD trezord-go-2.0.30.ebuild 645 SHA256 d96e0b40d62db581deb0e31ade6abc75131cf791846e0a14b2953d3c2c1da422 SHA512 472c3961f4fbc63e0439f438b3f89dc4c6de6a5ae592bd0ba921812eb2975575294526efe29c030de71dce508af770a2003716ca8650e86e4116704e80df0bdd WHIRLPOOL 1dde424aa4aec18319532bc562f3840747f6296060c090fbf306c6970b27f90be2284dca5b99a2f95d9d3140384be71101a437234d54198a6c172e485f243f6b diff --git a/net-p2p/trezord-go/trezord-go-2.0.30.ebuild b/net-p2p/trezord-go/trezord-go-2.0.30.ebuild new file mode 100644 index 00000000..a7e07410 --- /dev/null +++ b/net-p2p/trezord-go/trezord-go-2.0.30.ebuild @@ -0,0 +1,26 @@ +EAPI=7 + +GOLANG_PKG_IMPORTPATH="github.com/trezor" +GOLANG_PKG_VERSION="d0b5fb041d2a8e5be35899655949e154b3b7845b" + +GOLANG_PKG_DEPENDENCIES=( + "github.com/gorilla/csrf:79c60d0" # 1.7.0 + "github.com/gorilla/handlers:d453eff" # 1.5.1 + "github.com/gorilla/mux:98cb6bf" # 1.8.0 + "github.com/gorilla/securecookie:e59506c" # 1.1.1 + "github.com/felixge/httpsnoop:33ec42c" # 1.0.1 + "github.com/pkg/errors:614d223" # 0.9.1 + "github.com/natefinch/lumberjack:dd45e6a -> gopkg.in/natefinch/lumberjack.v2" # 2.0.0 +) + +inherit golang-single + +DESCRIPTION="Trezor Bridge" + +LICENSE="LGPL-3" +SLOT="0" +KEYWORDS="amd64" + +GOLANG_PKG_USE_CGO=1 + +DEPEND="!net-p2p/trezord" diff --git a/net-p2p/trezord/Manifest b/net-p2p/trezord/Manifest index be608a22..6771d581 100644 --- a/net-p2p/trezord/Manifest +++ b/net-p2p/trezord/Manifest @@ -1,3 +1,3 @@ DIST trezord-2.0.29.tar.gz 5579397 SHA256 39649bf24f2f6c3d1ad1b23a97365d6d483a7a64d4d925377c3520581ff8c6ba SHA512 358aff3087ab9b1c57ce323f1827efe4e084503ab7bd88942bba0b7581f1c01474e31df17391d182a4fff749c05c691bfad6001752d6a28d6270d872b81f734d WHIRLPOOL 6ead3c00f71637646cf83dffc72012042baf70a83e0515d88fdb16fa9c1cf8682eb4f848591d8e8c20f1bf66b6fa4dd30eced00e71e3195d96641076495fe800 -EBUILD trezord-2.0.29.ebuild 622 SHA256 afd98dad3ef79cf1f8d2fa78dfd2f17f8805fde63ac282d4ac850a8dd8f45b89 SHA512 ec973ddb183e0831d2cb11160cd7fb353dde682ac1fe9837e43e2555caa9d232e195de57f7e94edb4c1ac1c12706aa90ae0ac6071ae880e437f6333adea3a68d WHIRLPOOL e4dec4d1441eb36bccf0de5a3be340f7813396be02c82ccbe1606ca0b697056d1464954acfcb6c0e538ea125b0ac3945bfd4277f8d4914e763720daed9ea526e -EBUILD trezord-9999.ebuild 579 SHA256 1defb24781b3c5c06673dd29ab10b136dad0dd04e6c4bb02cde66dc45f5b066c SHA512 21ef1f45f0dc62d69a840fcac80f608f543183fb27787b111c1066b697b1fb4ac18dd96b18c3960cef2b5c6147695129098766ddd1b3ddf6232d51303d65d17a WHIRLPOOL d0d8ed285cb0f9241029cbc3abd051a2317d19d6ded795c8465eaef229afb0ed4a9c5fd4ebe8875980cccbf84410e3f69337d7ef5f0204bb585f3b2f07517e7e +EBUILD trezord-2.0.29.ebuild 651 SHA256 b2d09452c83189cb5a746638d3db9cc9454aaa4f68628c9ecbaa7b892700e18a SHA512 67a96ca7e81c0b6a5e78c8ecebd723cc768e0785523f01aca9b4064f787a87624e155bcd0623851aa8dfd6ed61cf35d822e99c6063ebce377047782b75bd5b74 WHIRLPOOL 17e9ec644541da75867a02f1550a1f03f6bc7222ff825c0579e7012d0037d5d4ca6bd4ee531533b3354b0f54e16c4c1e1a4fd6584fec3fd79f61b0ea6c8a53d9 +EBUILD trezord-9999.ebuild 608 SHA256 3d09e8383293f58fd157eca6eb12ed0fd619e04a7f9e39f281e8134f2c080388 SHA512 3542eda0860ffdb2ba0edd21c4084a82602509de244071b5eb05886f33549f28cf77776affa5c5dd0954d62854ba9723e84cd60e601b70cd47e1dbfb14ba2988 WHIRLPOOL 705102fbb190662a6ffd8dde4517273daf40e25a8e47adf3e36392959bb1dbeaa23573fdff381ace038cc91d895240cb6f93b5a9b71251028d328b2a10f57644 diff --git a/net-p2p/trezord/trezord-2.0.29.ebuild b/net-p2p/trezord/trezord-2.0.29.ebuild index 0f4cd999..f3969280 100644 --- a/net-p2p/trezord/trezord-2.0.29.ebuild +++ b/net-p2p/trezord/trezord-2.0.29.ebuild @@ -11,6 +11,7 @@ LICENSE="LGPL-3" SLOT="0" KEYWORDS="amd64" EGO_PN=github.com/trezor/trezord-go +DEPEND="!net-p2p/trezord-go" src_unpack() { diff --git a/net-p2p/trezord/trezord-9999.ebuild b/net-p2p/trezord/trezord-9999.ebuild index d0f21f24..3df9c7a7 100644 --- a/net-p2p/trezord/trezord-9999.ebuild +++ b/net-p2p/trezord/trezord-9999.ebuild @@ -11,6 +11,7 @@ EGIT_REPO_URI="https://github.com/trezor/trezord-go" LICENSE="LGPL-3" SLOT="0" KEYWORDS="" +DEPEND="!net-p2p/trezord-go" DEPEND="dev-lang/go"