diff --git a/src/auditwheel/lddtree.py b/src/auditwheel/lddtree.py index 44785791..661446a4 100644 --- a/src/auditwheel/lddtree.py +++ b/src/auditwheel/lddtree.py @@ -321,8 +321,17 @@ def load_ld_paths( """ ldpaths: dict[str, list[str]] = {"conf": [], "env": [], "interp": []} - # Load up $LD_LIBRARY_PATH. - env_ldpath = os.environ.get("LD_LIBRARY_PATH") + # Load up $AUDITWHEEL_LD_LIBRARY_PATH and $LD_LIBRARY_PATH + env_ldpath = ":".join( + filter( + None, + ( + os.environ.get("AUDITWHEEL_LD_LIBRARY_PATH"), + os.environ.get("LD_LIBRARY_PATH"), + ), + ) + ) + if env_ldpath is not None: if root != "/": log.warning("ignoring LD_LIBRARY_PATH due to ROOT usage") diff --git a/tests/integration/test_bundled_wheels.py b/tests/integration/test_bundled_wheels.py index 046b8fc0..97f12487 100644 --- a/tests/integration/test_bundled_wheels.py +++ b/tests/integration/test_bundled_wheels.py @@ -1,18 +1,17 @@ from __future__ import annotations import importlib -import os import platform import sys import zipfile from argparse import Namespace from datetime import datetime, timezone -from os.path import isabs from pathlib import Path from unittest.mock import Mock import pytest +import auditwheel.wheel_abi from auditwheel import lddtree, main_repair from auditwheel.architecture import Architecture from auditwheel.libc import Libc @@ -23,70 +22,90 @@ @pytest.mark.parametrize( - ("file", "external_libs", "exclude"), + ("file", "external_libs", "exclude", "env"), [ ( "cffi-1.5.0-cp27-none-linux_x86_64.whl", {"libffi.so.5", "libpython2.7.so.1.0"}, frozenset(), + None, ), ( "cffi-1.5.0-cp27-none-linux_x86_64.whl", set(), frozenset(["libffi.so.5", "libpython2.7.so.1.0"]), + None, ), ( "cffi-1.5.0-cp27-none-linux_x86_64.whl", {"libffi.so.5", "libpython2.7.so.1.0"}, frozenset(["libffi.so.noexist", "libnoexist.so.*"]), + None, ), ( "cffi-1.5.0-cp27-none-linux_x86_64.whl", {"libpython2.7.so.1.0"}, frozenset(["libffi.so.[4,5]"]), + None, ), ( "cffi-1.5.0-cp27-none-linux_x86_64.whl", {"libffi.so.5", "libpython2.7.so.1.0"}, frozenset(["libffi.so.[6,7]"]), + None, ), ( "cffi-1.5.0-cp27-none-linux_x86_64.whl", {"libpython2.7.so.1.0"}, frozenset([f"{HERE}/*"]), + "LD_LIBRARY_PATH", + ), + ( + "cffi-1.5.0-cp27-none-linux_x86_64.whl", + {"libpython2.7.so.1.0"}, + frozenset([f"{HERE}/*"]), + "AUDITWHEEL_LD_LIBRARY_PATH", + ), + ( + "cffi-1.5.0-cp27-none-linux_x86_64.whl", + {"libffi.so.5", "libpython2.7.so.1.0"}, + frozenset([f"{HERE}/*"]), + None, ), ( "cffi-1.5.0-cp27-none-linux_x86_64.whl", {"libpython2.7.so.1.0"}, frozenset(["libffi.so.*"]), + None, ), - ("cffi-1.5.0-cp27-none-linux_x86_64.whl", set(), frozenset(["*"])), + ("cffi-1.5.0-cp27-none-linux_x86_64.whl", set(), frozenset(["*"]), None), ( "python_snappy-0.5.2-pp260-pypy_41-linux_x86_64.whl", {"libsnappy.so.1"}, frozenset(), + None, ), ], ) -def test_analyze_wheel_abi(file, external_libs, exclude): +def test_analyze_wheel_abi(file, external_libs, exclude, env): # 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) + if env: + cp.setenv(env, f"{HERE}") + importlib.reload(lddtree) + importlib.reload(auditwheel.wheel_abi) winfo = analyze_wheel_abi( Libc.GLIBC, Architecture.x86_64, HERE / file, exclude, False, True ) assert set(winfo.external_refs["manylinux_2_5_x86_64"].libs) == external_libs, ( - f"{HERE}, {exclude}, {os.environ}" + f"{HERE}, {exclude}, {env}" ) - if modify_ld_library_path: - importlib.reload(lddtree) + importlib.reload(lddtree) + importlib.reload(auditwheel.wheel_abi) def test_analyze_wheel_abi_pyfpe():