aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-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)