diff --git a/src/bindings/python/wheel/setup.py b/src/bindings/python/wheel/setup.py index 095b9579f4b354..d91523659a0a78 100644 --- a/src/bindings/python/wheel/setup.py +++ b/src/bindings/python/wheel/setup.py @@ -441,27 +441,22 @@ def copy_package_libs(self, src_dirs): package_clibs_dir = os.path.join(PACKAGE_DIR, WHEEL_LIBS_INSTALL_DIR) os.makedirs(package_clibs_dir, exist_ok=True) - for src_dir in src_dirs: - # additional blacklist filter, just to fix cmake install issues - blacklist_patterns = [ # static libraries and PBD files - "^.*\\.a$", "^.*\\.pdb$", - # TBB debug libraries - "^.*_debug\\.dll$", "^.*_debug\\.\\d*\\.dylib$", "^.*_debug\\.so\\.\\d*$", - # hwloc static libs on Windows - "^.*\\.la$"] + # additional blacklist filter, just to fix cmake install issues + blacklist_patterns = [ # static libraries and PBD files + "^.*\\.a$", "^.*\\.pdb$", + # TBB debug libraries + "^.*_debug\\.dll$", "^.*_debug\\.\\d*\\.dylib$", "^.*_debug\\.so\\.\\d*$", + # hwloc static libs on Windows + "^.*\\.la$"] + for src_dir in src_dirs: # copy so / dylib files to WHEEL_LIBS_INSTALL_DIR (clibs) inside python package for file_path in Path(src_dir).rglob("*"): file_name = os.path.basename(file_path) if file_path.is_symlink(): # sanity check for self.resolve_symlinks sys.exit(f"Wheel package content must not contain symlinks {file_path}") - blacklisted = False - for pattern in blacklist_patterns: - if re.match(pattern, file_name) is not None: - blacklisted = True - break - if file_path.is_file() and not blacklisted: + if file_path.is_file() and not is_blacklisted(file_name, blacklist_patterns): dst_file = os.path.join(package_clibs_dir, file_name) copyfile(file_path, dst_file) self.announce(f"Copy {file_path} to {dst_file}", level=3) @@ -480,22 +475,39 @@ def copy_package_data(self, src_dirs): package_cmake_dir = os.path.join(package_dir, "cmake") os.makedirs(package_cmake_dir, exist_ok=True) - replacements = { + openvino_replacements = { # change the path where the libraries are installed (runtime/lib/intel64/Release -> openvino/libs) - r"({_IMPORT_PREFIX})\/(.*)\/(.*.[lib|dylib|so|dll])": rf"\1/{WHEEL_LIBS_INSTALL_DIR}/\3", + r"(\{_IMPORT_PREFIX\})\/(.*)\/(.+\.[lib|dylib|so|dll])": rf"\1/{WHEEL_LIBS_INSTALL_DIR}/\3", # change the path where the include files are installed (runtime/include -> openvino/include) - r"({_IMPORT_PREFIX})\/(.*)\/(include)": rf"\1/{WHEEL_PACKAGE_DIR}/\3", - # change the libs versions (so.2024.3.0 -> so.2430 or 2024.3.0.dylib -> 2430.dylib) - r"(.so)?.(\d\d)(\d\d).(\d+).(\d+)(.dylib)?": r"\1.\3\4\5\6", + r"(\{_IMPORT_PREFIX\})\/(.*)\/(include)": rf"\1/{WHEEL_PACKAGE_DIR}/\3", + # change the OpenVINO libs versions (so.2024.3.0 -> so.2430 or 2024.3.0.dylib -> 2430.dylib) + r"\.(\d\d)(\d\d)\.(\d+)\.(\d+)\.dylib": r".\2\3\4.dylib", + r"\.so\.(\d\d)(\d\d)\.(\d+)\.(\d+)": r".so.\2\3\4", + } + + tbb_replacements = { + # change the path where the TBBConfig.cmake is installed (/lib/cmake/TBB -> openvino/cmake) + r"(\{CMAKE_CURRENT_LIST_FILE\})": r"\1/fake_dir", + # change the path where the libraries are installed (/lib -> openvino/libs) + r"(\{_IMPORT_PREFIX\})\/(.*)\/(.+\.[lib|dylib|so|dll])": rf"\1/{WHEEL_LIBS_INSTALL_DIR}/\3", + # change the path where the include files are installed (/include -> openvino/include) + r"(\{_IMPORT_PREFIX\})\/(.*)(include)": rf"\1/{WHEEL_PACKAGE_DIR}/\3", + # change the TBB libs versions (.12.13.dylib -> .12.dylib) + r"\.(\d+)\.(\d+)\.dylib": r".\1.dylib", + r"\.so\.(\d+)\.(\d+)": r".so.\1", } + # additional blacklist filter, just to fix cmake install issues + blacklist_patterns = [ # TBB cmake files describing debug libraries + "^.*TBBTargets-debug\\.cmake$"] + for src_dir in src_dirs: src, dst = Path(src_dir), Path(package_dir) # move the static libs to the directory with the shared libraries for file_path in Path(src).rglob("*.lib"): file_name = os.path.basename(file_path) - if file_path.is_file(): + if file_path.is_file() and not is_blacklisted(file_name, blacklist_patterns): dst_file = os.path.join(package_clibs_dir, file_name) move(file_path, dst_file) self.announce(f"Move {file_path} to {dst_file}", level=3) @@ -503,18 +515,26 @@ def copy_package_data(self, src_dirs): # collect all cmake files in one directory for file_path in Path(src).rglob("*.cmake"): file_name = os.path.basename(file_path) - if file_path.is_file(): + if file_path.is_file() and not is_blacklisted(file_name, blacklist_patterns): dst_file = os.path.join(package_cmake_dir, file_name) self.announce(f"Move {file_path} to {dst_file}", level=3) move(file_path, dst_file) self.announce("Patch cmake configurations", level=3) - replace_strings_in_file(dst_file, replacements) + replace_strings_in_file(dst_file, + openvino_replacements if file_name.startswith("OpenVINO") else tbb_replacements) if os.path.isdir(src) and os.listdir(src): # copy the rest of the files to the package directly shutil.copytree(src, dst, dirs_exist_ok=True) +def is_blacklisted(file_name, blacklist_patterns): + for pattern in blacklist_patterns: + if re.match(pattern, file_name) is not None: + return True + return False + + def copy_file(src, dst, verbose=False, dry_run=False): """Custom file copy.""" if dry_run: