commit:     4722066cb86aa5854d9e9f40544556d742d09c8b
Author:     Michał Górny <mgorny <AT> gentoo <DOT> org>
AuthorDate: Fri May 19 17:23:22 2017 +0000
Commit:     Michał Górny <mgorny <AT> gentoo <DOT> org>
CommitDate: Mon May 29 21:53:44 2017 +0000
URL:        https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=4722066c

python-r1.eclass: Inline implementation loop logic into python_setup

Inline the logic needed to iterate over implementations directly into
python_setup instead of using python_foreach_impl. This is mostly NFC,
except that we iterate in reverse order now -- that is, we start at
the newest implementation and stop at the first one that works for us.
Previously we (implicitly) started at the oldest implementation, checked
all implementation and used the last one (i.e. the newest) that worked.

More importantly, the new code makes it possible to alter the logic more
easily and avoid relying on implementation of python_foreach_impl().

 eclass/python-r1.eclass | 35 ++++++++++++++++++++++++++---------
 1 file changed, 26 insertions(+), 9 deletions(-)

diff --git a/eclass/python-r1.eclass b/eclass/python-r1.eclass
index ae9e3806e72..9c37a20f7c2 100644
--- a/eclass/python-r1.eclass
+++ b/eclass/python-r1.eclass
@@ -597,16 +597,34 @@ python_foreach_impl() {
 python_setup() {
        debug-print-function ${FUNCNAME} "${@}"
 
-       local best_impl patterns=( "${@-*}" )
-       _python_try_impl() {
-               if _python_impl_matches "${EPYTHON}" "${patterns[@]}"; then
-                       best_impl=${EPYTHON}
+       _python_validate_useflags
+       local pycompat=( "${PYTHON_COMPAT[@]}" )
+       if [[ ${PYTHON_COMPAT_OVERRIDE} ]]; then
+               pycompat=( ${PYTHON_COMPAT_OVERRIDE} )
+       fi
+
+       # (reverse iteration -- newest impl first)
+       local found
+       for (( i = ${#_PYTHON_SUPPORTED_IMPLS[@]} - 1; i >= 0; i-- )); do
+               local impl=${_PYTHON_SUPPORTED_IMPLS[i]}
+
+               # check PYTHON_COMPAT[_OVERRIDE]
+               has "${impl}" "${pycompat[@]}" || continue
+
+               # match USE flags only if override is not in effect
+               if [[ ! ${PYTHON_COMPAT_OVERRIDE} ]]; then
+                       use "python_targets_${impl}" || continue
                fi
-       }
-       python_foreach_impl _python_try_impl
-       unset -f _python_try_impl
 
-       if [[ ! ${best_impl} ]]; then
+               # check patterns
+               _python_impl_matches "${impl}" "${@-*}" || continue
+
+               python_export "${impl}" EPYTHON PYTHON
+               found=1
+               break
+       done
+
+       if [[ ! ${found} ]]; then
                eerror "${FUNCNAME}: none of the enabled implementation matched 
the patterns."
                eerror "  patterns: ${@-'(*)'}"
                eerror "Likely a REQUIRED_USE constraint (possibly 
USE-conditional) is missing."
@@ -615,7 +633,6 @@ python_setup() {
                die "${FUNCNAME}: no enabled implementation satisfy 
requirements"
        fi
 
-       python_export "${best_impl}" EPYTHON PYTHON
        python_wrapper_setup
 }
 

Reply via email to