Blame SOURCES/fix-tmpdir-infinite-recursion.patch

9edeeb
diff -up pip-19.3.1/news/7872.bugfix.pip7873 pip-19.3.1/news/7872.bugfix
9edeeb
--- pip-19.3.1/news/7872.bugfix.pip7873	2022-05-24 08:34:03.285054864 -0600
9edeeb
+++ pip-19.3.1/news/7872.bugfix	2022-05-24 08:34:03.285054864 -0600
9edeeb
@@ -0,0 +1 @@
9edeeb
+Prevent an infinite recursion with ``pip wheel`` when ``$TMPDIR`` is within the source directory.
9edeeb
diff -up pip-19.3.1/src/pip/_internal/download.py.pip7873 pip-19.3.1/src/pip/_internal/download.py
9edeeb
--- pip-19.3.1/src/pip/_internal/download.py.pip7873	2019-10-17 13:32:34.000000000 -0600
9edeeb
+++ pip-19.3.1/src/pip/_internal/download.py	2022-05-24 08:35:17.013833331 -0600
9edeeb
@@ -350,12 +350,24 @@ def _copy2_ignoring_special_files(src, d
9edeeb
 
9edeeb
 def _copy_source_tree(source, target):
9edeeb
     # type: (str, str) -> None
9edeeb
+    target_abspath = os.path.abspath(target)
9edeeb
+    target_basename = os.path.basename(target_abspath)
9edeeb
+    target_dirname = os.path.dirname(target_abspath)
9edeeb
+
9edeeb
     def ignore(d, names):
9edeeb
-        # Pulling in those directories can potentially be very slow,
9edeeb
-        # exclude the following directories if they appear in the top
9edeeb
-        # level dir (and only it).
9edeeb
-        # See discussion at https://github.com/pypa/pip/pull/6770
9edeeb
-        return ['.tox', '.nox'] if d == source else []
9edeeb
+        skipped = []  # type: List[str]
9edeeb
+        if d == source:
9edeeb
+            # Pulling in those directories can potentially be very slow,
9edeeb
+            # exclude the following directories if they appear in the top
9edeeb
+            # level dir (and only it).
9edeeb
+            # See discussion at https://github.com/pypa/pip/pull/6770
9edeeb
+            skipped += ['.tox', '.nox']
9edeeb
+        if os.path.abspath(d) == target_dirname:
9edeeb
+            # Prevent an infinite recursion if the target is in source.
9edeeb
+            # This can happen when TMPDIR is set to ${PWD}/...
9edeeb
+            # and we copy PWD to TMPDIR.
9edeeb
+            skipped += [target_basename]
9edeeb
+        return skipped
9edeeb
 
9edeeb
     kwargs = dict(ignore=ignore, symlinks=True)  # type: CopytreeKwargs
9edeeb
 
9edeeb
diff -up pip-19.3.1/src/pip/_internal/operations/prepare.py.pip7873 pip-19.3.1/src/pip/_internal/operations/prepare.py
9edeeb
diff -up pip-19.3.1/tests/data/src/extension/extension.c.pip7873 pip-19.3.1/tests/data/src/extension/extension.c
9edeeb
diff -up pip-19.3.1/tests/data/src/extension/setup.py.pip7873 pip-19.3.1/tests/data/src/extension/setup.py
9edeeb
--- pip-19.3.1/tests/data/src/extension/setup.py.pip7873	2022-05-24 08:34:03.285054864 -0600
9edeeb
+++ pip-19.3.1/tests/data/src/extension/setup.py	2022-05-24 08:34:03.285054864 -0600
9edeeb
@@ -0,0 +1,4 @@
9edeeb
+from setuptools import Extension, setup
9edeeb
+
9edeeb
+module = Extension('extension', sources=['extension.c'])
9edeeb
+setup(name='extension', version='0.0.1', ext_modules = [module])
9edeeb
diff -up pip-19.3.1/tests/functional/test_wheel.py.pip7873 pip-19.3.1/tests/functional/test_wheel.py
9edeeb
--- pip-19.3.1/tests/functional/test_wheel.py.pip7873	2019-10-17 13:32:34.000000000 -0600
9edeeb
+++ pip-19.3.1/tests/functional/test_wheel.py	2022-05-24 08:34:03.285054864 -0600
9edeeb
@@ -1,6 +1,7 @@
9edeeb
 """'pip wheel' tests"""
9edeeb
 import os
9edeeb
 import re
9edeeb
+import sys
9edeeb
 from os.path import exists
9edeeb
 
9edeeb
 import pytest
9edeeb
@@ -228,6 +229,24 @@ def test_pip_wheel_with_user_set_in_conf
9edeeb
     assert "Successfully built withpyproject" in result.stdout, result.stdout
9edeeb
 
9edeeb
 
9edeeb
+@pytest.mark.skipif(sys.platform.startswith('win'),
9edeeb
+                    reason='The empty extension module does not work on Win')
9edeeb
+def test_pip_wheel_ext_module_with_tmpdir_inside(script, data, common_wheels):
9edeeb
+    tmpdir = data.src / 'extension/tmp'
9edeeb
+    tmpdir.mkdir()
9edeeb
+    script.environ['TMPDIR'] = str(tmpdir)
9edeeb
+
9edeeb
+    # To avoid a test dependency on a C compiler, we set the env vars to "noop"
9edeeb
+    # The .c source is empty anyway
9edeeb
+    script.environ['CC'] = script.environ['LDSHARED'] = str('true')
9edeeb
+
9edeeb
+    result = script.pip(
9edeeb
+        'wheel', data.src / 'extension',
9edeeb
+        '--no-index', '-f', common_wheels
9edeeb
+    )
9edeeb
+    assert "Successfully built extension" in result.stdout, result.stdout
9edeeb
+
9edeeb
+
9edeeb
 @pytest.mark.network
9edeeb
 def test_pep517_wheels_are_not_confused_with_other_files(script, tmpdir, data):
9edeeb
     """Check correct wheels are copied. (#6196)