Merge lp:~jml/pkgme-devportal/remove-ldd into lp:pkgme-devportal

Proposed by Jonathan Lange
Status: Merged
Approved by: James Westby
Approved revision: 19
Merged at revision: 21
Proposed branch: lp:~jml/pkgme-devportal/remove-ldd
Merge into: lp:pkgme-devportal
Diff against target: 128 lines (+2/-95)
2 files modified
devportalbinary/binary.py (+2/-57)
devportalbinary/tests/test_binary.py (+0/-38)
To merge this branch: bzr merge lp:~jml/pkgme-devportal/remove-ldd
Reviewer Review Type Date Requested Status
James Westby Approve
Review via email: mp+84942@code.launchpad.net

Commit message

Remove the obsolete ldd code and tests.

Description of the change

Bug 901439 points out that the ldd tests fail on lucid. Since ldd is no longer actually used by pkgme-binary, this branch just deletes the code and the tests.

In addition, it removes the strategy pattern from get_shared_library_dependencies. Instead of taking a function that calculates libraries, it's now hard-coded to use objdump.

To post a comment you must log in.
Revision history for this message
James Westby (james-w) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'devportalbinary/binary.py'
--- devportalbinary/binary.py 2011-11-23 12:25:33 +0000
+++ devportalbinary/binary.py 2011-12-08 13:02:26 +0000
@@ -190,66 +190,11 @@
190 return libraries190 return libraries
191191
192192
193def ldd(binary_paths):193def get_shared_library_dependencies(paths):
194 # ldd has output of the form:
195 #
196 # path/to/elf/object:
197 # linux-vdso.so.1 => (0x00007fff4a7ff000)
198 # libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f7472623000)
199 # /lib64/ld-linux-x86-64.so.2 (0x00007f74729e5000)
200 #
201 # i.e.
202 # <name> => (not found|<path> (<address>))
203 #
204 # where <name> and <path> are both optional. If <name> is not given, then
205 # there is no arrow (=>).
206 binary_paths = list(binary_paths)
207 if not binary_paths:
208 return {}
209 cmd = ['ldd'] + binary_paths
210 output = subprocess.Popen(cmd, stdout=subprocess.PIPE).communicate()[0]
211 libraries = {}
212 current = []
213 if len(binary_paths) == 1:
214 libraries[binary_paths[0]] = current
215 for line in output.splitlines():
216 if line.endswith(':'):
217 current.sort()
218 current = libraries[line.strip(':')] = []
219 continue
220 tokens = line.split()
221 name, path = None, None
222 if '=>' in tokens:
223 name = tokens[0]
224 if (len(tokens) > 2
225 and tokens[2:] != ['not', 'found']
226 and not (tokens[2].startswith('(')
227 and tokens[2].endswith(')'))):
228 path = tokens[2]
229 else:
230 path = tokens[0]
231 current.append((name, path))
232 current.sort()
233 return libraries
234
235
236def needed_libraries_from_ldd(binary_paths):
237 # We don't consider virtual DSOs generated by the kernel, or libraries
238 # without actual names to be dependencies.
239 BLACKLIST = ['linux-vdso.so.1', 'linux-gate.so.1', None]
240 libs = ldd(binary_paths)
241 new_libs = {}
242 for path in libs:
243 new_libs[path] = [
244 name for name, path in libs[path] if name not in BLACKLIST]
245 return new_libs
246
247
248def get_shared_library_dependencies(paths, library_finder=needed_libraries_from_objdump):
249 """Find all of the shared libraries depended on the ELF binaries in 'paths'.194 """Find all of the shared libraries depended on the ELF binaries in 'paths'.
250 """195 """
251 so_names = set()196 so_names = set()
252 libraries = library_finder(paths)197 libraries = needed_libraries_from_objdump(paths)
253 for libs in libraries.values():198 for libs in libraries.values():
254 for name in libs:199 for name in libs:
255 so_names.add(name)200 so_names.add(name)
256201
=== modified file 'devportalbinary/tests/test_binary.py'
--- devportalbinary/tests/test_binary.py 2011-11-23 12:25:33 +0000
+++ devportalbinary/tests/test_binary.py 2011-12-08 13:02:26 +0000
@@ -22,7 +22,6 @@
22 guess_executable,22 guess_executable,
23 iter_binaries,23 iter_binaries,
24 iter_executables,24 iter_executables,
25 ldd,
26 METADATA_FILE,25 METADATA_FILE,
27 needed_libraries_from_objdump,26 needed_libraries_from_objdump,
28 NoBinariesFound,27 NoBinariesFound,
@@ -295,43 +294,6 @@
295294
296class GetSharedLibraryDependenciesTests(TestCase):295class GetSharedLibraryDependenciesTests(TestCase):
297296
298 def test_ldd_none(self):
299 deps = ldd([])
300 self.assertEqual({}, deps)
301
302 def test_ldd(self):
303 hello = os.path.join(os.path.dirname(__file__), 'hello')
304 deps = ldd([hello])
305 self.assertEqual(
306 {hello: [(None, '/lib64/ld-linux-x86-64.so.2'),
307 ('libc.so.6', '/lib/x86_64-linux-gnu/libc.so.6'),
308 ('linux-vdso.so.1', None)]},
309 deps)
310
311 def test_ldd_not_found(self):
312 hello = os.path.join(os.path.dirname(__file__), 'hello-missing-deps')
313 deps = ldd([hello])
314 self.assertEqual(
315 {hello: [(None, '/lib64/ld-linux-x86-64.so.2'),
316 ('libc.so.6', '/lib/x86_64-linux-gnu/libc.so.6'),
317 ('libnowaythisexists.so.1', None),
318 ('linux-vdso.so.1', None),
319 ]},
320 deps)
321
322 def test_ldd_multiple(self):
323 hello = os.path.join(os.path.dirname(__file__), 'hello')
324 simple = os.path.join(os.path.dirname(__file__), 'simple.so.1')
325 deps = ldd([hello, simple])
326 self.assertEqual(
327 {hello: [(None, '/lib64/ld-linux-x86-64.so.2'),
328 ('libc.so.6', '/lib/x86_64-linux-gnu/libc.so.6'),
329 ('linux-vdso.so.1', None)],
330 simple: [(None, '/lib64/ld-linux-x86-64.so.2'),
331 ('libc.so.6', '/lib/x86_64-linux-gnu/libc.so.6'),
332 ('linux-vdso.so.1', None)]},
333 deps)
334
335 def test_get_shared_library_dependencies(self):297 def test_get_shared_library_dependencies(self):
336 hello = os.path.join(os.path.dirname(__file__), 'hello')298 hello = os.path.join(os.path.dirname(__file__), 'hello')
337 deps = get_shared_library_dependencies([hello])299 deps = get_shared_library_dependencies([hello])

Subscribers

People subscribed via source and target branches