Skip to content

Commit e5e3cc1

Browse files
authored
Merge pull request pypa#247 from pypa/hotfix/246-linker-args-list
Wrap linker arg handling to restore prior expectation.
2 parents a04913a + ef297f2 commit e5e3cc1

File tree

5 files changed

+53
-10
lines changed

5 files changed

+53
-10
lines changed

.coveragerc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
omit =
33
# leading `*/` for pytest-dev/pytest-cov#456
44
*/.tox/*
5+
6+
# local
7+
*/compat/*
58
disable_warnings =
69
couldnt-parse
710

distutils/compat/__init__.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
from __future__ import annotations
2+
3+
from .py38 import removeprefix
4+
5+
6+
def consolidate_linker_args(args: list[str]) -> str:
7+
"""
8+
Ensure the return value is a string for backward compatibility.
9+
10+
Retain until at least 2024-04-31. See pypa/distutils#246
11+
"""
12+
13+
if not all(arg.startswith('-Wl,') for arg in args):
14+
return args
15+
return '-Wl,' + ','.join(removeprefix(arg, '-Wl,') for arg in args)

distutils/compat/py38.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import sys
2+
3+
if sys.version_info < (3, 9):
4+
5+
def removesuffix(self, suffix):
6+
# suffix='' should not call self[:-0].
7+
if suffix and self.endswith(suffix):
8+
return self[: -len(suffix)]
9+
else:
10+
return self[:]
11+
12+
def removeprefix(self, prefix):
13+
if self.startswith(prefix):
14+
return self[len(prefix) :]
15+
else:
16+
return self[:]
17+
else:
18+
19+
def removesuffix(self, suffix):
20+
return self.removesuffix(suffix)
21+
22+
def removeprefix(self, prefix):
23+
return self.removeprefix(prefix)

distutils/tests/test_unixccompiler.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import sys
55
import unittest.mock as mock
66
from distutils import sysconfig
7+
from distutils.compat import consolidate_linker_args
78
from distutils.errors import DistutilsPlatformError
89
from distutils.unixccompiler import UnixCCompiler
910
from distutils.util import _clear_cached_macosx_ver
@@ -149,10 +150,10 @@ def gcv(v):
149150
return 'yes'
150151

151152
sysconfig.get_config_var = gcv
152-
assert self.cc.rpath_foo() == [
153+
assert self.cc.rpath_foo() == consolidate_linker_args([
153154
'-Wl,--enable-new-dtags',
154155
'-Wl,-rpath,/foo',
155-
]
156+
])
156157

157158
def gcv(v):
158159
if v == 'CC':
@@ -161,10 +162,10 @@ def gcv(v):
161162
return 'yes'
162163

163164
sysconfig.get_config_var = gcv
164-
assert self.cc.rpath_foo() == [
165+
assert self.cc.rpath_foo() == consolidate_linker_args([
165166
'-Wl,--enable-new-dtags',
166167
'-Wl,-rpath,/foo',
167-
]
168+
])
168169

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

191192
sysconfig.get_config_var = gcv
192-
assert self.cc.rpath_foo() == [
193+
assert self.cc.rpath_foo() == consolidate_linker_args([
193194
'-Wl,--enable-new-dtags',
194195
'-Wl,-rpath,/foo',
195-
]
196+
])
196197

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

206207
sysconfig.get_config_var = gcv
207-
assert self.cc.rpath_foo() == [
208+
assert self.cc.rpath_foo() == consolidate_linker_args([
208209
'-Wl,--enable-new-dtags',
209210
'-Wl,-rpath,/foo',
210-
]
211+
])
211212

212213
# non-GCC non-GNULD
213214
sys.platform = 'bar'

distutils/unixccompiler.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import sys
2323

2424
from . import sysconfig
25+
from .compat import consolidate_linker_args
2526
from ._log import log
2627
from ._macos_compat import compiler_fixup
2728
from ._modified import newer
@@ -315,11 +316,11 @@ def runtime_library_dir_option(self, dir: str) -> str | list[str]:
315316
# For all compilers, `-Wl` is the presumed way to pass a
316317
# compiler option to the linker
317318
if sysconfig.get_config_var("GNULD") == "yes":
318-
return [
319+
return consolidate_linker_args([
319320
# Force RUNPATH instead of RPATH
320321
"-Wl,--enable-new-dtags",
321322
"-Wl,-rpath," + dir,
322-
]
323+
])
323324
else:
324325
return "-Wl,-R" + dir
325326

0 commit comments

Comments
 (0)