Gentoo Archives: gentoo-dev

From: Alec Warner <antarus@g.o>
To: gentoo-dev@l.g.o
Cc: python@g.o, hasufell@g.o, ulm@g.o, "Michał Górny" <mgorny@g.o>
Subject: Re: [gentoo-dev] [PATCH] multibuild: introduce a generic framework for custom phase functions.
Date: Sun, 10 Mar 2013 18:37:54
Message-Id: CAAr7Pr9jPLH9kvobO2wBeb9zA+QX-Y+vh+dqABV2i1pbVif5pA@mail.gmail.com
In Reply to: [gentoo-dev] [PATCH] multibuild: introduce a generic framework for custom phase functions. by "Michał Górny"
1 On Sun, Mar 10, 2013 at 8:50 AM, Michał Górny <mgorny@g.o> wrote:
2 > The framework provides functions to declare, export and obtain custom
3 > phase functions.
4
5 Thanks for fixing this up.
6
7 -A
8
9 >
10 > Each of the custom phases can be defined by eclasses and ebuilds
11 > in a manner similar to regular phases. The eclasses define
12 > ${ECLASS}_${phase} function and run 'multibuild_export_phases' to
13 > register them. The ebuilds define ${phase} function and it automatically
14 > takes precedence over eclass-defined ones.
15 > ---
16 > gx86/eclass/multibuild.eclass | 66 +++++++++++++++++++++++++++++++++++++++++++
17 > 1 file changed, 66 insertions(+)
18 >
19 > diff --git a/gx86/eclass/multibuild.eclass b/gx86/eclass/multibuild.eclass
20 > index bc510e9..3187c9e 100644
21 > --- a/gx86/eclass/multibuild.eclass
22 > +++ b/gx86/eclass/multibuild.eclass
23 > @@ -245,5 +245,71 @@ run_in_build_dir() {
24 > return ${ret}
25 > }
26 >
27 > +# @ECLASS-VARIABLE: _MULTIBUILD_EXPORTED_PHASES
28 > +# @INTERNAL
29 > +# @DESCRIPTION:
30 > +# The list of currently exported phase functions.
31 > +#
32 > +# Each function is stored in the form of 'eclass:phase-name'.
33 > +# New exports are prepended to the list, so the first matching value
34 > +# is the most recent one.
35 > +_MULTIBUILD_EXPORTED_PHASES=()
36 > +
37 > +# @FUNCTION: multibuild_export_phases
38 > +# @USAGE: <phase-name>...
39 > +# @DESCRIPTION:
40 > +# Export the eclass phase functions for named phases. The functions need
41 > +# be named ${ECLASS}_<phase-name>. The exported functions will override
42 > +# any previously exported phases.
43 > +multibuild_export_phases() {
44 > + debug-print-function ${FUNCNAME} "${@}"
45 > +
46 > + [[ ${#} -eq 0 ]] && die "Usage: multibuild_export_phases <phase-name>..."
47 > +
48 > + # just prepend to the list
49 > + _MULTIBUILD_EXPORTED_PHASES=(
50 > + "${@/#/${ECLASS}:}"
51 > + "${_MULTIBUILD_EXPORTED_PHASES[@]}"
52 > + )
53 > +}
54 > +
55 > +# @FUNCTION: multibuild_get_phase_function
56 > +# @USAGE: <phase-name>
57 > +# @DESCRIPTION:
58 > +# Find the topmost handler for the named phase. It can be either
59 > +# user-defined phase handler (with the same name as the phase)
60 > +# or a handler exported most recently by an eclass.
61 > +#
62 > +# Prints the function name to stdout or null string if there is
63 > +# no handler for the phase.
64 > +multibuild_get_phase_function() {
65 > + debug-print-function ${FUNCNAME} "${@}"
66 > +
67 > + [[ ${#} -ne 1 ]] && die "Usage: multibuild_get_phase_function <phase-name>"
68 > +
69 > + local phase=${1}
70 > +
71 > + # user-defined phase
72 > + if ! declare -f "${phase}" >/dev/null; then
73 > + local found p
74 > + for p in "${_MULTIBUILD_EXPORTED_PHASES[@]}"; do
75 > + if [[ ${p} == *:${phase} ]]; then
76 > + # we're breaking out, so we can overwrite it.
77 > + phase=${p/:/_}
78 > + found=1
79 > + break
80 > + fi
81 > + done
82 > +
83 > + if [[ ! ${found} ]]; then
84 > + return
85 > + elif ! declare -f "${phase}" >/dev/null; then
86 > + die "Phase function ${phase} exported but never defined!"
87 > + fi
88 > + fi
89 > +
90 > + echo "${phase}"
91 > +}
92 > +
93 > _MULTIBUILD=1
94 > fi
95 > --
96 > 1.8.1.5
97 >
98 >