diff options
author | Michał Górny <mgorny@gentoo.org> | 2020-12-31 12:18:04 +0100 |
---|---|---|
committer | Michał Górny <mgorny@gentoo.org> | 2021-01-15 18:05:53 +0100 |
commit | 10da6fd3ccd3ba547cb855371b670db909cb165c (patch) | |
tree | 0f33e366dcec2fe2125bcd5e6d4c3128465a884f /eclass | |
parent | app-emulation/libguestfs: Remove python (diff) | |
download | gentoo-10da6fd3ccd3ba547cb855371b670db909cb165c.tar.gz gentoo-10da6fd3ccd3ba547cb855371b670db909cb165c.tar.bz2 gentoo-10da6fd3ccd3ba547cb855371b670db909cb165c.zip |
python-utils-r1.eclass: Inline _python_impl_supported()
The _python_impl_supported() function is not used anymore in its
original function. It is called only once, in order to die on incorrect
targets in PYTHON_COMPAT. Let's inline the corresponding logic
in _python_set_impls() and remove the function.
While at it, add an extra check for outdated patterns. This also
renders the relevant tests obsolete.
Signed-off-by: Michał Górny <mgorny@gentoo.org>
Diffstat (limited to 'eclass')
-rw-r--r-- | eclass/python-utils-r1.eclass | 56 | ||||
-rwxr-xr-x | eclass/tests/python-utils-r1.sh | 18 |
2 files changed, 20 insertions, 54 deletions
diff --git a/eclass/python-utils-r1.eclass b/eclass/python-utils-r1.eclass index 9c8b6a14d2ac..2aa953213b6a 100644 --- a/eclass/python-utils-r1.eclass +++ b/eclass/python-utils-r1.eclass @@ -69,38 +69,6 @@ readonly _PYTHON_HISTORICAL_IMPLS # which can involve revisions of this eclass that support a different # set of Python implementations. -# @FUNCTION: _python_impl_supported -# @USAGE: <impl> -# @INTERNAL -# @DESCRIPTION: -# Check whether the implementation <impl> (PYTHON_COMPAT-form) -# is still supported. -# -# Returns 0 if the implementation is valid and supported. If it is -# unsupported, returns 1 -- and the caller should ignore the entry. -# If it is invalid, dies with an appopriate error messages. -_python_impl_supported() { - debug-print-function ${FUNCNAME} "${@}" - - [[ ${#} -eq 1 ]] || die "${FUNCNAME}: takes exactly 1 argument (impl)." - - local impl=${1} - - # keep in sync with _PYTHON_ALL_IMPLS! - # (not using that list because inline patterns shall be faster) - case "${impl}" in - python2_7|python3_[6789]|pypy3) - return 0 - ;; - jython2_7|pypy|pypy1_[89]|pypy2_0|python2_[56]|python3_[12345]) - return 1 - ;; - *) - [[ ${PYTHON_COMPAT_NO_STRICT} ]] && return 1 - die "Invalid implementation in PYTHON_COMPAT: ${impl}" - esac -} - # @FUNCTION: _python_verify_patterns # @USAGE: <pattern>... # @INTERNAL @@ -149,10 +117,26 @@ _python_set_impls() { if [[ $(declare -p PYTHON_COMPAT) != "declare -a"* ]]; then die 'PYTHON_COMPAT must be an array.' fi - for i in "${PYTHON_COMPAT[@]}"; do - # trigger validity checks - _python_impl_supported "${i}" - done + if [[ ! ${PYTHON_COMPAT_NO_STRICT} ]]; then + for i in "${PYTHON_COMPAT[@]}"; do + # check for incorrect implementations + # we're using pattern matching as an optimization + # please keep them in sync with _PYTHON_ALL_IMPLS + # and _PYTHON_HISTORICAL_IMPLS + case ${i} in + jython2_7|pypy|pypy1_[89]|pypy2_0|pypy3|python2_[5-7]|python3_[1-9]) + ;; + *) + if has "${i}" "${_PYTHON_ALL_IMPLS[@]}" \ + "${_PYTHON_HISTORICAL_IMPLS[@]}" + then + die "Mis-synced patterns in _python_set_impls: missing ${i}" + else + die "Invalid implementation in PYTHON_COMPAT: ${i}" + fi + esac + done + fi local supp=() unsupp=() diff --git a/eclass/tests/python-utils-r1.sh b/eclass/tests/python-utils-r1.sh index 86b87ec173d4..eb8223ec6ac0 100755 --- a/eclass/tests/python-utils-r1.sh +++ b/eclass/tests/python-utils-r1.sh @@ -183,24 +183,6 @@ test_fix_shebang '#!/usr/bin/foo' python2.7 FAIL # regression test for bug #522080 test_fix_shebang '#!/usr/bin/python ' python2.7 '#!/usr/bin/python2.7 ' -# make sure we don't break pattern matching -test_is "_python_impl_supported python2_5" 1 -test_is "_python_impl_supported python2_6" 1 -test_is "_python_impl_supported python2_7" 0 -test_is "_python_impl_supported python3_1" 1 -test_is "_python_impl_supported python3_2" 1 -test_is "_python_impl_supported python3_3" 1 -test_is "_python_impl_supported python3_4" 1 -test_is "_python_impl_supported python3_5" 1 -test_is "_python_impl_supported python3_6" 0 -test_is "_python_impl_supported python3_7" 0 -test_is "_python_impl_supported python3_8" 0 -test_is "_python_impl_supported pypy1_8" 1 -test_is "_python_impl_supported pypy1_9" 1 -test_is "_python_impl_supported pypy2_0" 1 -test_is "_python_impl_supported pypy" 1 -test_is "_python_impl_supported pypy3" 0 - # check _python_impl_matches behavior test_is "_python_impl_matches python2_7 -2" 0 test_is "_python_impl_matches python3_6 -2" 1 |