Skip to content

Commit

Permalink
Update API for 'replace_needed' to accept multiple so-name replacemen…
Browse files Browse the repository at this point in the history
…t pairs (based on review).
  • Loading branch information
Ashley Anderson committed Apr 27, 2022
1 parent cb938b5 commit e08035e
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 20 deletions.
18 changes: 4 additions & 14 deletions src/auditwheel/patcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,11 @@
from distutils.spawn import find_executable
from itertools import chain
from subprocess import CalledProcessError, check_call, check_output
from typing import Iterable, Tuple
from typing import Tuple


class ElfPatcher:
def replace_needed(self, file_name: str, so_name: str, new_so_name: str) -> None:
raise NotImplementedError

def replace_needed_multiple(
self, file_name: str, so_name_pairs: Iterable[Tuple[str, str]]
) -> None:
def replace_needed(self, file_name: str, *old_new_pairs: Tuple[str, str]) -> None:
raise NotImplementedError

def set_soname(self, file_name: str, new_so_name: str) -> None:
Expand Down Expand Up @@ -48,17 +43,12 @@ class Patchelf(ElfPatcher):
def __init__(self) -> None:
_verify_patchelf()

def replace_needed(self, file_name: str, so_name: str, new_so_name: str) -> None:
check_call(["patchelf", "--replace-needed", so_name, new_so_name, file_name])

def replace_needed_multiple(
self, file_name: str, so_name_pairs: Iterable[Tuple[str, str]]
) -> None:
def replace_needed(self, file_name: str, *old_new_pairs: Tuple[str, str]) -> None:
check_call(
[
"patchelf",
*chain.from_iterable(
("--replace-needed", *pair) for pair in so_name_pairs
("--replace-needed", *pair) for pair in old_new_pairs
),
file_name,
]
Expand Down
4 changes: 2 additions & 2 deletions src/auditwheel/repair.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def repair_wheel(
soname_map[soname] = (new_soname, new_path)
replacements.append((soname, new_soname))
if replacements:
patcher.replace_needed_multiple(fn, replacements)
patcher.replace_needed(fn, *replacements)

if len(ext_libs) > 0:
new_rpath = os.path.relpath(dest_dir, os.path.dirname(fn))
Expand All @@ -101,7 +101,7 @@ def repair_wheel(
if n in soname_map:
replacements.append((n, soname_map[n][0]))
if replacements:
patcher.replace_needed_multiple(path, replacements)
patcher.replace_needed(path, *replacements)

if update_tags:
ctx.out_wheel = add_platforms(ctx, abis, get_replace_platforms(abis[0]))
Expand Down
8 changes: 4 additions & 4 deletions tests/unit/test_elfpatcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,24 +41,24 @@ def test_patchelf_version_check_fail(check_output, version):
class TestPatchElf:
""" "Validate that patchelf is invoked with the correct arguments."""

def test_replace_needed(self, check_call, _0, _1):
def test_replace_needed_one(self, check_call, _0, _1):
patcher = Patchelf()
filename = "test.so"
soname_old = "TEST_OLD"
soname_new = "TEST_NEW"
patcher.replace_needed(filename, soname_old, soname_new)
patcher.replace_needed(filename, (soname_old, soname_new))
check_call.assert_called_once_with(
["patchelf", "--replace-needed", soname_old, soname_new, filename]
)

def test_replace_needed_multiple(self, check_call, _0, _1):
def test_replace_needed_multple(self, check_call, _0, _1):
patcher = Patchelf()
filename = "test.so"
replacements = [
("TEST_OLD1", "TEST_NEW1"),
("TEST_OLD2", "TEST_NEW2"),
]
patcher.replace_needed_multiple(filename, replacements)
patcher.replace_needed(filename, *replacements)
check_call.assert_called_once_with(
[
"patchelf",
Expand Down

0 comments on commit e08035e

Please sign in to comment.