aboutsummaryrefslogtreecommitdiffstats
path: root/build_scripts
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@qt.io>2021-06-10 11:46:08 +0200
committerFriedemann Kleint <Friedemann.Kleint@qt.io>2022-01-25 13:47:03 +0100
commit109d276fe24e9e381cc2599347063cd7276fb63e (patch)
tree19117c6d2ba5ce149a5329a7ac1d233d984fd3d0 /build_scripts
parent843bb81dcf03f80de9c51cfa4c32e31c4e207deb (diff)
build_scripts/Linux: Try to determine library dependencies with ldd first
The build scripts used a reimplementation of ldd to determine library dependencies in case ldd is not installed which may fail on recent systems. Try ldd first and fall back to the reimplementation only if it fails. Change-Id: Icca16c2fae0ce6086284eb0194a28d8ec32daae6 Reviewed-by: Simo Fält <simo.falt@qt.io> (cherry picked from commit 2b1cc890293592c9f40dcc14119b726886a20fe8) Reviewed-by: Cristian Maureira-Fredes <cristian.maureira-fredes@qt.io>
Diffstat (limited to 'build_scripts')
-rw-r--r--build_scripts/utils.py57
1 files changed, 56 insertions, 1 deletions
diff --git a/build_scripts/utils.py b/build_scripts/utils.py
index 002d6ae5b..5d62d4307 100644
--- a/build_scripts/utils.py
+++ b/build_scripts/utils.py
@@ -813,7 +813,36 @@ def ldd_get_paths_for_dependencies(dependencies_regex, executable_path=None, dep
return paths
-def ldd(executable_path):
+def _ldd_ldd(executable_path):
+ """Helper for ldd():
+ Returns ldd output of shared library dependencies for given
+ `executable_path`.
+
+ Parameters
+ ----------
+ executable_path : str
+ path to executable or shared library.
+
+ Returns
+ -------
+ output : str
+ the raw output retrieved from the dynamic linker.
+ """
+
+ output = ''
+ error = ''
+ try:
+ output_lines = run_process_output(['ldd', executable_path])
+ output = '\n'.join(output_lines)
+ except Exception as e:
+ error = str(e)
+ if not output:
+ message = "ldd failed to query for dependent shared libraries of {}: {}".format(executable_path, error)
+ raise RuntimeError(message)
+ return output
+
+
+def _ldd_ldso(executable_path):
"""
Returns ld.so output of shared library dependencies for given
`executable_path`.
@@ -873,6 +902,32 @@ def ldd(executable_path):
"libraries of {} ".format(executable_path))
+def ldd(executable_path):
+ """
+ Returns ldd output of shared library dependencies for given `executable_path`,
+ using either ldd or ld.so depending on availability.
+
+ Parameters
+ ----------
+ executable_path : str
+ path to executable or shared library.
+
+ Returns
+ -------
+ output : str
+ the raw output retrieved from the dynamic linker.
+ """
+ result = ''
+ try:
+ result = _ldd_ldd(executable_path)
+ except RuntimeError as e:
+ message = "ldd: Falling back to ld.so ({})".format(str(e))
+ log.warn(message)
+ if not result:
+ result = _ldd_ldso(executable_path)
+ return result
+
+
def find_files_using_glob(path, pattern):
""" Returns list of files that matched glob `pattern` in `path`. """
final_pattern = os.path.join(path, pattern)