Python wheel: failed to set RPATH for 3rd parties (#5835)

* Python wheel: failed to set RPATH for 3rd parties

* fix linter issues

* fix indent

* vpu_custom_kernels

* move ELF check under linux condition

* pylint
This commit is contained in:
Sergey Lyubimtsev 2021-05-26 21:31:06 +03:00 committed by GitHub
parent 96b7a04cfe
commit b07bcfb060
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -13,6 +13,7 @@ from distutils.command.install import install
from distutils.command.build import build from distutils.command.build import build
from distutils.errors import DistutilsSetupError from distutils.errors import DistutilsSetupError
from distutils.file_util import copy_file from distutils.file_util import copy_file
from distutils import log
from setuptools import setup, find_namespace_packages, Extension from setuptools import setup, find_namespace_packages, Extension
from setuptools.command.build_ext import build_ext from setuptools.command.build_ext import build_ext
from setuptools.command.build_clib import build_clib from setuptools.command.build_clib import build_clib
@ -74,12 +75,25 @@ LIB_INSTALL_CFG = {
'install_dir': NGRAPH_LIBS_DIR, 'install_dir': NGRAPH_LIBS_DIR,
'rpath': LIBS_RPATH, '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 = { PY_INSTALL_CFG = {
'ie_py': {'name': PYTHON_VERSION, 'prefix': 'site-packages', 'install_dir': PY_PACKAGES_DIR}, 'ie_py': {
'ngraph_py': {'name': f'pyngraph_{PYTHON_VERSION}', 'prefix': 'site-packages', 'install_dir': PY_PACKAGES_DIR}, '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')]) self.spawn(['cmake', '--install', CMAKE_BUILD_DIR, '--prefix', install_prefix, '--component', comp_data.get('name')])
# set rpath if applicable # set rpath if applicable
if sys.platform != 'win32' and comp_data.get('rpath'): if sys.platform != 'win32' and comp_data.get('rpath'):
file_types = ['*.so'] if sys.platform == 'linux' else ['*.dylib', '*.so'] file_types = ['.so'] if sys.platform == 'linux' else ['.dylib', '.so']
for file_type in file_types: for path in filter(lambda p: any(item in file_types for item in p.suffixes), Path(install_dir).glob('*')):
for path in Path(install_dir).glob(file_type): set_rpath(comp_data['rpath'], os.path.realpath(path))
set_rpath(comp_data['rpath'], path)
def generate_package(self, src_dirs): def generate_package(self, src_dirs):
""" """
@ -173,7 +186,7 @@ class CopyExt(build_ext):
rpath = os.path.join('$ORIGIN', rpath, WHEEL_LIBS_INSTALL_DIR) rpath = os.path.join('$ORIGIN', rpath, WHEEL_LIBS_INSTALL_DIR)
elif sys.platform == 'darwin': elif sys.platform == 'darwin':
rpath = os.path.join('@loader_path', rpath, WHEEL_LIBS_INSTALL_DIR) 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) 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 print(f'Setting rpath {rpath} for {executable}') # noqa: T001
cmd = [] cmd = []
rpath_tool = '' rpath_tool = ''
if sys.platform == 'linux': 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' rpath_tool = 'patchelf'
cmd = [rpath_tool, '--set-rpath', rpath, executable] cmd = [rpath_tool, '--set-rpath', rpath, executable]
elif sys.platform == 'darwin': elif sys.platform == 'darwin':