Skip to content

Commit 5245403

Browse files
committed
gh-78292: Improve python-config build script to respect symbolic link.
Signed-off-by: Farhaan Bukhsh <farhaan.bukhsh@gmail.com>
1 parent 82905dd commit 5245403

2 files changed

Lines changed: 42 additions & 1 deletion

File tree

Lib/test/test_sysconfig.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import json
99
import textwrap
1010
from unittest.mock import patch
11+
import tempfile
1112
from copy import copy
1213

1314
from test import support
@@ -760,6 +761,46 @@ def test_sysconfig_config_vars_no_prefix_cache(self):
760761
self.assertEqual(config_vars['exec_prefix'], sys.exec_prefix)
761762
self.assertEqual(config_vars['platbase'], sys.exec_prefix)
762763

764+
@unittest.skipUnless(
765+
os.name == "posix" and sys.platform != "darwin",
766+
"requires shell python-config",
767+
)
768+
@skip_unless_symlink
769+
@requires_subprocess()
770+
def test_python_config_symlink(self):
771+
if not is_python_build():
772+
self.skipTest("requires a CPython build directory")
773+
774+
python_config = os.path.join(_PROJECT_BASE, "python-config")
775+
if not os.path.isfile(python_config):
776+
self.skipTest("python-config was not built")
777+
778+
with tempfile.TemporaryDirectory() as tmpdir:
779+
real_prefix = os.path.join(tmpdir, "real")
780+
real_bindir = os.path.join(real_prefix, "bin")
781+
os.makedirs(real_bindir)
782+
783+
real_config = os.path.join(real_bindir, "python-config")
784+
shutil.copyfile(python_config, real_config)
785+
786+
link_prefix = os.path.join(tmpdir, "link")
787+
link_bindir = os.path.join(link_prefix, "bin")
788+
os.makedirs(link_bindir)
789+
790+
linked_config = os.path.join(link_bindir, "python-config")
791+
os.symlink(real_config, linked_config)
792+
793+
def get_prefix(config):
794+
return subprocess.check_output(
795+
["/bin/sh", config, "--prefix"],
796+
text=True,
797+
).strip()
798+
799+
expected = os.path.realpath(real_prefix)
800+
801+
self.assertEqual(get_prefix(real_config), expected)
802+
self.assertEqual(get_prefix(linked_config), expected)
803+
763804

764805
class MakefileTests(unittest.TestCase):
765806

Misc/python-config.sh.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ fi
2121
# Returns the actual prefix where this script was installed to.
2222
installed_prefix ()
2323
{
24-
RESULT=$(dirname $(cd $(dirname "$1") && pwd -P))
24+
RESULT=$(dirname $(cd $(dirname $(realpath "$1")) && pwd -P))
2525
if which readlink >/dev/null 2>&1 ; then
2626
if readlink -f "$RESULT" >/dev/null 2>&1; then
2727
RESULT=$(readlink -f "$RESULT")

0 commit comments

Comments
 (0)