Add a DISTUTILS_ALL_SUBPHASE_IMPLS variable that can be used to restrict implementations for the *_all() sub-phases.
Example use: IUSE="doc" RDEPEND="doc? ( dev-python/epydoc[$(python_gen_usedep 'python2*')] )" REQUIRED_USE="doc? ( || ( $(python_gen_useflags 'python2*') ) )" pkg_setup() { use doc && DISTUTILS_ALL_SUBPHASE_IMPLS=( 'python2*' ) } python_compile_all() { use doc && esetup.py doc } --- eclass/distutils-r1.eclass | 53 ++++++++++++++++++++++++++++++++++++---------- 1 file changed, 42 insertions(+), 11 deletions(-) diff --git a/eclass/distutils-r1.eclass b/eclass/distutils-r1.eclass index da5c687..33b2a96 100644 --- a/eclass/distutils-r1.eclass +++ b/eclass/distutils-r1.eclass @@ -181,6 +181,31 @@ fi # 'build --build-base ${BUILD_DIR}' to enforce keeping & using built # files in the specific root. +# @ECLASS-VARIABLE: DISTUTILS_ALL_SUBPHASE_IMPLS +# @DEFAULT_UNSET +# @DESCRIPTION: +# An array of patterns specifying which implementations can be used +# for *_all() sub-phase functions. If undefined, defaults to '*' +# (allowing any implementation). If multiple values are specified, +# implementations matching any of the patterns will be accepted. +# +# If the restriction needs to apply conditionally to a USE flag, +# the variable should be set conditionally as well (e.g. in an early +# phase function or other convenient location). +# +# Please remember to add a matching || block to REQUIRED_USE, +# to ensure that at least one implementation matching the patterns will +# be enabled. +# +# Example: +# @CODE +# REQUIRED_USE="doc? ( || ( $(python_gen_useflags 'python2*') ) )" +# +# pkg_setup() { +# use doc && DISTUTILS_ALL_SUBPHASE_IMPLS=( 'python2*' ) +# } +# @CODE + # @ECLASS-VARIABLE: mydistutilsargs # @DEFAULT_UNSET # @DESCRIPTION: @@ -624,24 +649,30 @@ distutils-r1_run_phase() { # @USAGE: [<argv>...] # @INTERNAL # @DESCRIPTION: -# Run the given command, restoring the best-implementation state. +# Run the given command, restoring the state for a most preferred Python +# implementation matching DISTUTILS_ALL_SUBPHASE_IMPLS. # # If in-source build is used, the command will be run in the copy -# of sources made for the best Python interpreter. +# of sources made for the selected Python interpreter. _distutils-r1_run_common_phase() { local DISTUTILS_ORIG_BUILD_DIR=${BUILD_DIR} if [[ ! ${DISTUTILS_SINGLE_IMPL} ]]; then - local _DISTUTILS_INITIAL_CWD=${PWD} - local MULTIBUILD_VARIANTS - _python_obtain_impls - - multibuild_for_best_variant _python_multibuild_wrapper \ - distutils-r1_run_phase "${@}" - else - # semi-hack, be careful. - _distutils-r1_run_foreach_impl "${@}" + local best_impl patterns=( "${DISTUTILS_ALL_SUBPHASE_IMPLS[@]-*}" ) + _distutils_try_impl() { + local pattern + for pattern in "${patterns[@]}"; do + if [[ ${EPYTHON} == ${pattern} ]]; then + best_impl=${MULTIBUILD_VARIANT} + fi + done + } + python_foreach_impl _distutils_try_impl + + local PYTHON_COMPAT=( "${best_impl}" ) fi + + _distutils-r1_run_foreach_impl "${@}" } # @FUNCTION: _distutils-r1_run_foreach_impl -- 2.2.1