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

Add option to add an extra lib name tag to wheel's short hash #503

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
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
8 changes: 8 additions & 0 deletions src/auditwheel/main_repair.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import argparse
import logging
import os
from os.path import abspath, basename, exists, isfile

from auditwheel.patcher import Patchelf
Expand Down Expand Up @@ -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)


Expand Down Expand Up @@ -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:
Expand Down
15 changes: 13 additions & 2 deletions src/auditwheel/repair.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
patcher: ElfPatcher,
exclude: frozenset[str],
strip: bool = False,
extra_lib_name_tag: str | None = None,
) -> str | None:
external_refs_by_fn = get_wheel_elfdata(wheel_policy, wheel_path, exclude)[1]

Expand Down Expand Up @@ -83,7 +84,9 @@

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:
Expand Down Expand Up @@ -127,7 +130,12 @@
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 = None,
) -> tuple[str, str]:
"""Graft a shared library from the system into the wheel and update the
relevant links.

Expand All @@ -143,6 +151,9 @@
with open(src_path, "rb") as f:
shorthash = hashfile(f)[:8]

if extra_lib_name_tag:
shorthash = f"{extra_lib_name_tag}-{shorthash}"

Check warning on line 155 in src/auditwheel/repair.py

View check run for this annotation

Codecov / codecov/patch

src/auditwheel/repair.py#L155

Added line #L155 was not covered by tests

src_name = os.path.basename(src_path)
base, ext = src_name.split(".", 1)
if not base.endswith("-%s" % shorthash):
Expand Down