Skip to content

Commit 976cfbc

Browse files
committed
Add '--strip' option to repair
Strip dependent libraries and extension modules when passing '--strip'.
1 parent 6afd879 commit 976cfbc

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

auditwheel/main_repair.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,11 @@ def configure_parser(sub_parsers):
4242
help=('Do not update the wheel filename tags and WHEEL info'
4343
' to match the repaired platform tag.'),
4444
default=True)
45+
p.add_argument('--strip',
46+
dest='STRIP',
47+
action='store_true',
48+
help='Strip symbols in the resulting wheel',
49+
default=False)
4550
p.set_defaults(func=execute)
4651

4752

@@ -86,7 +91,8 @@ def execute(args, p):
8691
lib_sdir=args.LIB_SDIR,
8792
out_dir=args.WHEEL_DIR,
8893
update_tags=args.UPDATE_TAGS,
89-
patcher=patcher)
94+
patcher=patcher,
95+
strip=args.STRIP)
9096

9197
if out_wheel is not None:
9298
analyzed_tag = analyze_wheel_abi(out_wheel).overall_tag

auditwheel/repair.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from collections import OrderedDict
99
from os.path import exists, basename, abspath, isabs, dirname
1010
from os.path import join as pjoin
11+
from subprocess import check_call
1112
from typing import Dict, Optional, Tuple
1213

1314
from auditwheel.patcher import ElfPatcher
@@ -28,7 +29,8 @@
2829

2930

3031
def repair_wheel(wheel_path: str, abi: str, lib_sdir: str, out_dir: str,
31-
update_tags: bool, patcher: ElfPatcher) -> Optional[str]:
32+
update_tags: bool, patcher: ElfPatcher,
33+
strip: bool = False) -> Optional[str]:
3234

3335
external_refs_by_fn = get_wheel_elfdata(wheel_path)[1]
3436

@@ -88,9 +90,21 @@ def repair_wheel(wheel_path: str, abi: str, lib_sdir: str, out_dir: str,
8890
if update_tags:
8991
ctx.out_wheel = add_platforms(ctx, [abi],
9092
get_replace_platforms(abi))
93+
94+
if strip:
95+
libs_to_strip = [path for (_, path) in soname_map.values()]
96+
extensions = external_refs_by_fn.keys()
97+
strip_symbols(itertools.chain(libs_to_strip, extensions))
98+
9199
return ctx.out_wheel
92100

93101

102+
def strip_symbols(libraries):
103+
for lib in libraries:
104+
logger.info('Stripping symbols from %s', lib)
105+
check_call(['strip', '-s', lib])
106+
107+
94108
def copylib(src_path, dest_dir, patcher):
95109
"""Graft a shared library from the system into the wheel and update the
96110
relevant links.

0 commit comments

Comments
 (0)