Skip to content

Commit

Permalink
Python wheel: failed to set RPATH for 3rd parties (#5835)
Browse files Browse the repository at this point in the history
* Python wheel: failed to set RPATH for 3rd parties

* fix linter issues

* fix indent

* vpu_custom_kernels

* move ELF check under linux condition

* pylint
  • Loading branch information
slyubimt authored May 26, 2021
1 parent 96b7a04 commit b07bcfb
Showing 1 changed file with 26 additions and 8 deletions.
34 changes: 26 additions & 8 deletions inference-engine/ie_bridges/python/wheel/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from distutils.command.build import build
from distutils.errors import DistutilsSetupError
from distutils.file_util import copy_file
from distutils import log
from setuptools import setup, find_namespace_packages, Extension
from setuptools.command.build_ext import build_ext
from setuptools.command.build_clib import build_clib
Expand Down Expand Up @@ -74,12 +75,25 @@
'install_dir': NGRAPH_LIBS_DIR,
'rpath': LIBS_RPATH,
},
'tbb_libs': {'name': 'tbb', 'prefix': 'libs.tbb', 'install_dir': TBB_LIBS_DIR},
'tbb_libs': {
'name': 'tbb',
'prefix': 'libs.tbb',
'install_dir': TBB_LIBS_DIR,
'rpath': LIBS_RPATH,
},
}

PY_INSTALL_CFG = {
'ie_py': {'name': PYTHON_VERSION, 'prefix': 'site-packages', 'install_dir': PY_PACKAGES_DIR},
'ngraph_py': {'name': f'pyngraph_{PYTHON_VERSION}', 'prefix': 'site-packages', 'install_dir': PY_PACKAGES_DIR},
'ie_py': {
'name': PYTHON_VERSION,
'prefix': 'site-packages',
'install_dir': PY_PACKAGES_DIR,
},
'ngraph_py': {
'name': f'pyngraph_{PYTHON_VERSION}',
'prefix': 'site-packages',
'install_dir': PY_PACKAGES_DIR,
},
}


Expand Down Expand Up @@ -128,10 +142,9 @@ def configure(self, install_cfg):
self.spawn(['cmake', '--install', CMAKE_BUILD_DIR, '--prefix', install_prefix, '--component', comp_data.get('name')])
# set rpath if applicable
if sys.platform != 'win32' and comp_data.get('rpath'):
file_types = ['*.so'] if sys.platform == 'linux' else ['*.dylib', '*.so']
for file_type in file_types:
for path in Path(install_dir).glob(file_type):
set_rpath(comp_data['rpath'], path)
file_types = ['.so'] if sys.platform == 'linux' else ['.dylib', '.so']
for path in filter(lambda p: any(item in file_types for item in p.suffixes), Path(install_dir).glob('*')):
set_rpath(comp_data['rpath'], os.path.realpath(path))

def generate_package(self, src_dirs):
"""
Expand Down Expand Up @@ -173,7 +186,7 @@ def run(self):
rpath = os.path.join('$ORIGIN', rpath, WHEEL_LIBS_INSTALL_DIR)
elif sys.platform == 'darwin':
rpath = os.path.join('@loader_path', rpath, WHEEL_LIBS_INSTALL_DIR)
set_rpath(rpath, src)
set_rpath(rpath, os.path.realpath(src))

copy_file(src, dst, verbose=self.verbose, dry_run=self.dry_run)

Expand Down Expand Up @@ -214,7 +227,12 @@ def set_rpath(rpath, executable):
print(f'Setting rpath {rpath} for {executable}') # noqa: T001
cmd = []
rpath_tool = ''

if sys.platform == 'linux':
with open(os.path.realpath(executable), 'rb') as file:
if file.read(1) != b'\x7f':
log.warn(f'WARNING: {executable}: missed ELF header')
return
rpath_tool = 'patchelf'
cmd = [rpath_tool, '--set-rpath', rpath, executable]
elif sys.platform == 'darwin':
Expand Down

0 comments on commit b07bcfb

Please sign in to comment.