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: <phase-name>...
+# @DESCRIPTION:
+# Export the eclass phase functions for named phases. The functions need
+# be named ${ECLASS}_<phase-name>. The exported functions will override
+# any previously exported phases.
+multibuild_export_phases() {
+       debug-print-function ${FUNCNAME} "${@}"
+
+       [[ ${#} -eq 0 ]] && die "Usage: multibuild_export_phases 
<phase-name>..."
+
+       # 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: <phase-name>
+# @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 
<phase-name>"
+       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


Reply via email to