From 867cda8ee8d60b8d2b63ec2947451a7b09276cc1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Filipe=20La=C3=ADns?= Date: Wed, 8 Jan 2025 19:53:27 +0000 Subject: [PATCH 1/7] GH-128469: warn when libpython was loaded from outside the build directory MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Filipe Laíns Date: Sat, 11 Jan 2025 01:13:04 +0000 Subject: [PATCH 2/7] Update Modules/getpath.py Co-authored-by: Peter Bierma --- Modules/getpath.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Modules/getpath.py b/Modules/getpath.py index 673b04fa712041..a8f3b7565123bd 100644 --- a/Modules/getpath.py +++ b/Modules/getpath.py @@ -789,7 +789,7 @@ def search_up(prefix, *landmarks, test=isfile): # When running Python from the build directory, if libpython is dynamically # linked, the wrong library might be loaded. -if build_prefix and not build_prefix.startswith(dirname(abspath(library))): +if build_prefix and library and not build_prefix.startswith(dirname(abspath(library))): msg = f'The runtime library has been loaded from outside the build directory ({library})!' if os_name == 'posix': msg += ' Consider setting LD_LIBRARY_PATH=. to force it to be loaded from the build directory.' From bf40c1703f8756dbb6c8dad8c9e684aadc8e7b9e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Filipe=20La=C3=ADns?= Date: Sat, 11 Jan 2025 03:44:15 +0000 Subject: [PATCH 3/7] Fix check MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Filipe Laíns Date: Sat, 11 Jan 2025 04:17:36 +0000 Subject: [PATCH 4/7] Add test MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Filipe Laíns Date: Sat, 11 Jan 2025 04:27:17 +0000 Subject: [PATCH 5/7] Fix test availability MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Filipe Laíns Date: Sat, 11 Jan 2025 04:31:22 +0000 Subject: [PATCH 6/7] Make test availability a bit stricter MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Filipe Laíns Date: Wed, 29 Jan 2025 22:11:51 +0000 Subject: [PATCH 7/7] Fix test without --enable-dynamic MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Filipe Laíns --- Lib/test/test_getpath.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Lib/test/test_getpath.py b/Lib/test/test_getpath.py index e747e2b9c312f1..ca7cee0c39872a 100644 --- a/Lib/test/test_getpath.py +++ b/Lib/test/test_getpath.py @@ -880,6 +880,10 @@ class RealGetPathTests(unittest.TestCase): any(sys.platform.startswith(p) for p in ('linux', 'freebsd', 'centos')), 'Test only support on Linux-like OS-es (support LD_LIBRARY_PATH)', ) + @unittest.skipUnless( + sysconfig.get_config_var('LDLIBRARY') != sysconfig.get_config_var('LIBRARY'), + 'Test only available when using a dynamic libpython', + ) def test_builddir_wrong_library_warning(self): library_name = sysconfig.get_config_var('INSTSONAME') with tempfile.TemporaryDirectory() as tmpdir: