Skip to content

Commit

Permalink
Support to wildcard a path with --exclude (#528)
Browse files Browse the repository at this point in the history
  • Loading branch information
oraluben authored Feb 1, 2025
1 parent 64197a9 commit 5276a7b
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 6 deletions.
15 changes: 13 additions & 2 deletions src/auditwheel/lddtree.py
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,7 @@ def lddtree(
libs: list[str] = []
rpaths: list[str] = []
runpaths: list[str] = []
_excluded_libs: set[str] = set()
for segment in elf.iter_segments():
if segment.header.p_type != "PT_DYNAMIC":
continue
Expand All @@ -396,8 +397,11 @@ def lddtree(
elif t.entry.d_tag == "DT_RUNPATH":
runpaths = parse_ld_paths(t.runpath, path=path, root=root)
elif t.entry.d_tag == "DT_NEEDED":
if any(fnmatch(t.needed, e) for e in exclude):
if t.needed in _excluded_libs or any(
fnmatch(t.needed, e) for e in exclude
):
log.info("Excluding %s", t.needed)
_excluded_libs.add(t.needed)
else:
libs.append(t.needed)
if runpaths:
Expand All @@ -416,7 +420,6 @@ def lddtree(
log.debug(" ldpaths[runpath] = %s", runpaths)
ret["rpath"] = rpaths
ret["runpath"] = runpaths
ret["needed"] = libs

# Search for the libs this ELF uses.
all_ldpaths: list[str] | None = None
Expand All @@ -434,6 +437,12 @@ def lddtree(
+ ldpaths["interp"]
)
realpath, fullpath = find_lib(elf, lib, all_ldpaths, root)
if lib in _excluded_libs or (
realpath is not None and any(fnmatch(realpath, e) for e in exclude)
):
log.info("Excluding %s", realpath)
_excluded_libs.add(lib)
continue
_all_libs[lib] = {
"realpath": realpath,
"path": fullpath,
Expand All @@ -453,4 +462,6 @@ def lddtree(

del elf

ret["needed"] = [lib for lib in libs if lib not in _excluded_libs]

return ret
Binary file added tests/integration/libffi.so.5
Binary file not shown.
30 changes: 26 additions & 4 deletions tests/integration/test_bundled_wheels.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
from __future__ import annotations

import importlib
import os
import platform
import subprocess
import sys
import zipfile
from argparse import Namespace
from datetime import datetime, timezone
from os.path import isabs
from pathlib import Path
from unittest import mock
from unittest.mock import Mock

import pytest

from auditwheel import main_repair
from auditwheel import lddtree, main_repair
from auditwheel.libc import Libc
from auditwheel.policy import WheelPolicies
from auditwheel.wheel_abi import analyze_wheel_abi
Expand Down Expand Up @@ -40,6 +43,11 @@
{"libffi.so.5"},
frozenset(["libffi.so.[6,7]"]),
),
(
"cffi-1.5.0-cp27-none-linux_x86_64.whl",
set(),
frozenset([f"{HERE}/*"]),
),
("cffi-1.5.0-cp27-none-linux_x86_64.whl", set(), frozenset(["libffi.so.*"])),
("cffi-1.5.0-cp27-none-linux_x86_64.whl", set(), frozenset(["*"])),
(
Expand All @@ -50,9 +58,23 @@
],
)
def test_analyze_wheel_abi(file, external_libs, exclude):
wheel_policies = WheelPolicies(libc=Libc.GLIBC, arch="x86_64")
winfo = analyze_wheel_abi(wheel_policies, str(HERE / file), exclude)
assert set(winfo.external_refs["manylinux_2_5_x86_64"]["libs"]) == external_libs
# If exclude libs contain path, LD_LIBRARY_PATH need to be modified to find the libs
# `lddtree.load_ld_paths` needs to be reloaded for it's `lru_cache`-ed.
modify_ld_library_path = any(isabs(e) for e in exclude)

with pytest.MonkeyPatch.context() as cp:
if modify_ld_library_path:
cp.setenv("LD_LIBRARY_PATH", f"{HERE}")
importlib.reload(lddtree)

wheel_policies = WheelPolicies(libc=Libc.GLIBC, arch="x86_64")
winfo = analyze_wheel_abi(wheel_policies, str(HERE / file), exclude)
assert (
set(winfo.external_refs["manylinux_2_5_x86_64"]["libs"]) == external_libs
), f"{HERE}, {exclude}, {os.environ}"

if modify_ld_library_path:
importlib.reload(lddtree)


def test_analyze_wheel_abi_pyfpe():
Expand Down

0 comments on commit 5276a7b

Please sign in to comment.