Introduce a new --via-root mode for distutils_install_for_testing
function.  The legacy --via-home seems to no longer work for a lot
of packages but before we can confirm that --via-root is good enough
for every single one of them, let's have two variants to choose from.

The general recommendation is to try --via-root, and explicitly specify
--via-home if the former does not work.  Once all packages have explicit
--via-*, we will decide how to proceed.

Signed-off-by: Michał Górny <mgo...@gentoo.org>
---
 eclass/distutils-r1.eclass | 50 +++++++++++++++++++++++++++++++-------
 1 file changed, 41 insertions(+), 9 deletions(-)

diff --git a/eclass/distutils-r1.eclass b/eclass/distutils-r1.eclass
index 25cb67b78a31..9e862a949275 100644
--- a/eclass/distutils-r1.eclass
+++ b/eclass/distutils-r1.eclass
@@ -492,7 +492,7 @@ esetup.py() {
 }
 
 # @FUNCTION: distutils_install_for_testing
-# @USAGE: [<args>...]
+# @USAGE: [--via-root|--via-home] [<args>...]
 # @DESCRIPTION:
 # Install the package into a temporary location for running tests.
 # Update PYTHONPATH appropriately and set TEST_DIR to the test
@@ -503,11 +503,19 @@ esetup.py() {
 # namespaces (and therefore proper install needs to be done to enforce
 # PYTHONPATH) or tests rely on the results of install command.
 # For most of the packages, tests built in BUILD_DIR are good enough.
+#
+# The function supports two install modes.  The current default is
+# the legacy --via-home mode.  However, it has problems with newer
+# versions of setuptools (50.3.0+).  The --via-root mode generally
+# works for these packages, and it will probably become the default
+# in the future, once we test all affected packages.  Please note
+# that proper testing sometimes requires unmerging the package first.
 distutils_install_for_testing() {
        debug-print-function ${FUNCNAME} "${@}"
 
        # A few notes:
-       # 1) because of namespaces, we can't use 'install --root',
+       # 1) because of namespaces, we can't use 'install --root'
+       #    (NB: this is probably no longer true with py3),
        # 2) 'install --home' is terribly broken on pypy, so we need
        #    to override --install-lib and --install-scripts,
        # 3) non-root 'install' complains about PYTHONPATH and missing dirs,
@@ -522,14 +530,38 @@ distutils_install_for_testing() {
        PATH=${bindir}:${PATH}
        PYTHONPATH=${libdir}:${PYTHONPATH}
 
-       local add_args=(
-               install
-                       --home="${TEST_DIR}"
-                       --install-lib="${libdir}"
-                       --install-scripts="${bindir}"
-       )
+       local install_method=home
+       case ${1} in
+               --via-home)
+                       install_method=home
+                       shift
+                       ;;
+               --via-root)
+                       install_method=root
+                       shift
+                       ;;
+       esac
+
+       case ${install_method} in
+               home)
+                       local add_args=(
+                               install
+                                       --home="${TEST_DIR}"
+                                       --install-lib="${libdir}"
+                                       --install-scripts="${bindir}"
+                       )
+                       mkdir -p "${libdir}" || die
+                       ;;
+               root)
+                       local add_args=(
+                               install
+                                       --root="${TEST_DIR}"
+                                       --install-lib=lib
+                                       --install-scripts=scripts
+                       )
+                       ;;
+       esac
 
-       mkdir -p "${libdir}" || die
        esetup.py "${add_args[@]}" "${@}"
 }
 
-- 
2.29.2


Reply via email to