aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@qt.io>2021-06-10 11:46:08 +0200
committerFriedemann Kleint <Friedemann.Kleint@qt.io>2021-07-06 12:28:34 +0200
commit80c2acebba5bef4f08d6b4eddd11d15f1d63be8d (patch)
treec2c0b4fc74fa1678593998c0985d9d7f6c3da8f7
parent8be437d44e59c043d79f072c04a06b295c913b3b (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: Christian Tismer <tismer@stackless.com> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
-rw-r--r--build_scripts/utils.py64
1 files changed, 60 insertions, 4 deletions
diff --git a/build_scripts/utils.py b/build_scripts/utils.py
index 1cc224963..614fe336a 100644
--- a/build_scripts/utils.py
+++ b/build_scripts/utils.py
@@ -796,18 +796,48 @@ 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 = f"ldd failed to query for dependent shared libraries of {executable_path}: {error}"
+ raise RuntimeError(message)
+ return output
+
+
+def _ldd_ldso(executable_path):
"""
+ Helper for ldd():
Returns ld.so output of shared library dependencies for given
`executable_path`.
- This is a partial port of /usr/bin/ldd from bash to Python.
+ This is a partial port of /usr/bin/ldd from bash to Python for
+ systems that do not have ldd.
The dependency list is retrieved by setting the
LD_TRACE_LOADED_OBJECTS=1 environment variable, and executing the
given path via the dynamic loader ld.so.
- Only works on Linux. The port is required to make this work on
- systems that might not have ldd.
+ Only works on Linux.
This is because ldd (on Ubuntu) is shipped in the libc-bin package
that, which might have a
minuscule percentage of not being installed.
@@ -856,6 +886,32 @@ def ldd(executable_path):
f"libraries of {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 = f"ldd: Falling back to ld.so ({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)