diff --git a/inference-engine/ie_bridges/python/wheel/setup.py b/inference-engine/ie_bridges/python/wheel/setup.py index c35a2ad1316..d7374308e8f 100644 --- a/inference-engine/ie_bridges/python/wheel/setup.py +++ b/inference-engine/ie_bridges/python/wheel/setup.py @@ -13,6 +13,7 @@ from distutils.command.install import install 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 @@ -74,12 +75,25 @@ LIB_INSTALL_CFG = { '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, + }, } @@ -128,10 +142,9 @@ class PrepareLibs(build_clib): 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): """ @@ -173,7 +186,7 @@ class CopyExt(build_ext): 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) @@ -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':