diff options
author | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2022-12-05 10:39:27 +0100 |
---|---|---|
committer | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2022-12-06 08:35:36 +0100 |
commit | 2d7c438cc4c13b22bbe45e937cbdb4215239fd29 (patch) | |
tree | e6043df14f3f8ef5f376380598600e1671c954dd /build_scripts | |
parent | 67292776a6cba219f5145db00b16e30015b4a33c (diff) |
build system: Port get_shared_library_filters to pathlib
Introduce a helper to find shared libraries and change the functions
to use Paths.
Task-number: PYSIDE-2080
Change-Id: I0b2e4c4c21f9810f6b45986c784d050fbf7a8058
Reviewed-by: Cristian Maureira-Fredes <cristian.maureira-fredes@qt.io>
Diffstat (limited to 'build_scripts')
-rw-r--r-- | build_scripts/main.py | 41 | ||||
-rw-r--r-- | build_scripts/platforms/linux.py | 4 |
2 files changed, 21 insertions, 24 deletions
diff --git a/build_scripts/main.py b/build_scripts/main.py index 7d3073da9..2fc66dfd6 100644 --- a/build_scripts/main.py +++ b/build_scripts/main.py @@ -1060,28 +1060,29 @@ class PysideBuild(_build, CommandMixin, BuildInfoCollectorMixin): filters = unix_filters return filters + def _find_shared_libraries(self, path, recursive=False): + """Helper to find shared libraries in a path.""" + result = set() + for filter in self.get_shared_library_filters(): + glob_pattern = f"**/{filter}" if recursive else filter + for library in path.glob(glob_pattern): + result.add(library) + return list(result) + def package_libraries(self, package_path): """Returns the libraries of the Python module""" - filters = self.get_shared_library_filters() - return [lib for lib in os.listdir( - package_path) if filter_match(lib, filters)] + return self._find_shared_libraries(package_path) def get_shared_libraries_in_path_recursively(self, initial_path): """Returns shared library plugins in given path (collected recursively)""" - filters = self.get_shared_library_filters() - libraries = [] - for dir_path, dir_names, file_names in os.walk(initial_path): - for name in file_names: - if filter_match(name, filters): - library_path = Path(dir_path) / name - libraries.append(library_path) - return libraries + return self._find_shared_libraries(initial_path, recursive=True) def update_rpath(self, package_path, executables, libexec=False): ROOT = '@loader_path' if sys.platform == 'darwin' else '$ORIGIN' QT_PATH = '/../lib' if libexec else '/Qt/lib' + message = "Patched rpath to '$ORIGIN/' in" if sys.platform.startswith('linux'): def rpath_cmd(srcpath): final_rpath = '' @@ -1100,6 +1101,7 @@ class PysideBuild(_build, CommandMixin, BuildInfoCollectorMixin): override=override) elif sys.platform == 'darwin': + message = "Updated rpath in" def rpath_cmd(srcpath): final_rpath = '' # Command line rpath option takes precedence over @@ -1117,15 +1119,13 @@ class PysideBuild(_build, CommandMixin, BuildInfoCollectorMixin): raise RuntimeError(f"Not configured for platform {sys.platform}") # Update rpath - for srcname in executables: - srcpath = Path(package_path) / srcname - if srcpath.is_dir() or srcpath.is_symlink(): + for executable in executables: + if executable.is_dir() or executable.is_symlink(): continue - if not srcpath.exists(): + if not executable.exists(): continue - rpath_cmd(srcpath) - log.info("Patched rpath to '$ORIGIN/' (Linux) or " - f"updated rpath (OS/X) in {srcpath}.") + rpath_cmd(executable) + log.info(f"{message} {executable}.") def update_rpath_for_linux_plugins( self, @@ -1145,7 +1145,6 @@ class PysideBuild(_build, CommandMixin, BuildInfoCollectorMixin): log.info("Patching rpath for Qt and QML plugins.") for plugin in plugin_paths: - plugin = Path(plugin) if plugin.is_dir() or plugin.is_symlink(): continue if not plugin.exists(): @@ -1175,9 +1174,7 @@ class PysideBuild(_build, CommandMixin, BuildInfoCollectorMixin): qt_lib_dir = Path(qt_lib_dir) rpath_value = "$ORIGIN" log.info(f"Patching rpath for Qt and ICU libraries in {qt_lib_dir}.") - libs = self.package_libraries(qt_lib_dir) - lib_paths = [qt_lib_dir / lib for lib in libs] - for library in lib_paths: + for library in self.package_libraries(qt_lib_dir): if library.is_dir() or library.is_symlink(): continue if library.exists(): diff --git a/build_scripts/platforms/linux.py b/build_scripts/platforms/linux.py index c99a6e925..3d473063c 100644 --- a/build_scripts/platforms/linux.py +++ b/build_scripts/platforms/linux.py @@ -92,7 +92,7 @@ def prepare_standalone_package_linux(pyside_build, _vars, cross_build=False): _vars=_vars) copied_plugins = pyside_build.get_shared_libraries_in_path_recursively( - os.fspath(plugins_target)) + plugins_target) pyside_build.update_rpath_for_linux_plugins(copied_plugins) if copy_qml: @@ -106,7 +106,7 @@ def prepare_standalone_package_linux(pyside_build, _vars, cross_build=False): ignore=["*.debug"], _vars=_vars) copied_plugins = pyside_build.get_shared_libraries_in_path_recursively( - os.fspath(qml_plugins_target)) + qml_plugins_target) pyside_build.update_rpath_for_linux_plugins( copied_plugins, qt_lib_dir=destination_qt_lib_dir, |