relocatable: Handle directories having subdirectories of binaries

Make the processing of directories less naive so that it can handle a directory
with children that are directories. We now scan for and process binaries in all
directories below the scanned paths rather than only the top-level directory.

This patch moves the meat of the post-processing into a separate function which
is fed paths, process_dir (). Then when the function finds a subdirectory of
the passed path which is itself a directory it recursively calls itself.

Signed-off-by: Joshua Lock <josh@linux.intel.com>
This commit is contained in:
Joshua Lock 2010-04-01 11:42:50 +01:00
parent cf929499aa
commit b43b80c760
1 changed files with 24 additions and 15 deletions

View File

@ -3,27 +3,28 @@ SYSROOT_PREPROCESS_FUNCS += "relocatable_binaries_preprocess"
CHRPATH_BIN ?= "chrpath"
PREPROCESS_RELOCATE_DIRS ?= ""
def rpath_replace (path, d):
def process_dir (directory, d):
import subprocess as sub
cmd = bb.data.expand('${CHRPATH_BIN}', d)
bindirs = bb.data.expand("${bindir} ${sbindir} ${base_sbindir} ${base_bindir} ${libdir} ${base_libdir} ${PREPROCESS_RELOCATE_DIRS}", d).split()
tmpdir = bb.data.getVar('TMPDIR', d)
basedir = bb.data.expand('${base_prefix}', d)
for d in bindirs:
dir = path + "/" + d
bb.debug("Checking %s for binaries to process" % dir)
if not os.path.exists(dir):
continue
for file in os.listdir(dir):
fpath = dir + "/" + file
if os.path.islink(fpath):
fpath = os.readlink(fpath)
if not os.path.isabs(fpath):
fpath = os.path.normpath(os.path.join(dir, fpath))
bb.debug("Checking %s for binaries to process" % directory)
if not os.path.exists(directory):
return
dirs = os.listdir(directory)
for file in dirs:
fpath = directory + "/" + file
if os.path.islink(fpath):
fpath = os.readlink(fpath)
if not os.path.isabs(fpath):
fpath = os.path.normpath(os.path.join(directory, fpath))
if os.path.isdir(fpath):
process_dir(fpath, d)
else:
#bb.note("Testing %s for relocatability" % fpath)
p = sub.Popen([cmd, '-l', fpath],stdout=sub.PIPE,stderr=sub.PIPE)
err, out = p.communicate()
@ -65,6 +66,14 @@ def rpath_replace (path, d):
#bb.note("Setting rpath to " + args)
sub.call([cmd, '-r', args, fpath])
def rpath_replace (path, d):
bindirs = bb.data.expand("${bindir} ${sbindir} ${base_sbindir} ${base_bindir} ${libdir} ${base_libdir} ${PREPROCESS_RELOCATE_DIRS}", d).split()
for bindir in bindirs:
bb.note ("Processing directory " + bindir)
directory = path + "/" + bindir
process_dir (directory, d)
python relocatable_binaries_preprocess() {
rpath_replace(bb.data.expand('${SYSROOT_DESTDIR}', d), d)
}