diff --git a/auditwheel/main_repair.py b/auditwheel/main_repair.py index 0f357cf6..d7f50a64 100644 --- a/auditwheel/main_repair.py +++ b/auditwheel/main_repair.py @@ -65,6 +65,12 @@ def configure_parser(sub_parsers): action='store_true', help='Strip symbols in the resulting wheel', default=False) + p.add_argument('--include', + dest='INCLUDE', + help='Only include these libraries') + p.add_argument('--exclude', + dest='EXCLUDE', + help='Exclude these libraries') p.add_argument('--only-plat', dest='ONLY_PLAT', action='store_true', @@ -126,7 +132,10 @@ def execute(args, p): out_dir=args.WHEEL_DIR, update_tags=args.UPDATE_TAGS, patcher=patcher, - strip=args.STRIP) + strip=args.STRIP, + include=(args.INCLUDE or '').split(','), + exclude=(args.EXCLUDE or '').split(','), + ) if out_wheel is not None: logger.info('\nFixed-up wheel written to %s', out_wheel) diff --git a/auditwheel/repair.py b/auditwheel/repair.py index 17bcf1fb..69848b8f 100644 --- a/auditwheel/repair.py +++ b/auditwheel/repair.py @@ -28,9 +28,23 @@ re.VERBOSE).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 _filter(items: Optional[List[str]]) -> List[str]: + return [_.strip() for _ in (items or []) if _.strip()] + + def repair_wheel(wheel_path: str, abis: List[str], lib_sdir: str, out_dir: str, update_tags: bool, patcher: ElfPatcher, - strip: bool = False) -> Optional[str]: + strip: bool = False, + include: Optional[List[str]] = None, + exclude: Optional[List[str]] = None, + ) -> Optional[str]: external_refs_by_fn = get_wheel_elfdata(wheel_path)[1] @@ -44,6 +58,10 @@ def repair_wheel(wheel_path: str, abis: List[str], lib_sdir: str, out_dir: str, wheel_fname = basename(wheel_path) + # Remove empty strings in include/exclude list + include = _filter(include) + exclude = _filter(exclude) + with InWheelCtx(wheel_path) as ctx: ctx.out_wheel = pjoin(out_dir, wheel_fname) @@ -68,6 +86,20 @@ def repair_wheel(wheel_path: str, abis: List[str], lib_sdir: str, out_dir: str, 'library "%s" could not be located') % soname) + # exhaustive include list + if include and not _is_in_list(soname, include): + logger.debug( + f'Excluding {soname} which is not in exhaustive ' + f'include list `{", ".join(include)}`)') + continue + + # 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)