From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) by finch.gentoo.org (Postfix) with ESMTP id 881861391DB for ; Thu, 20 Mar 2014 08:25:48 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 25DD5E0A6B; Thu, 20 Mar 2014 08:25:48 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id A1BDEE0A6B for ; Thu, 20 Mar 2014 08:25:47 +0000 (UTC) Received: from flycatcher.gentoo.org (flycatcher.gentoo.org [81.93.255.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id AAADB33FC65 for ; Thu, 20 Mar 2014 08:25:46 +0000 (UTC) Received: by flycatcher.gentoo.org (Postfix, from userid 559) id 7AF0C2004C; Thu, 20 Mar 2014 08:25:45 +0000 (UTC) From: "Mike Frysinger (vapier)" To: gentoo-commits@lists.gentoo.org Reply-To: gentoo-dev@lists.gentoo.org, vapier@gentoo.org Subject: [gentoo-commits] gentoo-projects commit in pax-utils: lddtree.py X-VCS-Repository: gentoo-projects X-VCS-Files: lddtree.py X-VCS-Directories: pax-utils X-VCS-Committer: vapier X-VCS-Committer-Name: Mike Frysinger Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Message-Id: <20140320082545.7AF0C2004C@flycatcher.gentoo.org> Date: Thu, 20 Mar 2014 08:25:45 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org X-Archives-Salt: 2e3bc7b7-670b-45f3-b6d4-d8b2304c53a0 X-Archives-Hash: 9d86eaef1fb66187f6ba370f07d9d0e0 vapier 14/03/20 08:25:45 Modified: lddtree.py Log: lddtree.py: initial prefix support by Benda Xu #488460 Revision Changes Path 1.44 pax-utils/lddtree.py file : http://sources.gentoo.org/viewvc.cgi/gentoo-projects/pax-utils/lddtree.py?rev=1.44&view=markup plain: http://sources.gentoo.org/viewvc.cgi/gentoo-projects/pax-utils/lddtree.py?rev=1.44&content-type=text/plain diff : http://sources.gentoo.org/viewvc.cgi/gentoo-projects/pax-utils/lddtree.py?r1=1.43&r2=1.44 Index: lddtree.py =================================================================== RCS file: /var/cvsroot/gentoo-projects/pax-utils/lddtree.py,v retrieving revision 1.43 retrieving revision 1.44 diff -u -r1.43 -r1.44 --- lddtree.py 20 Mar 2014 08:18:06 -0000 1.43 +++ lddtree.py 20 Mar 2014 08:25:45 -0000 1.44 @@ -3,7 +3,7 @@ # Copyright 2012-2013 Mike Frysinger # Use of this source code is governed by a BSD-style license (BSD-3) # pylint: disable=C0301 -# $Header: /var/cvsroot/gentoo-projects/pax-utils/lddtree.py,v 1.43 2014/03/20 08:18:06 vapier Exp $ +# $Header: /var/cvsroot/gentoo-projects/pax-utils/lddtree.py,v 1.44 2014/03/20 08:25:45 vapier Exp $ # TODO: Handle symlinks. @@ -184,13 +184,14 @@ return paths -def LoadLdpaths(root='/'): +def LoadLdpaths(root='/', prefix=''): """Load linker paths from common locations This parses the ld.so.conf and LD_LIBRARY_PATH env var. Args: root: The root tree to prepend to paths + prefix: The path under |root| to search Returns: dict containing library paths to search @@ -213,7 +214,7 @@ ldpaths['env'] = ParseLdPaths(env_ldpath, path='') # Load up /etc/ld.so.conf. - ldpaths['conf'] = ParseLdSoConf(root + 'etc/ld.so.conf', root=root) + ldpaths['conf'] = ParseLdSoConf(root + prefix + '/etc/ld.so.conf', root=root) return ldpaths @@ -262,7 +263,7 @@ return None -def ParseELF(path, root='/', ldpaths={'conf':[], 'env':[], 'interp':[]}, +def ParseELF(path, root='/', prefix='', ldpaths={'conf':[], 'env':[], 'interp':[]}, _first=True, _all_libs={}): """Parse the ELF dependency tree of the specified file @@ -270,6 +271,7 @@ path: The ELF to scan root: The root tree to prepend to paths; this applies to interp and rpaths only as |path| and |ldpaths| are expected to be prefixed already + prefix: The path under |root| to search ldpaths: dict containing library paths to search; should have the keys: conf, env, interp _first: Recursive use only; is this the first ELF ? @@ -322,7 +324,7 @@ # XXX: Should read it and scan for /lib paths. ldpaths['interp'] = [ normpath(root + os.path.dirname(interp)), - normpath(root + '/usr' + os.path.dirname(interp)), + normpath(root + prefix + '/usr' + os.path.dirname(interp).lstrip(prefix)), ] break @@ -370,7 +372,7 @@ 'needed': [], } if fullpath: - lret = ParseELF(fullpath, root, ldpaths, False, _all_libs) + lret = ParseELF(fullpath, root, prefix, ldpaths, False, _all_libs) _all_libs[lib]['needed'] = lret['needed'] del elf @@ -383,7 +385,7 @@ def _ShowVersion(_option, _opt, _value, _parser): - d = '$Id: lddtree.py,v 1.43 2014/03/20 08:18:06 vapier Exp $'.split() + d = '$Id: lddtree.py,v 1.44 2014/03/20 08:25:45 vapier Exp $'.split() print('%s-%s %s %s' % (d[1].split('.')[0], d[2], d[3], d[4])) sys.exit(0) @@ -550,6 +552,10 @@ default=os.environ.get('ROOT', ''), type='string', action='callback', callback=_NormalizePath, help='Search for all files/dependencies in ROOT') + parser.add_option('-P', '--prefix', + default=os.environ.get('EPREFIX', '@GENTOO_PORTAGE_EPREFIX@'), type='string', + action='callback', callback=_NormalizePath, + help='Specify EPREFIX for binaries (for Gentoo Prefix)') parser.add_option('--no-auto-root', dest='auto_root', action='store_false', default=True, help='Do not automatically prefix input ELFs with ROOT') @@ -594,6 +600,8 @@ if options.root != '/': options.root += '/' + if options.prefix == '@''GENTOO_PORTAGE_EPREFIX''@': + options.prefix = '' if options.bindir and options.bindir[0] != '/': parser.error('--bindir accepts absolute paths only') @@ -610,7 +618,7 @@ if not paths: err('missing ELF files to scan') - ldpaths = LoadLdpaths(options.root) + ldpaths = LoadLdpaths(options.root, options.prefix) if options.debug: print('ldpaths[conf] =', ldpaths['conf']) print('ldpaths[env] =', ldpaths['env']) @@ -628,7 +636,7 @@ for p in glob.iglob(path): matched = True try: - elf = ParseELF(p, options.root, ldpaths) + elf = ParseELF(p, options.root, options.prefix, ldpaths) except exceptions.ELFError as e: if options.skip_non_elfs: continue