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: Mon, 25 Mar 2013 22:36:04
Message-Id: 20130325223559.79A482171D@flycatcher.gentoo.org
1 vapier 13/03/25 22:35:59
2
3 Modified: lddtree.py
4 Log:
5 lddtree.py: when using --root, stop copying files into the output using that path too
6
7 similarly, have the files specified on the command line automatically prefix with the root path (controllable by --no-auto-root)
8
9 Revision Changes Path
10 1.25 pax-utils/lddtree.py
11
12 file : http://sources.gentoo.org/viewvc.cgi/gentoo-projects/pax-utils/lddtree.py?rev=1.25&view=markup
13 plain: http://sources.gentoo.org/viewvc.cgi/gentoo-projects/pax-utils/lddtree.py?rev=1.25&content-type=text/plain
14 diff : http://sources.gentoo.org/viewvc.cgi/gentoo-projects/pax-utils/lddtree.py?r1=1.24&r2=1.25
15
16 Index: lddtree.py
17 ===================================================================
18 RCS file: /var/cvsroot/gentoo-projects/pax-utils/lddtree.py,v
19 retrieving revision 1.24
20 retrieving revision 1.25
21 diff -u -r1.24 -r1.25
22 --- lddtree.py 24 Mar 2013 05:37:34 -0000 1.24
23 +++ lddtree.py 25 Mar 2013 22:35:59 -0000 1.25
24 @@ -3,7 +3,7 @@
25 # Copyright 2012 Mike Frysinger <vapier@g.o>
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.24 2013/03/24 05:37:34 vapier Exp $
29 +# $Header: /var/cvsroot/gentoo-projects/pax-utils/lddtree.py,v 1.25 2013/03/25 22:35:59 vapier Exp $
30
31 """Read the ELF dependency tree and show it
32
33 @@ -319,7 +319,7 @@
34
35
36 def _ShowVersion(_option, _opt, _value, _parser):
37 - d = '$Id: lddtree.py,v 1.24 2013/03/24 05:37:34 vapier Exp $'.split()
38 + d = '$Id: lddtree.py,v 1.25 2013/03/25 22:35:59 vapier Exp $'.split()
39 print('%s-%s %s %s' % (d[1].split('.')[0], d[2], d[3], d[4]))
40 sys.exit(0)
41
42 @@ -365,11 +365,16 @@
43
44 def _ActionCopy(options, elf):
45 """Copy the ELF and its dependencies to a destination tree"""
46 - def _copy(src):
47 + def _copy(src, striproot=True):
48 if src is None:
49 return
50
51 - dst = options.dest + src
52 + if striproot:
53 + subdst = src[len(options.root) - 1:]
54 + else:
55 + subdst = src
56 + dst = options.dest + subdst
57 +
58 if os.path.exists(dst):
59 # See if they're the same file.
60 ostat = os.stat(src)
61 @@ -396,7 +401,7 @@
62 os.unlink(dst)
63 shutil.copy2(src, dst)
64
65 - _copy(elf['path'])
66 + _copy(elf['path'], striproot=options.auto_root)
67 _copy(elf['interp'])
68 for lib in elf['libs']:
69 _copy(elf['libs'][lib]['path'])
70 @@ -405,14 +410,30 @@
71 def main(argv):
72 parser = optparse.OptionParser("""%prog [options] <ELFs>
73
74 -Display ELF dependencies as a tree""")
75 +Display ELF dependencies as a tree
76 +
77 +When using the --root option, all paths are implicitly prefixed by that.
78 + e.g. lddtree -R /my/magic/root /bin/bash
79 +This will load up the ELF found at /my/magic/root/bin/bash and then resolve
80 +all libraries via that path. If you wish to actually read /bin/bash (and
81 +so use the ROOT path as an alternative library tree), you can specify the
82 +--no-auto-root option.
83 +
84 +When pairing --root with --copy-to-tree, the ROOT path will be stripped.
85 + e.g. lddtree -R /my/magic/root --copy-to-tree /foo /bin/bash
86 +You will see /foo/bin/bash and /foo/lib/libc.so.6 and not paths like
87 +/foo/my/magic/root/bin/bash. If you want that, you'll have to manually
88 +add the ROOT path to the output path.""")
89 parser.add_option('-a', '--all',
90 action='store_true', default=False,
91 help=('Show all duplicated dependencies'))
92 parser.add_option('-R', '--root',
93 - dest='root', default=os.environ.get('ROOT', ''), type='string',
94 + default=os.environ.get('ROOT', ''), type='string',
95 action='callback', callback=_NormalizePath,
96 help=('Search for all files/dependencies in ROOT'))
97 + parser.add_option('--no-auto-root',
98 + dest='auto_root', action='store_false', default=True,
99 + help=('Do not automatically prefix input ELFs with ROOT'))
100 parser.add_option('--copy-to-tree',
101 dest='dest', default=None, type='string',
102 action='callback', callback=_NormalizePath,
103 @@ -449,6 +470,8 @@
104 # Process all the files specified.
105 ret = 0
106 for path in paths:
107 + if options.auto_root:
108 + path = options.root + path.lstrip('/')
109 try:
110 elf = ParseELF(path, options.root, ldpaths)
111 except (exceptions.ELFError, IOError) as e: