summaryrefslogtreecommitdiffstats
path: root/meta/classes/chrpath.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/chrpath.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/chrpath.bbclass')
-rw-r--r--meta/classes/chrpath.bbclass89
1 files changed, 89 insertions, 0 deletions
diff --git a/meta/classes/chrpath.bbclass b/meta/classes/chrpath.bbclass
new file mode 100644
index 0000000000..10b5ca0180
--- /dev/null
+++ b/meta/classes/chrpath.bbclass
@@ -0,0 +1,89 @@
1CHRPATH_BIN ?= "chrpath"
2PREPROCESS_RELOCATE_DIRS ?= ""
3
4def process_dir (directory, d):
5 import subprocess as sub
6 import stat
7
8 cmd = d.expand('${CHRPATH_BIN}')
9 tmpdir = d.getVar('TMPDIR')
10 basedir = d.expand('${base_prefix}')
11
12 #bb.debug("Checking %s for binaries to process" % directory)
13 if not os.path.exists(directory):
14 return
15
16 dirs = os.listdir(directory)
17 for file in dirs:
18 fpath = directory + "/" + file
19 fpath = os.path.normpath(fpath)
20 if os.path.islink(fpath):
21 # Skip symlinks
22 continue
23
24 if os.path.isdir(fpath):
25 process_dir(fpath, d)
26 else:
27 #bb.note("Testing %s for relocatability" % fpath)
28
29 # We need read and write permissions for chrpath, if we don't have
30 # them then set them temporarily. Take a copy of the files
31 # permissions so that we can restore them afterwards.
32 perms = os.stat(fpath)[stat.ST_MODE]
33 if os.access(fpath, os.W_OK|os.R_OK):
34 perms = None
35 else:
36 # Temporarily make the file writeable so we can chrpath it
37 os.chmod(fpath, perms|stat.S_IRWXU)
38
39 p = sub.Popen([cmd, '-l', fpath],stdout=sub.PIPE,stderr=sub.PIPE)
40 err, out = p.communicate()
41 # If returned succesfully, process stderr for results
42 if p.returncode != 0:
43 continue
44
45 # Throw away everything other than the rpath list
46 curr_rpath = err.partition("RPATH=")[2]
47 #bb.note("Current rpath for %s is %s" % (fpath, curr_rpath.strip()))
48 rpaths = curr_rpath.split(":")
49 new_rpaths = []
50 for rpath in rpaths:
51 # If rpath is already dynamic continue
52 if rpath.find("$ORIGIN") != -1:
53 continue
54 # If the rpath shares a root with base_prefix determine a new dynamic rpath from the
55 # base_prefix shared root
56 if rpath.find(basedir) != -1:
57 depth = fpath.partition(basedir)[2].count('/')
58 libpath = rpath.partition(basedir)[2].strip()
59 # otherwise (i.e. cross packages) determine a shared root based on the TMPDIR
60 # NOTE: This will not work reliably for cross packages, particularly in the case
61 # where your TMPDIR is a short path (i.e. /usr/poky) as chrpath cannot insert an
62 # rpath longer than that which is already set.
63 else:
64 depth = fpath.rpartition(tmpdir)[2].count('/')
65 libpath = rpath.partition(tmpdir)[2].strip()
66
67 base = "$ORIGIN"
68 while depth > 1:
69 base += "/.."
70 depth-=1
71 new_rpaths.append("%s%s" % (base, libpath))
72
73 # if we have modified some rpaths call chrpath to update the binary
74 if len(new_rpaths):
75 args = ":".join(new_rpaths)
76 #bb.note("Setting rpath for %s to %s" %(fpath, args))
77 sub.call([cmd, '-r', args, fpath])
78
79 if perms:
80 os.chmod(fpath, perms)
81
82def rpath_replace (path, d):
83 bindirs = d.expand("${bindir} ${sbindir} ${base_sbindir} ${base_bindir} ${libdir} ${base_libdir} ${libexecdir} ${PREPROCESS_RELOCATE_DIRS}").split()
84
85 for bindir in bindirs:
86 #bb.note ("Processing directory " + bindir)
87 directory = path + "/" + bindir
88 process_dir (directory, d)
89