Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrap linker arg handling to restore prior expectation. #247

Merged
merged 3 commits into from
Apr 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jaraco Just to double checking... do you really meant 2024-04-31 here? That's about just two weeks from today, not six months!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I meant 2025. Fixed in e5268b5.

"""

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
Loading