diff options
author | Joshua Lock <josh@linux.intel.com> | 2010-02-12 14:55:32 +0000 |
---|---|---|
committer | Joshua Lock <josh@linux.intel.com> | 2010-02-12 15:00:44 +0000 |
commit | f1a87fadc7c091c67499a0c953603ce63f826177 (patch) | |
tree | 9e49d3682feb96eb4bf763b94d22d6155736f52b /meta/classes/relocatable.bbclass | |
parent | 62c103ce0e154ee5bf6183987adc90fc6df154c6 (diff) | |
download | openembedded-core-f1a87fadc7c091c67499a0c953603ce63f826177.tar.gz openembedded-core-f1a87fadc7c091c67499a0c953603ce63f826177.tar.bz2 openembedded-core-f1a87fadc7c091c67499a0c953603ce63f826177.tar.xz openembedded-core-f1a87fadc7c091c67499a0c953603ce63f826177.zip |
relocatable.bbclass: Improve logic and style
The initial pass at this class was pretty lame and broke on a lot of native
packages. This rewrite makes the code a lot more dynamic, removing use of hard
coded paths and improving the logic.
The class now runs a chrpath -l over the binary to determine what rpaths are
currently set. It then munges the output and determines relative versions of
each component of the rpath and uses chrpath -r to set them.
Signed-off-by: Joshua Lock <josh@linux.intel.com>
Diffstat (limited to 'meta/classes/relocatable.bbclass')
-rw-r--r-- | meta/classes/relocatable.bbclass | 46 |
1 files changed, 31 insertions, 15 deletions
diff --git a/meta/classes/relocatable.bbclass b/meta/classes/relocatable.bbclass index 81fe8c518..95be7b6e8 100644 --- a/meta/classes/relocatable.bbclass +++ b/meta/classes/relocatable.bbclass @@ -2,23 +2,39 @@ SYSROOT_PREPROCESS_FUNCS += "relocatable_binaries_preprocess" CHRPATH_BIN ?= "chrpath" -def rpath_replace (paths, d): - chrpath = bb.data.expand('${CHRPATH_BIN}', d) +def rpath_replace (path, d): + import subprocess as sub - for path in paths: - for root, dirs, files in os.walk(path): - for f in files: - if 'usr' in path: - os.system("%s -r $ORIGIN/../lib:$ORIGIN/../../lib %s/%s" % (chrpath, path,f)) - else: - os.system("%s -r $ORIGIN/../lib %s/%s" % (chrpath, path, f)) + cmd = bb.data.expand('${CHRPATH_BIN}', d) + tmpdir = bb.data.expand('${base_prefix}', d) -python relocatable_binaries_preprocess() { - paths = [] - target = bb.data.expand("${SYSROOT_DESTDIR}${TMPDIR}/sysroots/${TARGET_ARCH}-${TARGET_OS}", d) + for root, dirs, files in os.walk(path): + for file in files: + fpath = root + '/' + file + if '/bin/' in fpath: + p = sub.Popen([cmd, '-l', fpath],stdout=sub.PIPE,stderr=sub.PIPE) + err, out = p.communicate() + # If returned succesfully, process stderr for results + if p.returncode == 0: + # Throw away everything other than the rpath list + curr_rpath = err.partition("RPATH=")[2] + #bb.note("Current rpath for %s is %s" % (fpath, curr_rpath.strip())) + rpaths = curr_rpath.split(":") + new_rpaths = [] + for rpath in rpaths: + depth = fpath.partition(tmpdir)[2].strip().count('/') + if depth == 3: + # / is two levels up + root = "$ORIGIN/../.." + else: + root = "$ORIGIN/.." - paths.append(target + "/bin") - paths.append(target + "/usr/bin") + # kill everything up to "/" + new_rpaths.append("%s%s" % (root, rpath.partition(tmpdir)[2].strip())) + args = ":".join(new_rpaths) + #bb.note("Setting rpath to " + args) + sub.call([cmd, '-r', args, fpath]) - rpath_replace(paths, d) +python relocatable_binaries_preprocess() { + rpath_replace(bb.data.expand("${SYSROOT_DESTDIR}${TMPDIR}/sysroots/${TARGET_ARCH}-${TARGET_OS}", d), d) } |