Gentoo Archives: gentoo-commits

From: "Mike Frysinger (vapier)" <vapier@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] gentoo-projects commit in pax-utils: lddtree.py
Date: Wed, 30 Jul 2014 14:35:42
Message-Id: 20140730143539.1DD232004C@flycatcher.gentoo.org
1 vapier 14/07/30 14:35:39
2
3 Modified: lddtree.py
4 Log:
5 lddtree.py: save the original path as well as the full path for symlinks
6
7 SONAMEs are usually symlinks, so we need to manually dereference them to get to the right file, but we want to save the original name so we can copy them to the right place
8
9 Revision Changes Path
10 1.51 pax-utils/lddtree.py
11
12 file : http://sources.gentoo.org/viewvc.cgi/gentoo-projects/pax-utils/lddtree.py?rev=1.51&view=markup
13 plain: http://sources.gentoo.org/viewvc.cgi/gentoo-projects/pax-utils/lddtree.py?rev=1.51&content-type=text/plain
14 diff : http://sources.gentoo.org/viewvc.cgi/gentoo-projects/pax-utils/lddtree.py?r1=1.50&r2=1.51
15
16 Index: lddtree.py
17 ===================================================================
18 RCS file: /var/cvsroot/gentoo-projects/pax-utils/lddtree.py,v
19 retrieving revision 1.50
20 retrieving revision 1.51
21 diff -u -r1.50 -r1.51
22 --- lddtree.py 30 Jul 2014 08:22:07 -0000 1.50
23 +++ lddtree.py 30 Jul 2014 14:35:38 -0000 1.51
24 @@ -4,7 +4,7 @@
25 # Copyright 2012-2014 The Chromium OS Authors
26 # Use of this source code is governed by a BSD-style license (BSD-3)
27 # pylint: disable=C0301
28 -# $Header: /var/cvsroot/gentoo-projects/pax-utils/lddtree.py,v 1.50 2014/07/30 08:22:07 vapier Exp $
29 +# $Header: /var/cvsroot/gentoo-projects/pax-utils/lddtree.py,v 1.51 2014/07/30 14:35:38 vapier Exp $
30
31 # TODO: Handle symlinks.
32
33 @@ -63,6 +63,10 @@
34 def readlink(path, root, prefixed=False):
35 """Like os.readlink(), but relative to a |root|
36
37 + This does not currently handle the pathological case:
38 + /lib/foo.so -> ../../../../../../../foo.so
39 + This relies on the .. entries in / to point to itself.
40 +
41 Args:
42 path: The symlink to read
43 root: The path to use for resolving absolute symlinks
44 @@ -81,7 +85,7 @@
45 while os.path.islink(root + path):
46 path = os.path.join(os.path.dirname(path), os.readlink(root + path))
47
48 - return (root + path) if prefixed else path
49 + return normpath((root + path) if prefixed else path)
50
51
52 def makedirs(path):
53 @@ -284,7 +288,7 @@
54 debug: Enable debug output
55
56 Returns:
57 - the full path to the desired library
58 + Tuple of the full path to the desired library and the real path to it
59 """
60 dbg(debug, ' FindLib(%s)' % lib)
61
62 @@ -293,17 +297,16 @@
63 target = readlink(path, root, prefixed=True)
64 if path != target:
65 dbg(debug, ' checking: %s -> %s' % (path, target))
66 - path = target
67 else:
68 dbg(debug, ' checking:', path)
69
70 - if os.path.exists(path):
71 - with open(path, 'rb') as f:
72 + if os.path.exists(target):
73 + with open(target, 'rb') as f:
74 libelf = ELFFile(f)
75 if CompatibleELFs(elf, libelf):
76 - return path
77 + return (target, path)
78
79 - return None
80 + return (None, None)
81
82
83 def ParseELF(path, root='/', prefix='', ldpaths={'conf':[], 'env':[], 'interp':[]},
84 @@ -345,6 +348,7 @@
85 ret = {
86 'interp': None,
87 'path': path if display is None else display,
88 + 'realpath': path,
89 'needed': [],
90 'rpath': [],
91 'runpath': [],
92 @@ -367,6 +371,7 @@
93 ret['interp'] = normpath(root + interp)
94 ret['libs'][os.path.basename(interp)] = {
95 'path': ret['interp'],
96 + 'realpath': readlink(ret['interp'], root, prefixed=True),
97 'needed': [],
98 }
99 # XXX: Should read it and scan for /lib paths.
100 @@ -417,8 +422,9 @@
101 continue
102 if all_ldpaths is None:
103 all_ldpaths = rpaths + ldpaths['rpath'] + ldpaths['env'] + runpaths + ldpaths['runpath'] + ldpaths['conf'] + ldpaths['interp']
104 - fullpath = FindLib(elf, lib, all_ldpaths, root, debug=debug)
105 + realpath, fullpath = FindLib(elf, lib, all_ldpaths, root, debug=debug)
106 _all_libs[lib] = {
107 + 'realpath': realpath,
108 'path': fullpath,
109 'needed': [],
110 }
111 @@ -437,7 +443,7 @@
112
113
114 def _ShowVersion(_option, _opt, _value, _parser):
115 - d = '$Id: lddtree.py,v 1.50 2014/07/30 08:22:07 vapier Exp $'.split()
116 + d = '$Id: lddtree.py,v 1.51 2014/07/30 14:35:38 vapier Exp $'.split()
117 print('%s-%s %s %s' % (d[1].split('.')[0], d[2], d[3], d[4]))
118 sys.exit(0)
119
120 @@ -486,8 +492,9 @@
121 def _StripRoot(path):
122 return path[len(options.root) - 1:]
123
124 - def _copy(src, striproot=True, wrapit=False, libpaths=(), outdir=None):
125 - if src is None:
126 + def _copy(realsrc, src, striproot=True, wrapit=False, libpaths=(),
127 + outdir=None):
128 + if realsrc is None:
129 return
130
131 if wrapit:
132 @@ -506,7 +513,7 @@
133 try:
134 # See if they're the same file.
135 nstat = os.stat(dst + ('.elf' if wrapit else ''))
136 - ostat = os.stat(src)
137 + ostat = os.stat(realsrc)
138 for field in ('mode', 'mtime', 'size'):
139 if getattr(ostat, 'st_' + field) != \
140 getattr(nstat, 'st_' + field):
141 @@ -522,10 +529,10 @@
142
143 makedirs(os.path.dirname(dst))
144 try:
145 - shutil.copy2(src, dst)
146 + shutil.copy2(realsrc, dst)
147 except IOError:
148 os.unlink(dst)
149 - shutil.copy2(src, dst)
150 + shutil.copy2(realsrc, dst)
151
152 if wrapit:
153 if options.verbose:
154 @@ -544,10 +551,11 @@
155 # for known libs that get loaded (e.g. curl will dlopen(libresolv)).
156 libpaths = set()
157 for lib in elf['libs']:
158 - path = elf['libs'][lib]['path']
159 + libdata = elf['libs'][lib]
160 + path = libdata['realpath']
161 if not options.libdir:
162 libpaths.add(_StripRoot(os.path.dirname(path)))
163 - _copy(path, outdir=options.libdir)
164 + _copy(path, libdata['path'], outdir=options.libdir)
165
166 if not options.libdir:
167 libpaths = list(libpaths)
168 @@ -558,8 +566,10 @@
169 else:
170 libpaths.add(options.libdir)
171
172 - _copy(elf['interp'], outdir=options.libdir)
173 - _copy(elf['path'], striproot=options.auto_root,
174 + # We don't bother to copy this as ParseElf adds the interp to the 'libs',
175 + # so it was already copied in the libs loop above.
176 + #_copy(elf['interp'], outdir=options.libdir)
177 + _copy(elf['realpath'], elf['path'], striproot=options.auto_root,
178 wrapit=options.generate_wrappers, libpaths=libpaths,
179 outdir=options.bindir)
180
181 @@ -718,6 +728,7 @@
182 'runpath': [],
183 'rpath': [],
184 'path': p,
185 + 'realpath': realpath,
186 }
187 _ActionCopy(options, elf)
188 continue