summaryrefslogtreecommitdiffstats
path: root/meta/classes/relocatable.bbclass
diff options
context:
space:
mode:
authorJoshua Lock <josh@linux.intel.com>2010-02-12 14:55:32 +0000
committerJoshua Lock <josh@linux.intel.com>2010-02-12 15:00:44 +0000
commitf1a87fadc7c091c67499a0c953603ce63f826177 (patch)
tree9e49d3682feb96eb4bf763b94d22d6155736f52b /meta/classes/relocatable.bbclass
parent62c103ce0e154ee5bf6183987adc90fc6df154c6 (diff)
downloadpoky-f1a87fadc7c091c67499a0c953603ce63f826177.tar.gz
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.bbclass46
1 files changed, 31 insertions, 15 deletions
diff --git a/meta/classes/relocatable.bbclass b/meta/classes/relocatable.bbclass
index 81fe8c518d..95be7b6e88 100644
--- a/meta/classes/relocatable.bbclass
+++ b/meta/classes/relocatable.bbclass
@@ -2,23 +2,39 @@ SYSROOT_PREPROCESS_FUNCS += "relocatable_binaries_preprocess"
2 2
3CHRPATH_BIN ?= "chrpath" 3CHRPATH_BIN ?= "chrpath"
4 4
5def rpath_replace (paths, d): 5def rpath_replace (path, d):
6 chrpath = bb.data.expand('${CHRPATH_BIN}', d) 6 import subprocess as sub
7 7
8 for path in paths: 8 cmd = bb.data.expand('${CHRPATH_BIN}', d)
9 for root, dirs, files in os.walk(path): 9 tmpdir = bb.data.expand('${base_prefix}', d)
10 for f in files:
11 if 'usr' in path:
12 os.system("%s -r $ORIGIN/../lib:$ORIGIN/../../lib %s/%s" % (chrpath, path,f))
13 else:
14 os.system("%s -r $ORIGIN/../lib %s/%s" % (chrpath, path, f))
15 10
16python relocatable_binaries_preprocess() { 11 for root, dirs, files in os.walk(path):
17 paths = [] 12 for file in files:
18 target = bb.data.expand("${SYSROOT_DESTDIR}${TMPDIR}/sysroots/${TARGET_ARCH}-${TARGET_OS}", d) 13 fpath = root + '/' + file
14 if '/bin/' in fpath:
15 p = sub.Popen([cmd, '-l', fpath],stdout=sub.PIPE,stderr=sub.PIPE)
16 err, out = p.communicate()
17 # If returned succesfully, process stderr for results
18 if p.returncode == 0:
19 # Throw away everything other than the rpath list
20 curr_rpath = err.partition("RPATH=")[2]
21 #bb.note("Current rpath for %s is %s" % (fpath, curr_rpath.strip()))
22 rpaths = curr_rpath.split(":")
23 new_rpaths = []
24 for rpath in rpaths:
25 depth = fpath.partition(tmpdir)[2].strip().count('/')
26 if depth == 3:
27 # / is two levels up
28 root = "$ORIGIN/../.."
29 else:
30 root = "$ORIGIN/.."
19 31
20 paths.append(target + "/bin") 32 # kill everything up to "/"
21 paths.append(target + "/usr/bin") 33 new_rpaths.append("%s%s" % (root, rpath.partition(tmpdir)[2].strip()))
34 args = ":".join(new_rpaths)
35 #bb.note("Setting rpath to " + args)
36 sub.call([cmd, '-r', args, fpath])
22 37
23 rpath_replace(paths, d) 38python relocatable_binaries_preprocess() {
39 rpath_replace(bb.data.expand("${SYSROOT_DESTDIR}${TMPDIR}/sysroots/${TARGET_ARCH}-${TARGET_OS}", d), d)
24} 40}