Add a python_has_version() wrapper for convenient use
in python_check_deps().  It includes:

- verbose output
- default "-b" root that's more suitable for build-time checks
- forward compatibility for -b/-d/-r arguments in EAPI 6

Signed-off-by: Michał Górny <mgo...@gentoo.org>
---
 eclass/python-utils-r1.eclass | 42 +++++++++++++++++++++++++++++++++++
 1 file changed, 42 insertions(+)

diff --git a/eclass/python-utils-r1.eclass b/eclass/python-utils-r1.eclass
index 204392e08da4..fd8fbae3ef03 100644
--- a/eclass/python-utils-r1.eclass
+++ b/eclass/python-utils-r1.eclass
@@ -1397,5 +1397,47 @@ _python_run_check_deps() {
        eend ${?}
 }
 
+# @FUNCTION: python_has_version
+# @USAGE: [-b|-d|-r] <atom>...
+# @DESCRIPTION:
+# A convenience wrapper for has_version() with verbose output and better
+# defaults for use in python_check_deps().
+#
+# The wrapper accepts EAPI 7+-style -b/-d/-r options to indicate
+# the root to perform the lookup on.  Unlike has_version, the default
+# is -b.  In EAPI 6, -b and -d are translated to --host-root
+# for compatibility.
+#
+# The wrapper accepts multiple package specifications.  For the check
+# to succeed, *all* specified atoms must match.
+python_has_version() {
+       debug-print-function ${FUNCNAME} "${@}"
+
+       local root_arg=( -b )
+       case ${1} in
+               -b|-d|-r)
+                       root_arg=( "${1}" )
+                       shift
+                       ;;
+       esac
+
+       if [[ ${EAPI} == 6 ]]; then
+               if [[ ${root_arg} == -r ]]; then
+                       root_arg=()
+               else
+                       root_arg=( --host-root )
+               fi
+       fi
+
+       local pkg
+       for pkg; do
+               ebegin "    ${pkg}"
+               has_version "${root_args[@]}" "${pkg}"
+               eend ${?} || return
+       done
+
+       return 0
+}
+
 _PYTHON_UTILS_R1=1
 fi
-- 
2.35.1


Reply via email to