Extract the dynamic library dependencies from an ELF executable.
(path: Path)
| 287 | |
| 288 | |
| 289 | def get_needed_libs(path: Path) -> Iterator[Path]: |
| 290 | """ |
| 291 | Extract the dynamic library dependencies from an ELF executable. |
| 292 | """ |
| 293 | with subprocess.Popen( |
| 294 | ["ldd", str(path)], stdout=subprocess.PIPE, stderr=subprocess.PIPE |
| 295 | ) as proc: |
| 296 | out, err = proc.communicate() |
| 297 | if proc.returncode != 0: |
| 298 | err = err.decode("utf-8").splitlines()[-1].strip() |
| 299 | raise Exception(f"cannot read ELF file: {err}") |
| 300 | for match in LDD_LIB_RE.finditer(out.decode("utf-8")): |
| 301 | libname, libpath = match.groups() |
| 302 | if libname.startswith("librte_"): |
| 303 | libpath = Path(libpath) |
| 304 | if libpath.is_file(): |
| 305 | yield libpath.resolve() |
| 306 | |
| 307 | |
| 308 | # ---------------------------------------------------------------------------- |