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-06-10 12:51:56 +0200
commit2b1cc890293592c9f40dcc14119b726886a20fe8 (patch)
tree49756f3187841bbb121988aab8503381bfc0daa2
parent99148a428f937476e5e740f16999bb2eb44a3c3f (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>
-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 0a9036905..abe0b2c05 100644
--- a/build_scripts/utils.py
+++ b/build_scripts/utils.py
@@ -802,18 +802,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.
@@ -862,6 +892,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)