Gentoo Archives: gentoo-dev

From: "Michał Górny" <mgorny@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: [gentoo-dev] [PATCH] multibuild: introduce a generic framework for custom phase functions.
Date: Sun, 10 Mar 2013 15:50:15
Message-Id: 1362930617-20031-1-git-send-email-mgorny@gentoo.org
In Reply to: Re: [gentoo-dev] [PATCH 1/7] multibuild: introduce a generic framework for custom phase functions. by Ulrich Mueller
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 | 66 +++++++++++++++++++++++++++++++++++++++++++
11 1 file changed, 66 insertions(+)
12
13 diff --git a/gx86/eclass/multibuild.eclass b/gx86/eclass/multibuild.eclass
14 index bc510e9..3187c9e 100644
15 --- a/gx86/eclass/multibuild.eclass
16 +++ b/gx86/eclass/multibuild.eclass
17 @@ -245,5 +245,71 @@ run_in_build_dir() {
18 return ${ret}
19 }
20
21 +# @ECLASS-VARIABLE: _MULTIBUILD_EXPORTED_PHASES
22 +# @INTERNAL
23 +# @DESCRIPTION:
24 +# The list of currently exported phase functions.
25 +#
26 +# Each function is stored in the form of 'eclass:phase-name'.
27 +# New exports are prepended to the list, so the first matching value
28 +# is the most recent one.
29 +_MULTIBUILD_EXPORTED_PHASES=()
30 +
31 +# @FUNCTION: multibuild_export_phases
32 +# @USAGE: <phase-name>...
33 +# @DESCRIPTION:
34 +# Export the eclass phase functions for named phases. The functions need
35 +# be named ${ECLASS}_<phase-name>. The exported functions will override
36 +# any previously exported phases.
37 +multibuild_export_phases() {
38 + debug-print-function ${FUNCNAME} "${@}"
39 +
40 + [[ ${#} -eq 0 ]] && die "Usage: multibuild_export_phases <phase-name>..."
41 +
42 + # just prepend to the list
43 + _MULTIBUILD_EXPORTED_PHASES=(
44 + "${@/#/${ECLASS}:}"
45 + "${_MULTIBUILD_EXPORTED_PHASES[@]}"
46 + )
47 +}
48 +
49 +# @FUNCTION: multibuild_get_phase_function
50 +# @USAGE: <phase-name>
51 +# @DESCRIPTION:
52 +# Find the topmost handler for the named phase. It can be either
53 +# user-defined phase handler (with the same name as the phase)
54 +# or a handler exported most recently by an eclass.
55 +#
56 +# Prints the function name to stdout or null string if there is
57 +# no handler for the phase.
58 +multibuild_get_phase_function() {
59 + debug-print-function ${FUNCNAME} "${@}"
60 +
61 + [[ ${#} -ne 1 ]] && die "Usage: multibuild_get_phase_function <phase-name>"
62 +
63 + local phase=${1}
64 +
65 + # user-defined phase
66 + if ! declare -f "${phase}" >/dev/null; then
67 + local found p
68 + for p in "${_MULTIBUILD_EXPORTED_PHASES[@]}"; do
69 + if [[ ${p} == *:${phase} ]]; then
70 + # we're breaking out, so we can overwrite it.
71 + phase=${p/:/_}
72 + found=1
73 + break
74 + fi
75 + done
76 +
77 + if [[ ! ${found} ]]; then
78 + return
79 + elif ! declare -f "${phase}" >/dev/null; then
80 + die "Phase function ${phase} exported but never defined!"
81 + fi
82 + fi
83 +
84 + echo "${phase}"
85 +}
86 +
87 _MULTIBUILD=1
88 fi
89 --
90 1.8.1.5

Replies