From 564dcfbde6dcc09917af77ee992a0b9b4dcaa512 Mon Sep 17 00:00:00 2001 From: Mike Frysinger Date: Thu, 29 Sep 2011 14:43:18 -0400 Subject: [PATCH] check_deps: handle "include" directives in ld.so.conf The ld.so.conf file supports an "include" directive where it'll include all the files matched by the following glob. Since Gentoo has started using this, we need to support parsing of it too. So move the parsing code into a dedicated function and recursively call ourselves when we hit an include directive. BUG=chromium-os:20636 TEST=`./check_deps /build/amd64-generic /bin/bash` now finds libs TEST=`./build_image --board=x86-alex` still works Change-Id: I8894ca42358d91d8f2ee6e95b47faf9334ccdd26 Reviewed-on: http://gerrit.chromium.org/gerrit/8494 Reviewed-by: David James Commit-Ready: Mike Frysinger Tested-by: Mike Frysinger --- build_library/check_deps | 48 ++++++++++++++++++++++++++++++++-------- 1 file changed, 39 insertions(+), 9 deletions(-) diff --git a/build_library/check_deps b/build_library/check_deps index b15c62477f..82519c6eef 100755 --- a/build_library/check_deps +++ b/build_library/check_deps @@ -7,6 +7,7 @@ import os import re import sys +import glob _SHARED_RE = re.compile(r"Shared library: \[([^\]]+)\]") _RPATH_RE = re.compile(r"Library rpath: \[([^\]]+)\]") @@ -15,6 +16,43 @@ _RPATH_RE = re.compile(r"Library rpath: \[([^\]]+)\]") class CheckDependencies(object): """Check that dependencies for binaries can be found in the specified dir.""" + def _ReadLdSoConf(self, path): + """Parse ld.so.conf files. + + Starting with the file at PATH (searched relative to self._root), return + all the valid libdirs found. Include directives are handled recursively. + + Args: + path: the path to the ld.so.conf file (inside of the root). + + Returns: + A list of valid libdirs. + """ + + libdirs = [] + + ld_so_conf = self._root + path + if os.path.exists(ld_so_conf): + f = file(ld_so_conf) + + for line in f: + line = line.rstrip() + + if line.startswith("/"): + libpath = self._root + line + if os.path.exists(libpath): + libdirs.append(libpath) + + elif line.startswith("include "): + # Includes are absolute or relative to the file itself. + line = os.path.join(os.path.dirname(path), line[8:]) + for p in glob.glob(self._root + line): + libdirs.extend(self._ReadLdSoConf(os.path.relpath(p, self._root))) + + f.close() + + return libdirs + def __init__(self, root, verbose=False): """Initializer. @@ -38,15 +76,7 @@ class CheckDependencies(object): ] # Read more directories from ld.so.conf. - ld_so_conf = "%s/etc/ld.so.conf" % root - if os.path.exists(ld_so_conf): - f = file(ld_so_conf) - for line in f: - if line.startswith("/"): - path = root + line[:-1] - if os.path.exists(path): - libdirs.append(path) - f.close() + libdirs.extend(self._ReadLdSoConf("/etc/ld.so.conf")) self._ReadLibs(libdirs, self._libcache)