From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) by finch.gentoo.org (Postfix) with ESMTP id BF374198005 for ; Sun, 10 Mar 2013 10:17:50 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id ED358E068C; Sun, 10 Mar 2013 10:17:43 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) (using TLSv1 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id 250A4E064E for ; Sun, 10 Mar 2013 10:17:43 +0000 (UTC) Received: from pomiocik.lan (77-255-9-250.adsl.inetia.pl [77.255.9.250]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) (Authenticated sender: mgorny) by smtp.gentoo.org (Postfix) with ESMTPSA id E1B8733BF3E; Sun, 10 Mar 2013 10:17:40 +0000 (UTC) From: =?UTF-8?q?Micha=C5=82=20G=C3=B3rny?= To: gentoo-dev@lists.gentoo.org Cc: hasufell@gentoo.org, python@gentoo.org, =?UTF-8?q?Micha=C5=82=20G=C3=B3rny?= Subject: [gentoo-dev] [PATCH 1/7] multibuild: introduce a generic framework for custom phase functions. Date: Sun, 10 Mar 2013 11:18:05 +0100 Message-Id: <1362910691-8439-1-git-send-email-mgorny@gentoo.org> X-Mailer: git-send-email 1.8.1.5 In-Reply-To: <20130310111644.0840d935@pomiocik.lan> References: <20130310111644.0840d935@pomiocik.lan> Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-dev@lists.gentoo.org Reply-to: gentoo-dev@lists.gentoo.org X-Archives-Salt: 3fd15367-5c94-4ad4-a308-8867ee6f8e23 X-Archives-Hash: 8d08017b05fe1624932316c89aaedfc2 The framework provides functions to declare, export and obtain custom phase functions. Each of the custom phases can be defined by eclasses and ebuilds in a manner similar to regular phases. The eclasses define ${ECLASS}_${phase} function and run 'multibuild_export_phases' to register them. The ebuilds define ${phase} function and it automatically takes precedence over eclass-defined ones. --- gx86/eclass/multibuild.eclass | 61 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) diff --git a/gx86/eclass/multibuild.eclass b/gx86/eclass/multibuild.eclass index bc510e9..ea0500c 100644 --- a/gx86/eclass/multibuild.eclass +++ b/gx86/eclass/multibuild.eclass @@ -28,6 +28,8 @@ if [[ ! ${_MULTIBUILD} ]]; then inherit multiprocessing +DEPEND=">=app-shells/bash-4.2" + # @ECLASS-VARIABLE: MULTIBUILD_VARIANTS # @DESCRIPTION: # An array specifying all enabled variants which multibuild_foreach* @@ -245,5 +247,64 @@ run_in_build_dir() { return ${ret} } +# @FUNCTION: multibuild_export_phases +# @USAGE: ... +# @DESCRIPTION: +# Export the eclass phase functions for named phases. The functions need +# be named ${ECLASS}_. The exported functions will override +# any previously exported phases. +multibuild_export_phases() { + debug-print-function ${FUNCNAME} "${@}" + + [[ ${#} -eq 0 ]] && die "Usage: multibuild_export_phases ..." + + # This is necessary to allow sourcing of the ebuild with old bash + # versions, e.g. for cachegen. + if [[ $(( (BASH_VERSINFO[0] << 8) + BASH_VERSINFO[1] )) \ + -lt $(( (4 << 8) + 2 )) ]] ; then + _MULTIBUILD_ANCIENT_BASH=1 + return 0 + fi + + declare -g -A _MULTIBUILD_EXPORTED_PHASES || die + local p + for p; do + _MULTIBUILD_EXPORTED_PHASES[${p}]=${ECLASS}_${p} + done +} + +# @FUNCTION: multibuild_get_phase_function +# @USAGE: +# @DESCRIPTION: +# Find the topmost handler for the named phase. It can be either +# user-defined phase handler (with the same name as the phase) +# or a handler exported most recently by an eclass. +# +# Prints the function name to stdout or null string if there is +# no handler for the phase. +multibuild_get_phase_function() { + debug-print-function ${FUNCNAME} "${@}" + + [[ ${#} -ne 1 ]] && die "Usage: multibuild_get_phase_function " + if [[ ${_MULTIBUILD_ANCIENT_BASH} ]]; then + die "Old bash (<4.2) used to start the build, please restart emerge." + fi + + local phase=${1} + + # user-defined phase + if ! declare -f "${phase}" >/dev/null; then + phase=${_MULTIBUILD_EXPORTED_PHASES[${phase}]} + + if [[ ! ${phase} ]]; then + return + elif ! declare -f "${phase}" >/dev/null; then + die "Phase function ${phase} exported but never defined!" + fi + fi + + echo "${phase}" +} + _MULTIBUILD=1 fi -- 1.8.1.5