mirror of
https://github.com/gentoo-mirror/gentoo.git
synced 2026-11-24 11:37:20 -08:00
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:
+11
-36
@@ -82,12 +82,6 @@ inherit multibuild python-utils-r1
|
||||
# @CODE
|
||||
# PYTHON_COMPAT=( python2_7 python3_{3,4} )
|
||||
# @CODE
|
||||
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
|
||||
|
||||
# @ECLASS-VARIABLE: PYTHON_COMPAT_OVERRIDE
|
||||
# @INTERNAL
|
||||
@@ -186,24 +180,17 @@ fi
|
||||
# @CODE
|
||||
|
||||
_python_set_globals() {
|
||||
local impls=()
|
||||
|
||||
PYTHON_DEPS=
|
||||
local i PYTHON_PKG_DEP
|
||||
for i in "${PYTHON_COMPAT[@]}"; do
|
||||
_python_impl_supported "${i}" || continue
|
||||
|
||||
_python_set_impls
|
||||
|
||||
for i in "${_PYTHON_SUPPORTED_IMPLS[@]}"; do
|
||||
python_export "${i}" PYTHON_PKG_DEP
|
||||
PYTHON_DEPS+="python_targets_${i}? ( ${PYTHON_PKG_DEP} ) "
|
||||
|
||||
impls+=( "${i}" )
|
||||
done
|
||||
|
||||
if [[ ${#impls[@]} -eq 0 ]]; then
|
||||
die "No supported implementation in PYTHON_COMPAT."
|
||||
fi
|
||||
|
||||
local flags=( "${impls[@]/#/python_targets_}" )
|
||||
local flags=( "${_PYTHON_SUPPORTED_IMPLS[@]/#/python_targets_}" )
|
||||
local optflags=${flags[@]/%/(-)?}
|
||||
|
||||
# A nice QA trick here. Since a python-single-r1 package has to have
|
||||
@@ -212,7 +199,7 @@ _python_set_globals() {
|
||||
# it should prevent developers from mistakenly depending on packages
|
||||
# not supporting multiple Python implementations.
|
||||
|
||||
local flags_st=( "${impls[@]/#/-python_single_target_}" )
|
||||
local flags_st=( "${_PYTHON_SUPPORTED_IMPLS[@]/#/-python_single_target_}" )
|
||||
optflags+=,${flags_st[@]/%/(-)}
|
||||
|
||||
IUSE=${flags[*]}
|
||||
@@ -246,9 +233,7 @@ _python_validate_useflags() {
|
||||
|
||||
local i
|
||||
|
||||
for i in "${PYTHON_COMPAT[@]}"; do
|
||||
_python_impl_supported "${i}" || continue
|
||||
|
||||
for i in "${_PYTHON_SUPPORTED_IMPLS[@]}"; do
|
||||
use "python_targets_${i}" && return 0
|
||||
done
|
||||
|
||||
@@ -290,9 +275,7 @@ python_gen_usedep() {
|
||||
local impl pattern
|
||||
local matches=()
|
||||
|
||||
for impl in "${PYTHON_COMPAT[@]}"; do
|
||||
_python_impl_supported "${impl}" || continue
|
||||
|
||||
for impl in "${_PYTHON_SUPPORTED_IMPLS[@]}"; do
|
||||
for pattern; do
|
||||
if [[ ${impl} == ${pattern} ]]; then
|
||||
matches+=(
|
||||
@@ -333,9 +316,7 @@ python_gen_useflags() {
|
||||
local impl pattern
|
||||
local matches=()
|
||||
|
||||
for impl in "${PYTHON_COMPAT[@]}"; do
|
||||
_python_impl_supported "${impl}" || continue
|
||||
|
||||
for impl in "${_PYTHON_SUPPORTED_IMPLS[@]}"; do
|
||||
for pattern; do
|
||||
if [[ ${impl} == ${pattern} ]]; then
|
||||
matches+=( "python_targets_${impl}" )
|
||||
@@ -382,9 +363,7 @@ python_gen_cond_dep() {
|
||||
local dep=${1}
|
||||
shift
|
||||
|
||||
for impl in "${PYTHON_COMPAT[@]}"; do
|
||||
_python_impl_supported "${impl}" || continue
|
||||
|
||||
for impl in "${_PYTHON_SUPPORTED_IMPLS[@]}"; do
|
||||
for pattern; do
|
||||
if [[ ${impl} == ${pattern} ]]; then
|
||||
# substitute ${PYTHON_USEDEP} if used
|
||||
@@ -460,12 +439,8 @@ _python_obtain_impls() {
|
||||
|
||||
MULTIBUILD_VARIANTS=()
|
||||
|
||||
for impl in "${_PYTHON_ALL_IMPLS[@]}"; do
|
||||
if has "${impl}" "${PYTHON_COMPAT[@]}" \
|
||||
&& use "python_targets_${impl}"
|
||||
then
|
||||
MULTIBUILD_VARIANTS+=( "${impl}" )
|
||||
fi
|
||||
for impl in "${_PYTHON_SUPPORTED_IMPLS[@]}"; do
|
||||
use "python_targets_${impl}" && MULTIBUILD_VARIANTS+=( "${impl}" )
|
||||
done
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user