From 4446a7887e9f9b9127ba7b9757c535d78456951d Mon Sep 17 00:00:00 2001 From: Michał Górny Date: Tue, 24 Sep 2013 19:53:06 +0000 Subject: Introduce python_gen_any_dep to generate any-of dependencies matching python_check_deps() code. --- eclass/python-any-r1.eclass | 63 ++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 62 insertions(+), 1 deletion(-) (limited to 'eclass/python-any-r1.eclass') diff --git a/eclass/python-any-r1.eclass b/eclass/python-any-r1.eclass index 3be995f5946c..c5c65a3fd69f 100644 --- a/eclass/python-any-r1.eclass +++ b/eclass/python-any-r1.eclass @@ -1,6 +1,6 @@ # Copyright 1999-2013 Gentoo Foundation # Distributed under the terms of the GNU General Public License v2 -# $Header: /var/cvsroot/gentoo-x86/eclass/python-any-r1.eclass,v 1.13 2013/08/01 12:49:42 mgorny Exp $ +# $Header: /var/cvsroot/gentoo-x86/eclass/python-any-r1.eclass,v 1.14 2013/09/24 19:53:06 mgorny Exp $ # @ECLASS: python-any-r1 # @MAINTAINER: @@ -156,6 +156,67 @@ _python_build_set_globals # python_targets_python2_7(-)?,python_single_target_python2_7(+)? # @CODE +# @FUNCTION: python_gen_any_dep +# @USAGE: +# @DESCRIPTION: +# Generate an any-of dependency that enforces a version match between +# the Python interpreter and Python packages. needs +# to list one or more dependencies with verbatim '${PYTHON_USEDEP}' +# references (quoted!) that will get expanded inside the function. +# +# This should be used along with an appropriate python_check_deps() +# that checks which of the any-of blocks were matched. +# +# Example use: +# @CODE +# DEPEND="$(python_gen_any_dep ' +# dev-python/foo[${PYTHON_USEDEP}] +# || ( dev-python/bar[${PYTHON_USEDEP}] +# dev-python/baz[${PYTHON_USEDEP}] )')" +# +# python_check_deps() { +# has_version "dev-python/foo[${PYTHON_USEDEP}]" \ +# && { has_version "dev-python/bar[${PYTHON_USEDEP}]" \ +# || has_version "dev-python/baz[${PYTHON_USEDEP}]"; } +# } +# @CODE +# +# Example value: +# @CODE +# || ( +# ( +# dev-lang/python:2.7 +# dev-python/foo[python_targets_python2_7(-)?,python_single_target_python2_7(+)?] +# || ( dev-python/bar[python_targets_python2_7(-)?,python_single_target_python2_7(+)?] +# dev-python/baz[python_targets_python2_7(-)?,python_single_target_python2_7(+)?] ) +# ) +# ( +# dev-lang/python:2.6 +# dev-python/foo[python_targets_python2_6(-)?,python_single_target_python2_6(+)?] +# || ( dev-python/bar[python_targets_python2_6(-)?,python_single_target_python2_6(+)?] +# dev-python/baz[python_targets_python2_6(-)?,python_single_target_python2_6(+)?] ) +# ) +# ) +# @CODE +python_gen_any_dep() { + debug-print-function ${FUNCNAME} "${@}" + + local depstr=${1} + [[ ${depstr} ]] || die "No dependency string provided" + + local PYTHON_PKG_DEP out= + for i in "${_PYTHON_ALL_IMPLS[@]}"; do + has "${i}" "${PYTHON_COMPAT[@]}" || continue + + local PYTHON_USEDEP="python_targets_${i}(-),python_single_target_${i}(+)" + python_export "${i}" PYTHON_PKG_DEP + + local i_depstr=${depstr//\$\{PYTHON_USEDEP\}/${PYTHON_USEDEP}} + out="( ${PYTHON_PKG_DEP} ${i_depstr} ) ${out}" + done + echo "|| ( ${out})" +} + # @FUNCTION: _python_EPYTHON_supported # @USAGE: # @INTERNAL -- cgit v1.2.3-65-gdbad