Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add --strip option to 'repair' #255

Merged
merged 2 commits into from
Jul 21, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion auditwheel/main_repair.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ def configure_parser(sub_parsers):
help=('Do not update the wheel filename tags and WHEEL info'
' to match the repaired platform tag.'),
default=True)
p.add_argument('--strip',
dest='STRIP',
action='store_true',
help='Strip symbols in the resulting wheel',
default=False)
p.set_defaults(func=execute)


Expand Down Expand Up @@ -86,7 +91,8 @@ def execute(args, p):
lib_sdir=args.LIB_SDIR,
out_dir=args.WHEEL_DIR,
update_tags=args.UPDATE_TAGS,
patcher=patcher)
patcher=patcher,
strip=args.STRIP)

if out_wheel is not None:
analyzed_tag = analyze_wheel_abi(out_wheel).overall_tag
Expand Down
16 changes: 15 additions & 1 deletion auditwheel/repair.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from collections import OrderedDict
from os.path import exists, basename, abspath, isabs, dirname
from os.path import join as pjoin
from subprocess import check_call
from typing import Dict, Optional, Tuple

from auditwheel.patcher import ElfPatcher
Expand All @@ -28,7 +29,8 @@


def repair_wheel(wheel_path: str, abi: str, lib_sdir: str, out_dir: str,
update_tags: bool, patcher: ElfPatcher) -> Optional[str]:
update_tags: bool, patcher: ElfPatcher,
strip: bool = False) -> Optional[str]:

external_refs_by_fn = get_wheel_elfdata(wheel_path)[1]

Expand Down Expand Up @@ -88,9 +90,21 @@ def repair_wheel(wheel_path: str, abi: str, lib_sdir: str, out_dir: str,
if update_tags:
ctx.out_wheel = add_platforms(ctx, [abi],
get_replace_platforms(abi))

if strip:
libs_to_strip = [path for (_, path) in soname_map.values()]
extensions = external_refs_by_fn.keys()
strip_symbols(itertools.chain(libs_to_strip, extensions))

return ctx.out_wheel


def strip_symbols(libraries):
for lib in libraries:
logger.info('Stripping symbols from %s', lib)
check_call(['strip', '-s', lib])


def copylib(src_path, dest_dir, patcher):
"""Graft a shared library from the system into the wheel and update the
relevant links.
Expand Down
3 changes: 3 additions & 0 deletions tests/integration/sample_extension/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[build-system]
requires = ["setuptools >= 45.0.0", "cython"]
build-backend = "setuptools.build_meta"
8 changes: 8 additions & 0 deletions tests/integration/sample_extension/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from setuptools import setup
from Cython.Build import cythonize

setup(
name="sample_extension",
version="0.1.0",
ext_modules=cythonize("src/sample_extension.pyx")
)
5 changes: 5 additions & 0 deletions tests/integration/sample_extension/src/sample_extension.pyx
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
def test_func(x):
return _test_func(x)

cdef _test_func(x):
return x + 1
30 changes: 30 additions & 0 deletions tests/integration/test_manylinux.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import glob
from contextlib import contextmanager
import docker
from subprocess import CalledProcessError
Expand Down Expand Up @@ -650,3 +651,32 @@ def test_build_repair_wheel_with_internal_rpath(any_manylinux_container, docker_
)
for name in w.namelist()
)


def test_strip_wheel(any_manylinux_container, docker_python, io_folder):
policy, manylinux_ctr = any_manylinux_container
docker_exec(
manylinux_ctr,
['bash', '-c', 'cd /auditwheel_src/tests/integration/sample_extension '
'&& python -m pip wheel --no-deps -w /io .']
)

orig_wheel, *_ = os.listdir(io_folder)
assert orig_wheel.startswith("sample_extension-0.1.0")

# Repair the wheel using the appropriate manylinux container
repair_command = (
'auditwheel repair --plat {policy} --strip -w /io /io/{orig_wheel}'
).format(policy=policy, orig_wheel=orig_wheel)
docker_exec(manylinux_ctr, repair_command)

repaired_wheel, *_ = glob.glob("{io_folder}/*{policy}*.whl".format(
io_folder=io_folder, policy=policy))
repaired_wheel = os.path.basename(repaired_wheel)

docker_exec(docker_python, "pip install /io/" + repaired_wheel)
output = docker_exec(
docker_python,
["python", "-c", "from sample_extension import test_func; print(test_func(1))"]
)
assert output.strip() == "2"