Skip to content

Commit

Permalink
Merge pull request #247 from pypa/hotfix/246-linker-args-list
Browse files Browse the repository at this point in the history
Wrap linker arg handling to restore prior expectation.
  • Loading branch information
jaraco committed Jun 28, 2024
2 parents 9eaea6a + e74608b commit b3406ca
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 10 deletions.
3 changes: 3 additions & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
omit =
# leading `*/` for pytest-dev/pytest-cov#456
*/.tox/*

# local
*/compat/*
disable_warnings =
couldnt-parse

Expand Down
15 changes: 15 additions & 0 deletions distutils/compat/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from __future__ import annotations

from .py38 import removeprefix


def consolidate_linker_args(args: list[str]) -> str:
"""
Ensure the return value is a string for backward compatibility.
Retain until at least 2024-04-31. See pypa/distutils#246
"""

if not all(arg.startswith('-Wl,') for arg in args):
return args
return '-Wl,' + ','.join(removeprefix(arg, '-Wl,') for arg in args)
23 changes: 23 additions & 0 deletions distutils/compat/py38.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import sys

if sys.version_info < (3, 9):

def removesuffix(self, suffix):
# suffix='' should not call self[:-0].
if suffix and self.endswith(suffix):
return self[: -len(suffix)]
else:
return self[:]

def removeprefix(self, prefix):
if self.startswith(prefix):
return self[len(prefix) :]
else:
return self[:]
else:

def removesuffix(self, suffix):
return self.removesuffix(suffix)

def removeprefix(self, prefix):
return self.removeprefix(prefix)
17 changes: 9 additions & 8 deletions distutils/tests/test_unixccompiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import sys
import unittest.mock as mock
from distutils import sysconfig
from distutils.compat import consolidate_linker_args
from distutils.errors import DistutilsPlatformError
from distutils.unixccompiler import UnixCCompiler
from distutils.util import _clear_cached_macosx_ver
Expand Down Expand Up @@ -149,10 +150,10 @@ def gcv(v):
return 'yes'

sysconfig.get_config_var = gcv
assert self.cc.rpath_foo() == [
assert self.cc.rpath_foo() == consolidate_linker_args([
'-Wl,--enable-new-dtags',
'-Wl,-rpath,/foo',
]
])

def gcv(v):
if v == 'CC':
Expand All @@ -161,10 +162,10 @@ def gcv(v):
return 'yes'

sysconfig.get_config_var = gcv
assert self.cc.rpath_foo() == [
assert self.cc.rpath_foo() == consolidate_linker_args([
'-Wl,--enable-new-dtags',
'-Wl,-rpath,/foo',
]
])

# GCC non-GNULD
sys.platform = 'bar'
Expand All @@ -189,10 +190,10 @@ def gcv(v):
return 'yes'

sysconfig.get_config_var = gcv
assert self.cc.rpath_foo() == [
assert self.cc.rpath_foo() == consolidate_linker_args([
'-Wl,--enable-new-dtags',
'-Wl,-rpath,/foo',
]
])

# non-GCC GNULD
sys.platform = 'bar'
Expand All @@ -204,10 +205,10 @@ def gcv(v):
return 'yes'

sysconfig.get_config_var = gcv
assert self.cc.rpath_foo() == [
assert self.cc.rpath_foo() == consolidate_linker_args([
'-Wl,--enable-new-dtags',
'-Wl,-rpath,/foo',
]
])

# non-GCC non-GNULD
sys.platform = 'bar'
Expand Down
5 changes: 3 additions & 2 deletions distutils/unixccompiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import sys

from . import sysconfig
from .compat import consolidate_linker_args
from ._log import log
from ._macos_compat import compiler_fixup
from ._modified import newer
Expand Down Expand Up @@ -315,11 +316,11 @@ def runtime_library_dir_option(self, dir: str) -> str | list[str]:
# For all compilers, `-Wl` is the presumed way to pass a
# compiler option to the linker
if sysconfig.get_config_var("GNULD") == "yes":
return [
return consolidate_linker_args([
# Force RUNPATH instead of RPATH
"-Wl,--enable-new-dtags",
"-Wl,-rpath," + dir,
]
])
else:
return "-Wl,-R" + dir

Expand Down

0 comments on commit b3406ca

Please sign in to comment.