Lines 179-185
def ParseLdSoConf(ldso_conf, root='/', _
Link Here
|
179 |
return paths |
179 |
return paths |
180 |
|
180 |
|
181 |
|
181 |
|
182 |
def LoadLdpaths(root='/'): |
182 |
def LoadLdpaths(root='/', prefix=''): |
183 |
"""Load linker paths from common locations |
183 |
"""Load linker paths from common locations |
184 |
|
184 |
|
185 |
This parses the ld.so.conf and LD_LIBRARY_PATH env var. |
185 |
This parses the ld.so.conf and LD_LIBRARY_PATH env var. |
Lines 207-213
def LoadLdpaths(root='/'):
Link Here
|
207 |
ldpaths['env'] = ParseLdPaths(env_ldpath, path='') |
207 |
ldpaths['env'] = ParseLdPaths(env_ldpath, path='') |
208 |
|
208 |
|
209 |
# Load up /etc/ld.so.conf. |
209 |
# Load up /etc/ld.so.conf. |
210 |
ldpaths['conf'] = ParseLdSoConf(root + 'etc/ld.so.conf', root=root) |
210 |
ldpaths['conf'] = ParseLdSoConf(root + prefix + '/etc/ld.so.conf', root=root) |
211 |
|
211 |
|
212 |
return ldpaths |
212 |
return ldpaths |
213 |
|
213 |
|
Lines 254-260
def FindLib(elf, lib, ldpaths):
Link Here
|
254 |
return None |
254 |
return None |
255 |
|
255 |
|
256 |
|
256 |
|
257 |
def ParseELF(path, root='/', ldpaths={'conf':[], 'env':[], 'interp':[]}, |
257 |
def ParseELF(path, root='/', prefix='', ldpaths={'conf':[], 'env':[], 'interp':[]}, |
258 |
_first=True, _all_libs={}): |
258 |
_first=True, _all_libs={}): |
259 |
"""Parse the ELF dependency tree of the specified file |
259 |
"""Parse the ELF dependency tree of the specified file |
260 |
|
260 |
|
Lines 262-267
def ParseELF(path, root='/', ldpaths={'c
Link Here
|
262 |
path: The ELF to scan |
262 |
path: The ELF to scan |
263 |
root: The root tree to prepend to paths; this applies to interp and rpaths |
263 |
root: The root tree to prepend to paths; this applies to interp and rpaths |
264 |
only as |path| and |ldpaths| are expected to be prefixed already |
264 |
only as |path| and |ldpaths| are expected to be prefixed already |
|
|
265 |
prefix: The EPREFIX for Gentoo Prefix; this aids generating /usr/lib paths |
266 |
from interp field |
265 |
ldpaths: dict containing library paths to search; should have the keys: |
267 |
ldpaths: dict containing library paths to search; should have the keys: |
266 |
conf, env, interp |
268 |
conf, env, interp |
267 |
_first: Recursive use only; is this the first ELF ? |
269 |
_first: Recursive use only; is this the first ELF ? |
Lines 304-310
def ParseELF(path, root='/', ldpaths={'c
Link Here
|
304 |
if segment.header.p_type != 'PT_INTERP': |
306 |
if segment.header.p_type != 'PT_INTERP': |
305 |
continue |
307 |
continue |
306 |
|
308 |
|
307 |
interp = bstr(segment.get_interp_name()) |
309 |
interp = normpath(bstr(segment.get_interp_name())) |
308 |
ret['interp'] = normpath(root + interp) |
310 |
ret['interp'] = normpath(root + interp) |
309 |
ret['libs'][os.path.basename(interp)] = { |
311 |
ret['libs'][os.path.basename(interp)] = { |
310 |
'path': ret['interp'], |
312 |
'path': ret['interp'], |
Lines 313-319
def ParseELF(path, root='/', ldpaths={'c
Link Here
|
313 |
# XXX: Should read it and scan for /lib paths. |
315 |
# XXX: Should read it and scan for /lib paths. |
314 |
ldpaths['interp'] = [ |
316 |
ldpaths['interp'] = [ |
315 |
normpath(root + os.path.dirname(interp)), |
317 |
normpath(root + os.path.dirname(interp)), |
316 |
normpath(root + '/usr' + os.path.dirname(interp)), |
318 |
normpath(root + prefix + '/usr' + os.path.dirname(interp).lstrip(prefix)), |
317 |
] |
319 |
] |
318 |
break |
320 |
break |
319 |
|
321 |
|
Lines 361-367
def ParseELF(path, root='/', ldpaths={'c
Link Here
|
361 |
'needed': [], |
363 |
'needed': [], |
362 |
} |
364 |
} |
363 |
if fullpath: |
365 |
if fullpath: |
364 |
lret = ParseELF(fullpath, root, ldpaths, False, _all_libs) |
366 |
lret = ParseELF(fullpath, root, prefix, ldpaths, False, _all_libs) |
365 |
_all_libs[lib]['needed'] = lret['needed'] |
367 |
_all_libs[lib]['needed'] = lret['needed'] |
366 |
|
368 |
|
367 |
del elf |
369 |
del elf |
Lines 541-546
they need will be placed into /foo/lib/
Link Here
|
541 |
default=os.environ.get('ROOT', ''), type='string', |
543 |
default=os.environ.get('ROOT', ''), type='string', |
542 |
action='callback', callback=_NormalizePath, |
544 |
action='callback', callback=_NormalizePath, |
543 |
help='Search for all files/dependencies in ROOT') |
545 |
help='Search for all files/dependencies in ROOT') |
|
|
546 |
parser.add_option('-P', '--prefix', |
547 |
default=os.environ.get('EPREFIX', ''), type='string', |
548 |
action='callback', callback=_NormalizePath, |
549 |
help='Specify EPREFIX for binaries from Gentoo Prefix') |
544 |
parser.add_option('--no-auto-root', |
550 |
parser.add_option('--no-auto-root', |
545 |
dest='auto_root', action='store_false', default=True, |
551 |
dest='auto_root', action='store_false', default=True, |
546 |
help='Do not automatically prefix input ELFs with ROOT') |
552 |
help='Do not automatically prefix input ELFs with ROOT') |
Lines 595-601
they need will be placed into /foo/lib/
Link Here
|
595 |
if not paths: |
601 |
if not paths: |
596 |
err('missing ELF files to scan') |
602 |
err('missing ELF files to scan') |
597 |
|
603 |
|
598 |
ldpaths = LoadLdpaths(options.root) |
604 |
ldpaths = LoadLdpaths(options.root, options.prefix) |
599 |
if options.debug: |
605 |
if options.debug: |
600 |
print('ldpaths[conf] =', ldpaths['conf']) |
606 |
print('ldpaths[conf] =', ldpaths['conf']) |
601 |
print('ldpaths[env] =', ldpaths['env']) |
607 |
print('ldpaths[env] =', ldpaths['env']) |
Lines 613-619
they need will be placed into /foo/lib/
Link Here
|
613 |
for p in glob.iglob(path): |
619 |
for p in glob.iglob(path): |
614 |
matched = True |
620 |
matched = True |
615 |
try: |
621 |
try: |
616 |
elf = ParseELF(p, options.root, ldpaths) |
622 |
elf = ParseELF(p, options.root, options.prefix, ldpaths) |
617 |
except (exceptions.ELFError, IOError) as e: |
623 |
except (exceptions.ELFError, IOError) as e: |
618 |
# XXX: Ugly. Should unify with _Action* somehow. |
624 |
# XXX: Ugly. Should unify with _Action* somehow. |
619 |
if options.dest is not None and options.copy_non_elfs: |
625 |
if options.dest is not None and options.copy_non_elfs: |