Skip to content

Commit

Permalink
Merge pull request #95 from lpsinger/process-non-py-binaries
Browse files Browse the repository at this point in the history
Process non-Python binaries (e.g. binary executables)
  • Loading branch information
ehashman authored Jul 3, 2018
2 parents cb14341 + 8b0b43d commit 0b26fe4
Show file tree
Hide file tree
Showing 5 changed files with 94 additions and 7 deletions.
15 changes: 8 additions & 7 deletions auditwheel/wheel_abi.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,19 +41,20 @@ def get_wheel_elfdata(wheel_fn: str):
'The wheel has to be platlib compliant in order to be repaired by auditwheel.') %
so_path_split[-1])

log.info('processing: %s', fn)
elftree = lddtree(fn)
full_elftree[fn] = elftree
if is_py_ext:
log.info('processing: %s', fn)
elftree = lddtree(fn)
full_elftree[fn] = elftree
uses_PyFPE_jbuf |= elf_references_PyFPE_jbuf(elf)
for key, value in elf_find_versioned_symbols(elf):
versioned_symbols[key].add(value)
for key, value in elf_find_versioned_symbols(elf):
versioned_symbols[key].add(value)

if is_py_ext:
if py_ver == 2:
uses_ucs2_symbols |= any(
True for _ in elf_find_ucs2_symbols(elf))
full_external_refs[fn] = lddtree_external_references(elftree,
ctx.path)
full_external_refs[fn] = lddtree_external_references(elftree,
ctx.path)


log.debug(json.dumps(full_elftree, indent=4))
Expand Down
35 changes: 35 additions & 0 deletions tests/test_manylinux.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
'/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin')
WHEEL_CACHE_FOLDER = op.expanduser('~/.cache/auditwheel_tests')
ORIGINAL_NUMPY_WHEEL = 'numpy-1.11.0-cp35-cp35m-linux_x86_64.whl'
ORIGINAL_TESTPACKAGE_WHEEL = 'testpackage-0.0.1-cp35-cp35m-linux_x86_64.whl'


def find_src_folder():
Expand Down Expand Up @@ -161,3 +162,37 @@ def test_build_repair_numpy(docker_container):
# Check that the 2 fortran runtimes are well isolated and can be loaded
# at once in the same Python program:
docker_exec(python_id, ["python", "-c", "'import numpy; import foo'"])


def test_build_wheel_with_binary_executable(docker_container):
# Test building a wheel that contains a binary executable (e.g., a program)

manylinux_id, python_id, io_folder = docker_container
docker_exec(manylinux_id, 'yum install -y gsl-devel')

docker_exec(manylinux_id, 'cd /auditwheel_src/test/testpackage && python setup.py bdist_wheel -d /io')

filenames = os.listdir(io_folder)
assert filenames == [ORIGINAL_TESTPACKAGE_WHEEL]
orig_wheel = filenames[0]
assert 'manylinux' not in orig_wheel

# Repair the wheel using the manylinux1 container
docker_exec(manylinux_id, 'auditwheel repair -w /io /io/' + orig_wheel)
filenames = os.listdir(io_folder)
assert len(filenames) == 2
repaired_wheels = [fn for fn in filenames if 'manylinux1' in fn]
assert repaired_wheels == ['testpackage-0.0.1-cp35-cp35m-manylinux1_x86_64.whl']
repaired_wheel = repaired_wheels[0]
output = docker_exec(manylinux_id, 'auditwheel show /io/' + repaired_wheel)
assert (
'testpackage-0.0.1-cp35-cp35m-manylinux1_x86_64.whl is consistent'
' with the following platform tag: "manylinux1_x86_64"'
) in output.replace('\n', ' ')

# Check that the repaired numpy wheel can be installed and executed
# on a modern linux image.
docker_exec(python_id, 'pip install /io/' + repaired_wheel)
output = docker_exec(
python_id, 'python -c "from testpackage import runit; print(runit(1.5))"').strip()
assert output.strip() == '2.25'
12 changes: 12 additions & 0 deletions tests/testpackage/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from setuptools import setup
import subprocess

cmd = 'gcc testpackage/testprogram.c -lgsl -o testpackage/testprogram'
subprocess.check_call(cmd.split())

setup(
name='testpackage',
version='0.0.1',
packages=['testpackage'],
package_data={'testpackage': ['testprogram']}
)
8 changes: 8 additions & 0 deletions tests/testpackage/testpackage/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import pkg_resources
import subprocess


def runit(x):
filename = pkg_resources.resource_filename(__name__, 'testprogram')
output = subprocess.check_output([filename, str(x)])
return float(x)
31 changes: 31 additions & 0 deletions tests/testpackage/testpackage/testprogram.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/* A simple example program to square a number using GSL. */

#include <gsl/gsl_math.h>
#include <stdio.h>
#include <stdlib.h>

int main(int argc, char **argv)
{
double x;
char *startptr, *endptr;

if (argc != 2)
{
fputs("Expected exactly one command line argument\n", stderr);
return EXIT_FAILURE;
}

startptr = argv[1];
endptr = NULL;
x = strtod(startptr, &endptr);

if (startptr == endptr)
{
fputs("Expected command line argument to be a float\n", stderr);
return EXIT_FAILURE;
}

x = gsl_pow_2(x);
printf("%g\n", x);
return EXIT_SUCCESS;
}

0 comments on commit 0b26fe4

Please # to comment.