Gentoo Archives: gentoo-dev

From: "Michał Górny" <mgorny@g.o>
To: gentoo-dev@l.g.o
Cc: hasufell@g.o, python@g.o, "Michał Górny" <mgorny@g.o>
Subject: [gentoo-dev] [PATCH 1/7] multibuild: introduce a generic framework for custom phase functions.
Date: Sun, 10 Mar 2013 10:17:50
Message-Id: 1362910691-8439-1-git-send-email-mgorny@gentoo.org
In Reply to: [gentoo-dev] [PATCHES] multibuild.eclass: custom phase function helpers by "Michał Górny"
1 The framework provides functions to declare, export and obtain custom
2 phase functions.
3
4 Each of the custom phases can be defined by eclasses and ebuilds
5 in a manner similar to regular phases. The eclasses define
6 ${ECLASS}_${phase} function and run 'multibuild_export_phases' to
7 register them. The ebuilds define ${phase} function and it automatically
8 takes precedence over eclass-defined ones.
9 ---
10 gx86/eclass/multibuild.eclass | 61 +++++++++++++++++++++++++++++++++++++++++++
11 1 file changed, 61 insertions(+)
12
13 diff --git a/gx86/eclass/multibuild.eclass b/gx86/eclass/multibuild.eclass
14 index bc510e9..ea0500c 100644
15 --- a/gx86/eclass/multibuild.eclass
16 +++ b/gx86/eclass/multibuild.eclass
17 @@ -28,6 +28,8 @@ if [[ ! ${_MULTIBUILD} ]]; then
18
19 inherit multiprocessing
20
21 +DEPEND=">=app-shells/bash-4.2"
22 +
23 # @ECLASS-VARIABLE: MULTIBUILD_VARIANTS
24 # @DESCRIPTION:
25 # An array specifying all enabled variants which multibuild_foreach*
26 @@ -245,5 +247,64 @@ run_in_build_dir() {
27 return ${ret}
28 }
29
30 +# @FUNCTION: multibuild_export_phases
31 +# @USAGE: <phase-name>...
32 +# @DESCRIPTION:
33 +# Export the eclass phase functions for named phases. The functions need
34 +# be named ${ECLASS}_<phase-name>. The exported functions will override
35 +# any previously exported phases.
36 +multibuild_export_phases() {
37 + debug-print-function ${FUNCNAME} "${@}"
38 +
39 + [[ ${#} -eq 0 ]] && die "Usage: multibuild_export_phases <phase-name>..."
40 +
41 + # This is necessary to allow sourcing of the ebuild with old bash
42 + # versions, e.g. for cachegen.
43 + if [[ $(( (BASH_VERSINFO[0] << 8) + BASH_VERSINFO[1] )) \
44 + -lt $(( (4 << 8) + 2 )) ]] ; then
45 + _MULTIBUILD_ANCIENT_BASH=1
46 + return 0
47 + fi
48 +
49 + declare -g -A _MULTIBUILD_EXPORTED_PHASES || die
50 + local p
51 + for p; do
52 + _MULTIBUILD_EXPORTED_PHASES[${p}]=${ECLASS}_${p}
53 + done
54 +}
55 +
56 +# @FUNCTION: multibuild_get_phase_function
57 +# @USAGE: <phase-name>
58 +# @DESCRIPTION:
59 +# Find the topmost handler for the named phase. It can be either
60 +# user-defined phase handler (with the same name as the phase)
61 +# or a handler exported most recently by an eclass.
62 +#
63 +# Prints the function name to stdout or null string if there is
64 +# no handler for the phase.
65 +multibuild_get_phase_function() {
66 + debug-print-function ${FUNCNAME} "${@}"
67 +
68 + [[ ${#} -ne 1 ]] && die "Usage: multibuild_get_phase_function <phase-name>"
69 + if [[ ${_MULTIBUILD_ANCIENT_BASH} ]]; then
70 + die "Old bash (<4.2) used to start the build, please restart emerge."
71 + fi
72 +
73 + local phase=${1}
74 +
75 + # user-defined phase
76 + if ! declare -f "${phase}" >/dev/null; then
77 + phase=${_MULTIBUILD_EXPORTED_PHASES[${phase}]}
78 +
79 + if [[ ! ${phase} ]]; then
80 + return
81 + elif ! declare -f "${phase}" >/dev/null; then
82 + die "Phase function ${phase} exported but never defined!"
83 + fi
84 + fi
85 +
86 + echo "${phase}"
87 +}
88 +
89 _MULTIBUILD=1
90 fi
91 --
92 1.8.1.5

Replies