python*-r1.eclass: Commonize PYTHON_COMPAT processing, cache the result

Introduce a common _python_set_impls function in python-utils-r1.eclass
that validates and processes PYTHON_COMPAT, then stores the result in
_PYTHON_SUPPORTED_IMPLS and _PYTHON_UNSUPPORTED_IMPLS variables. Reuse
those variables in all python-r1 suite eclasses, effectively reducing
code duplication and providing cache for repeated implementation support
checks.
This commit is contained in:
Michał Górny
2015-12-22 23:12:23 +01:00
parent cb425a3598
commit 33380ad5e1
4 changed files with 83 additions and 102 deletions
+49
View File
@@ -84,6 +84,55 @@ _python_impl_supported() {
esac
}
# @FUNCTION: _python_set_impls
# @INTERNAL
# @DESCRIPTION:
# Check PYTHON_COMPAT for well-formedness and validity, then set
# two global variables:
#
# - _PYTHON_SUPPORTED_IMPLS containing valid implementations supported
# by the ebuild (PYTHON_COMPAT - dead implementations),
#
# - and _PYTHON_UNSUPPORTED_IMPLS containing valid implementations that
# are not supported by the ebuild.
#
# Implementations in both variables are ordered using the pre-defined
# eclass implementation ordering.
#
# This function must be called once in global scope by an eclass
# utilizing PYTHON_COMPAT.
_python_set_impls() {
local i
if ! declare -p PYTHON_COMPAT &>/dev/null; then
die 'PYTHON_COMPAT not declared.'
fi
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
_PYTHON_SUPPORTED_IMPLS=()
_PYTHON_UNSUPPORTED_IMPLS=()
for i in "${_PYTHON_ALL_IMPLS[@]}"; do
if has "${i}" "${PYTHON_COMPAT[@]}"; then
_PYTHON_SUPPORTED_IMPLS+=( "${i}" )
else
_PYTHON_UNSUPPORTED_IMPLS+=( "${i}" )
fi
done
if [[ ${#_PYTHON_SUPPORTED_IMPLS[@]} -eq 0 ]]; then
die "No supported implementation in PYTHON_COMPAT."
fi
readonly _PYTHON_SUPPORTED_IMPLS _PYTHON_UNSUPPORTED_IMPLS
}
# @ECLASS-VARIABLE: PYTHON
# @DEFAULT_UNSET
# @DESCRIPTION: