From 82ef32c9658cd0d2c1d4ae7bc982641883e7f53e Mon Sep 17 00:00:00 2001 From: Cyrille Rossant Date: Sat, 5 Feb 2022 16:09:35 +0100 Subject: [PATCH] Add --exclude option This allows not including libraries like OpenGL or Vulkan which are provided by the OS --- src/auditwheel/main_repair.py | 7 +++++++ src/auditwheel/repair.py | 19 +++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/src/auditwheel/main_repair.py b/src/auditwheel/main_repair.py index c4fafa79..b6168876 100644 --- a/src/auditwheel/main_repair.py +++ b/src/auditwheel/main_repair.py @@ -85,6 +85,12 @@ def configure_parser(sub_parsers): help="Strip symbols in the resulting wheel", default=False, ) + p.add_argument( + "--exclude", + dest="EXCLUDE", + help="List of excluded sonames as a comma-separated string", + default='' + ) p.add_argument( "--only-plat", dest="ONLY_PLAT", @@ -166,6 +172,7 @@ def execute(args, p): update_tags=args.UPDATE_TAGS, patcher=patcher, strip=args.STRIP, + exclude=args.EXCLUDE.split(','), ) if out_wheel is not None: diff --git a/src/auditwheel/repair.py b/src/auditwheel/repair.py index c3386aec..ad526dc6 100644 --- a/src/auditwheel/repair.py +++ b/src/auditwheel/repair.py @@ -30,6 +30,14 @@ ).match +def _is_in_list(soname: str, items: Optional[List[str]]) -> Optional[str]: + for item in (items or []): + if item in soname: + return item + + return None + + def repair_wheel( wheel_path: str, abis: List[str], @@ -38,6 +46,7 @@ def repair_wheel( update_tags: bool, patcher: ElfPatcher, strip: bool = False, + exclude: List[str] = (), ) -> Optional[str]: external_refs_by_fn = get_wheel_elfdata(wheel_path)[1] @@ -52,6 +61,9 @@ def repair_wheel( wheel_fname = basename(wheel_path) + # Remove empty strings in exclude list + exclude = [_.strip() for _ in exclude if _.strip()] + with InWheelCtx(wheel_path) as ctx: ctx.out_wheel = pjoin(out_dir, wheel_fname) @@ -79,6 +91,13 @@ def repair_wheel( % soname ) + # exclude some libraries + exc = _is_in_list(soname, exclude) + if exc: + logger.info( + f'Excluding {soname} (match exclude string `{exc}`)') + continue + new_soname, new_path = copylib(src_path, dest_dir, patcher) soname_map[soname] = (new_soname, new_path) patcher.replace_needed(fn, soname, new_soname)