From e5c4598f8e8f74f54ca081eba1a8e39013d01dab Mon Sep 17 00:00:00 2001 From: Sean Gillies Date: Tue, 30 Jul 2024 09:27:50 -0600 Subject: [PATCH 1/4] Implement extra lib name tag on top of latest auditwheel --- src/auditwheel/main_repair.py | 8 ++++++++ src/auditwheel/repair.py | 12 ++++++++++-- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/auditwheel/main_repair.py b/src/auditwheel/main_repair.py index 4374f208..5d159b03 100644 --- a/src/auditwheel/main_repair.py +++ b/src/auditwheel/main_repair.py @@ -2,6 +2,7 @@ import argparse import logging +import os from os.path import abspath, basename, exists, isfile from auditwheel.patcher import Patchelf @@ -100,6 +101,12 @@ def configure_parser(sub_parsers): help="Do not check for higher policy compatibility", default=False, ) + p.add_argument( + "--extra-lib-name-tag", + dest="EXTRA_LIB_NAME_TAG", + help="Extra, optional tag for copied library names", + default=os.environ.get("AUDITWHEEL_EXTRA_LIB_NAME_TAG", None), + ) p.set_defaults(func=execute) @@ -180,6 +187,7 @@ def execute(args, p): patcher=patcher, exclude=exclude, strip=args.STRIP, + extra_lib_name_tag=args.EXTRA_LIB_NAME_TAG, ) if out_wheel is not None: diff --git a/src/auditwheel/repair.py b/src/auditwheel/repair.py index 85e3ca39..b294f36e 100644 --- a/src/auditwheel/repair.py +++ b/src/auditwheel/repair.py @@ -42,6 +42,7 @@ def repair_wheel( patcher: ElfPatcher, exclude: frozenset[str], strip: bool = False, + extra_lib_name_tag: str = None, ) -> str | None: external_refs_by_fn = get_wheel_elfdata(wheel_policy, wheel_path, exclude)[1] @@ -83,7 +84,9 @@ def repair_wheel( if not exists(dest_dir): os.mkdir(dest_dir) - new_soname, new_path = copylib(src_path, dest_dir, patcher) + new_soname, new_path = copylib( + src_path, dest_dir, patcher, extra_lib_name_tag=extra_lib_name_tag + ) soname_map[soname] = (new_soname, new_path) replacements.append((soname, new_soname)) if replacements: @@ -127,7 +130,9 @@ def strip_symbols(libraries: Iterable[str]) -> None: check_call(["strip", "-s", lib]) -def copylib(src_path: str, dest_dir: str, patcher: ElfPatcher) -> tuple[str, str]: +def copylib( + src_path: str, dest_dir: str, patcher: ElfPatcher, extra_lib_name_tag: str = None +) -> tuple[str, str]: """Graft a shared library from the system into the wheel and update the relevant links. @@ -143,6 +148,9 @@ def copylib(src_path: str, dest_dir: str, patcher: ElfPatcher) -> tuple[str, str with open(src_path, "rb") as f: shorthash = hashfile(f)[:8] + if extra_lib_name_tag: + shorthash = f"{extra_lib_name_tag}-{shorthash}" + src_name = os.path.basename(src_path) base, ext = src_name.split(".", 1) if not base.endswith("-%s" % shorthash): From 885666308e0a463c2fa6b8ad2a79328eee5388e4 Mon Sep 17 00:00:00 2001 From: Sean Gillies Date: Tue, 30 Jul 2024 09:43:51 -0600 Subject: [PATCH 2/4] Use Optional[str] type hint --- src/auditwheel/repair.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/auditwheel/repair.py b/src/auditwheel/repair.py index b294f36e..c1aea4d0 100644 --- a/src/auditwheel/repair.py +++ b/src/auditwheel/repair.py @@ -11,7 +11,7 @@ from os.path import join as pjoin from pathlib import Path from subprocess import check_call -from typing import Iterable +from typing import Iterable, Optional from auditwheel.patcher import ElfPatcher @@ -42,7 +42,7 @@ def repair_wheel( patcher: ElfPatcher, exclude: frozenset[str], strip: bool = False, - extra_lib_name_tag: str = None, + extra_lib_name_tag: Optional[str] = None, ) -> str | None: external_refs_by_fn = get_wheel_elfdata(wheel_policy, wheel_path, exclude)[1] @@ -131,7 +131,7 @@ def strip_symbols(libraries: Iterable[str]) -> None: def copylib( - src_path: str, dest_dir: str, patcher: ElfPatcher, extra_lib_name_tag: str = None + src_path: str, dest_dir: str, patcher: ElfPatcher, extra_lib_name_tag: Optional[str] = None ) -> tuple[str, str]: """Graft a shared library from the system into the wheel and update the relevant links. From f39ec665644c1230fa3cd3eb81360421b8b98c7b Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 30 Jul 2024 15:45:35 +0000 Subject: [PATCH 3/4] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- src/auditwheel/repair.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/auditwheel/repair.py b/src/auditwheel/repair.py index c1aea4d0..6ebc631c 100644 --- a/src/auditwheel/repair.py +++ b/src/auditwheel/repair.py @@ -42,7 +42,7 @@ def repair_wheel( patcher: ElfPatcher, exclude: frozenset[str], strip: bool = False, - extra_lib_name_tag: Optional[str] = None, + extra_lib_name_tag: str | None = None, ) -> str | None: external_refs_by_fn = get_wheel_elfdata(wheel_policy, wheel_path, exclude)[1] @@ -131,7 +131,10 @@ def strip_symbols(libraries: Iterable[str]) -> None: def copylib( - src_path: str, dest_dir: str, patcher: ElfPatcher, extra_lib_name_tag: Optional[str] = None + src_path: str, + dest_dir: str, + patcher: ElfPatcher, + extra_lib_name_tag: str | None = None, ) -> tuple[str, str]: """Graft a shared library from the system into the wheel and update the relevant links. From d8aa814451c20081ed9d6c8fdd19b6b8a400939e Mon Sep 17 00:00:00 2001 From: Sean Gillies Date: Tue, 30 Jul 2024 09:50:27 -0600 Subject: [PATCH 4/4] Appease flake8 --- src/auditwheel/repair.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/auditwheel/repair.py b/src/auditwheel/repair.py index 6ebc631c..103930a1 100644 --- a/src/auditwheel/repair.py +++ b/src/auditwheel/repair.py @@ -11,7 +11,7 @@ from os.path import join as pjoin from pathlib import Path from subprocess import check_call -from typing import Iterable, Optional +from typing import Iterable from auditwheel.patcher import ElfPatcher