From e08035e1c159e28c2ce0e980c896fc2aefc42cd3 Mon Sep 17 00:00:00 2001 From: Ashley Anderson Date: Wed, 27 Apr 2022 19:44:48 -0400 Subject: [PATCH] Update API for 'replace_needed' to accept multiple so-name replacement pairs (based on review). --- src/auditwheel/patcher.py | 18 ++++-------------- src/auditwheel/repair.py | 4 ++-- tests/unit/test_elfpatcher.py | 8 ++++---- 3 files changed, 10 insertions(+), 20 deletions(-) diff --git a/src/auditwheel/patcher.py b/src/auditwheel/patcher.py index 135a0a13..bc797ec6 100644 --- a/src/auditwheel/patcher.py +++ b/src/auditwheel/patcher.py @@ -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: @@ -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, ] diff --git a/src/auditwheel/repair.py b/src/auditwheel/repair.py index 91e160b9..4edb6250 100644 --- a/src/auditwheel/repair.py +++ b/src/auditwheel/repair.py @@ -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)) @@ -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])) diff --git a/tests/unit/test_elfpatcher.py b/tests/unit/test_elfpatcher.py index 83abf4ab..62f10d8b 100644 --- a/tests/unit/test_elfpatcher.py +++ b/tests/unit/test_elfpatcher.py @@ -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",