From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by finch.gentoo.org (Postfix) with ESMTPS id D1848139694 for ; Sat, 20 May 2017 13:32:37 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 1B73E21C107; Sat, 20 May 2017 13:30:58 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id CF7F521C0FF for ; Sat, 20 May 2017 13:30:57 +0000 (UTC) Received: from localhost.localdomain (d202-252.icpnet.pl [109.173.202.252]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: mgorny) by smtp.gentoo.org (Postfix) with ESMTPSA id 50B8E3416BD; Sat, 20 May 2017 13:30:56 +0000 (UTC) From: =?UTF-8?q?Micha=C5=82=20G=C3=B3rny?= To: gentoo-dev@lists.gentoo.org Cc: python@gentoo.org, =?UTF-8?q?Micha=C5=82=20G=C3=B3rny?= Subject: [gentoo-dev] [PATCH 3/7] python-r1.eclass: Inline implementation loop logic into python_setup Date: Sat, 20 May 2017 15:30:40 +0200 Message-Id: <20170520133044.9692-4-mgorny@gentoo.org> X-Mailer: git-send-email 2.13.0 In-Reply-To: <20170520133044.9692-1-mgorny@gentoo.org> References: <20170520133044.9692-1-mgorny@gentoo.org> Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-dev@lists.gentoo.org Reply-to: gentoo-dev@lists.gentoo.org X-Archives-Salt: 6ca81320-dd00-4366-99d0-41fb0fa68fdf X-Archives-Hash: c5da8f5c5bbbd3da7ffe5d35d72e13c5 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 ae9e3806e729..9c37a20f7c2e 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 } -- 2.13.0