summaryrefslogtreecommitdiffstats
path: root/meta/classes/relocatable.bbclass
diff options
context:
space:
mode:
authorLaurentiu Palcu <laurentiu.palcu@intel.com>2012-07-31 11:49:37 +0300
committerRichard Purdie <richard.purdie@linuxfoundation.org>2012-08-02 15:28:39 +0100
commit476ced15c244b5a4bb91cef59fdf7e3b5a981576 (patch)
treee22a034ab718c1f657461425fbaee2801ec43c3a /meta/classes/relocatable.bbclass
parent44df019842bc83cdcf559ac64b989ab3c5febd6a (diff)
downloadpoky-476ced15c244b5a4bb91cef59fdf7e3b5a981576.tar.gz
relocatable.bbclass: split it up, to reuse code
Most of the code in relocatable.bbclass will be used for relocating the SDK binaries. So, create another class chrpath.bbclass that will contain the core of the relocatable.bbclass, so we can reuse it. (From OE-Core rev: b50677b1641b201fd69942fd82a360907338234d) Signed-off-by: Laurentiu Palcu <laurentiu.palcu@intel.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'meta/classes/relocatable.bbclass')
-rw-r--r--meta/classes/relocatable.bbclass91
1 files changed, 2 insertions, 89 deletions
diff --git a/meta/classes/relocatable.bbclass b/meta/classes/relocatable.bbclass
index 072f533f4f..4ca9981f44 100644
--- a/meta/classes/relocatable.bbclass
+++ b/meta/classes/relocatable.bbclass
@@ -1,93 +1,6 @@
1SYSROOT_PREPROCESS_FUNCS += "relocatable_binaries_preprocess" 1inherit chrpath
2
3CHRPATH_BIN ?= "chrpath"
4PREPROCESS_RELOCATE_DIRS ?= ""
5
6def process_dir (directory, d):
7 import subprocess as sub
8 import stat
9
10 cmd = d.expand('${CHRPATH_BIN}')
11 tmpdir = d.getVar('TMPDIR')
12 basedir = d.expand('${base_prefix}')
13
14 #bb.debug("Checking %s for binaries to process" % directory)
15 if not os.path.exists(directory):
16 return
17
18 dirs = os.listdir(directory)
19 for file in dirs:
20 fpath = directory + "/" + file
21 fpath = os.path.normpath(fpath)
22 if os.path.islink(fpath):
23 # Skip symlinks
24 continue
25
26 if os.path.isdir(fpath):
27 process_dir(fpath, d)
28 else:
29 #bb.note("Testing %s for relocatability" % fpath)
30
31 # We need read and write permissions for chrpath, if we don't have
32 # them then set them temporarily. Take a copy of the files
33 # permissions so that we can restore them afterwards.
34 perms = os.stat(fpath)[stat.ST_MODE]
35 if os.access(fpath, os.W_OK|os.R_OK):
36 perms = None
37 else:
38 # Temporarily make the file writeable so we can chrpath it
39 os.chmod(fpath, perms|stat.S_IRWXU)
40 2
41 p = sub.Popen([cmd, '-l', fpath],stdout=sub.PIPE,stderr=sub.PIPE) 3SYSROOT_PREPROCESS_FUNCS += "relocatable_binaries_preprocess"
42 err, out = p.communicate()
43 # If returned succesfully, process stderr for results
44 if p.returncode != 0:
45 continue
46
47 # Throw away everything other than the rpath list
48 curr_rpath = err.partition("RPATH=")[2]
49 #bb.note("Current rpath for %s is %s" % (fpath, curr_rpath.strip()))
50 rpaths = curr_rpath.split(":")
51 new_rpaths = []
52 for rpath in rpaths:
53 # If rpath is already dynamic continue
54 if rpath.find("$ORIGIN") != -1:
55 continue
56 # If the rpath shares a root with base_prefix determine a new dynamic rpath from the
57 # base_prefix shared root
58 if rpath.find(basedir) != -1:
59 depth = fpath.partition(basedir)[2].count('/')
60 libpath = rpath.partition(basedir)[2].strip()
61 # otherwise (i.e. cross packages) determine a shared root based on the TMPDIR
62 # NOTE: This will not work reliably for cross packages, particularly in the case
63 # where your TMPDIR is a short path (i.e. /usr/poky) as chrpath cannot insert an
64 # rpath longer than that which is already set.
65 else:
66 depth = fpath.rpartition(tmpdir)[2].count('/')
67 libpath = rpath.partition(tmpdir)[2].strip()
68
69 base = "$ORIGIN"
70 while depth > 1:
71 base += "/.."
72 depth-=1
73 new_rpaths.append("%s%s" % (base, libpath))
74
75 # if we have modified some rpaths call chrpath to update the binary
76 if len(new_rpaths):
77 args = ":".join(new_rpaths)
78 #bb.note("Setting rpath for %s to %s" %(fpath, args))
79 sub.call([cmd, '-r', args, fpath])
80
81 if perms:
82 os.chmod(fpath, perms)
83
84def rpath_replace (path, d):
85 bindirs = d.expand("${bindir} ${sbindir} ${base_sbindir} ${base_bindir} ${libdir} ${base_libdir} ${libexecdir} ${PREPROCESS_RELOCATE_DIRS}").split()
86
87 for bindir in bindirs:
88 #bb.note ("Processing directory " + bindir)
89 directory = path + "/" + bindir
90 process_dir (directory, d)
91 4
92python relocatable_binaries_preprocess() { 5python relocatable_binaries_preprocess() {
93 rpath_replace(d.expand('${SYSROOT_DESTDIR}'), d) 6 rpath_replace(d.expand('${SYSROOT_DESTDIR}'), d)