Skip to content

Commit dae9433

Browse files
authored
Merge pull request #255 from lkollar/strip
Add --strip option to 'repair'
2 parents 6afd879 + dc39a35 commit dae9433

File tree

6 files changed

+68
-2
lines changed

6 files changed

+68
-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.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[build-system]
2+
requires = ["setuptools >= 45.0.0", "cython"]
3+
build-backend = "setuptools.build_meta"
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
from setuptools import setup
2+
from Cython.Build import cythonize
3+
4+
setup(
5+
name="sample_extension",
6+
version="0.1.0",
7+
ext_modules=cythonize("src/sample_extension.pyx")
8+
)
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
def test_func(x):
2+
return _test_func(x)
3+
4+
cdef _test_func(x):
5+
return x + 1

tests/integration/test_manylinux.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import glob
12
from contextlib import contextmanager
23
import docker
34
from subprocess import CalledProcessError
@@ -650,3 +651,32 @@ def test_build_repair_wheel_with_internal_rpath(any_manylinux_container, docker_
650651
)
651652
for name in w.namelist()
652653
)
654+
655+
656+
def test_strip_wheel(any_manylinux_container, docker_python, io_folder):
657+
policy, manylinux_ctr = any_manylinux_container
658+
docker_exec(
659+
manylinux_ctr,
660+
['bash', '-c', 'cd /auditwheel_src/tests/integration/sample_extension '
661+
'&& python -m pip wheel --no-deps -w /io .']
662+
)
663+
664+
orig_wheel, *_ = os.listdir(io_folder)
665+
assert orig_wheel.startswith("sample_extension-0.1.0")
666+
667+
# Repair the wheel using the appropriate manylinux container
668+
repair_command = (
669+
'auditwheel repair --plat {policy} --strip -w /io /io/{orig_wheel}'
670+
).format(policy=policy, orig_wheel=orig_wheel)
671+
docker_exec(manylinux_ctr, repair_command)
672+
673+
repaired_wheel, *_ = glob.glob("{io_folder}/*{policy}*.whl".format(
674+
io_folder=io_folder, policy=policy))
675+
repaired_wheel = os.path.basename(repaired_wheel)
676+
677+
docker_exec(docker_python, "pip install /io/" + repaired_wheel)
678+
output = docker_exec(
679+
docker_python,
680+
["python", "-c", "from sample_extension import test_func; print(test_func(1))"]
681+
)
682+
assert output.strip() == "2"

0 commit comments

Comments
 (0)