Gentoo Archives: gentoo-dev

From: "Michał Górny" <mgorny@g.o>
To: gentoo-dev@l.g.o
Cc: python@g.o, "Michał Górny" <mgorny@g.o>
Subject: [gentoo-dev] [PATCH 2/3] [distutils-r1] support restricting *_all() phase impls
Date: Mon, 05 Jan 2015 18:19:20
Message-Id: 1420481910-13985-2-git-send-email-mgorny@gentoo.org
In Reply to: [gentoo-dev] [PATCH 1/3] [python-r1] python_setup, allow restricting acceptable impls by "Michał Górny"
1 Add a DISTUTILS_ALL_SUBPHASE_IMPLS variable that can be used to restrict
2 implementations for the *_all() sub-phases.
3
4 Example use:
5
6 IUSE="doc"
7 RDEPEND="doc? ( dev-python/epydoc[$(python_gen_usedep 'python2*')] )"
8 REQUIRED_USE="doc? ( || ( $(python_gen_useflags 'python2*') ) )"
9
10 pkg_setup() {
11 use doc && DISTUTILS_ALL_SUBPHASE_IMPLS=( 'python2*' )
12 }
13
14 python_compile_all() {
15 use doc && esetup.py doc
16 }
17 ---
18 eclass/distutils-r1.eclass | 53 ++++++++++++++++++++++++++++++++++++----------
19 1 file changed, 42 insertions(+), 11 deletions(-)
20
21 diff --git a/eclass/distutils-r1.eclass b/eclass/distutils-r1.eclass
22 index da5c687..33b2a96 100644
23 --- a/eclass/distutils-r1.eclass
24 +++ b/eclass/distutils-r1.eclass
25 @@ -181,6 +181,31 @@ fi
26 # 'build --build-base ${BUILD_DIR}' to enforce keeping & using built
27 # files in the specific root.
28
29 +# @ECLASS-VARIABLE: DISTUTILS_ALL_SUBPHASE_IMPLS
30 +# @DEFAULT_UNSET
31 +# @DESCRIPTION:
32 +# An array of patterns specifying which implementations can be used
33 +# for *_all() sub-phase functions. If undefined, defaults to '*'
34 +# (allowing any implementation). If multiple values are specified,
35 +# implementations matching any of the patterns will be accepted.
36 +#
37 +# If the restriction needs to apply conditionally to a USE flag,
38 +# the variable should be set conditionally as well (e.g. in an early
39 +# phase function or other convenient location).
40 +#
41 +# Please remember to add a matching || block to REQUIRED_USE,
42 +# to ensure that at least one implementation matching the patterns will
43 +# be enabled.
44 +#
45 +# Example:
46 +# @CODE
47 +# REQUIRED_USE="doc? ( || ( $(python_gen_useflags 'python2*') ) )"
48 +#
49 +# pkg_setup() {
50 +# use doc && DISTUTILS_ALL_SUBPHASE_IMPLS=( 'python2*' )
51 +# }
52 +# @CODE
53 +
54 # @ECLASS-VARIABLE: mydistutilsargs
55 # @DEFAULT_UNSET
56 # @DESCRIPTION:
57 @@ -624,24 +649,30 @@ distutils-r1_run_phase() {
58 # @USAGE: [<argv>...]
59 # @INTERNAL
60 # @DESCRIPTION:
61 -# Run the given command, restoring the best-implementation state.
62 +# Run the given command, restoring the state for a most preferred Python
63 +# implementation matching DISTUTILS_ALL_SUBPHASE_IMPLS.
64 #
65 # If in-source build is used, the command will be run in the copy
66 -# of sources made for the best Python interpreter.
67 +# of sources made for the selected Python interpreter.
68 _distutils-r1_run_common_phase() {
69 local DISTUTILS_ORIG_BUILD_DIR=${BUILD_DIR}
70
71 if [[ ! ${DISTUTILS_SINGLE_IMPL} ]]; then
72 - local _DISTUTILS_INITIAL_CWD=${PWD}
73 - local MULTIBUILD_VARIANTS
74 - _python_obtain_impls
75 -
76 - multibuild_for_best_variant _python_multibuild_wrapper \
77 - distutils-r1_run_phase "${@}"
78 - else
79 - # semi-hack, be careful.
80 - _distutils-r1_run_foreach_impl "${@}"
81 + local best_impl patterns=( "${DISTUTILS_ALL_SUBPHASE_IMPLS[@]-*}" )
82 + _distutils_try_impl() {
83 + local pattern
84 + for pattern in "${patterns[@]}"; do
85 + if [[ ${EPYTHON} == ${pattern} ]]; then
86 + best_impl=${MULTIBUILD_VARIANT}
87 + fi
88 + done
89 + }
90 + python_foreach_impl _distutils_try_impl
91 +
92 + local PYTHON_COMPAT=( "${best_impl}" )
93 fi
94 +
95 + _distutils-r1_run_foreach_impl "${@}"
96 }
97
98 # @FUNCTION: _distutils-r1_run_foreach_impl
99 --
100 2.2.1