@@ -106,12 +106,12 @@ def parse_ld_paths(str_ldpaths: str, path: str, root: str = "") -> list[str]:
106
106
for ldpath in str_ldpaths .split (":" ):
107
107
if ldpath == "" :
108
108
# The ldso treats "" paths as $PWD.
109
- ldpath = os .getcwd ()
109
+ ldpath_ = os .getcwd ()
110
110
elif "$ORIGIN" in ldpath :
111
- ldpath = ldpath .replace ("$ORIGIN" , os .path .dirname (os .path .abspath (path )))
111
+ ldpath_ = ldpath .replace ("$ORIGIN" , os .path .dirname (os .path .abspath (path )))
112
112
else :
113
- ldpath = root + ldpath
114
- ldpaths .append (normpath (ldpath ))
113
+ ldpath_ = root + ldpath
114
+ ldpaths .append (normpath (ldpath_ ))
115
115
return [p for p in dedupe (ldpaths ) if os .path .isdir (p )]
116
116
117
117
@@ -140,8 +140,8 @@ def parse_ld_so_conf(ldso_conf: str, root: str = "/", _first: bool = True) -> li
140
140
try :
141
141
log .debug ("%sparse_ld_so_conf(%s)" , dbg_pfx , ldso_conf )
142
142
with open (ldso_conf ) as f :
143
- for line in f .readlines ():
144
- line = line .split ("#" , 1 )[0 ].strip ()
143
+ for input_line in f .readlines ():
144
+ line = input_line .split ("#" , 1 )[0 ].strip ()
145
145
if not line :
146
146
continue
147
147
if line .startswith ("include " ):
@@ -242,15 +242,7 @@ def compatible_elfs(elf1: ELFFile, elf2: ELFFile) -> bool:
242
242
"""
243
243
osabis = frozenset (e .header ["e_ident" ]["EI_OSABI" ] for e in (elf1 , elf2 ))
244
244
compat_sets = (
245
- frozenset (
246
- "ELFOSABI_%s" % x
247
- for x in (
248
- "NONE" ,
249
- "SYSV" ,
250
- "GNU" ,
251
- "LINUX" ,
252
- )
253
- ),
245
+ frozenset (f"ELFOSABI_{ x } " for x in ("NONE" , "SYSV" , "GNU" , "LINUX" )),
254
246
)
255
247
return (
256
248
(len (osabis ) == 1 or any (osabis .issubset (x ) for x in compat_sets ))
@@ -302,8 +294,7 @@ def lddtree(
302
294
ldpaths : dict [str , list [str ]] | None = None ,
303
295
display : str | None = None ,
304
296
exclude : frozenset [str ] = frozenset (),
305
- _first : bool = True ,
306
- _all_libs : dict = {},
297
+ _all_libs : dict | None = None ,
307
298
) -> dict :
308
299
"""Parse the ELF dependency tree of the specified file
309
300
@@ -324,8 +315,6 @@ def lddtree(
324
315
The path to show rather than ``path``
325
316
exclude
326
317
List of soname (DT_NEEDED) to exclude from the tree
327
- _first
328
- Recursive use only; is this the first ELF?
329
318
_all_libs
330
319
Recursive use only; dict of all libs we've seen
331
320
@@ -350,7 +339,8 @@ def lddtree(
350
339
if not ldpaths :
351
340
ldpaths = load_ld_paths ().copy ()
352
341
353
- if _first :
342
+ _first = _all_libs is None
343
+ if _all_libs is None :
354
344
_all_libs = {}
355
345
356
346
ret : dict [str , Any ] = {
@@ -363,7 +353,7 @@ def lddtree(
363
353
"libs" : _all_libs ,
364
354
}
365
355
366
- log .debug ("lddtree(%s)" % path )
356
+ log .debug ("lddtree(%s)" , path )
367
357
368
358
with open (path , "rb" ) as f :
369
359
elf = ELFFile (f )
@@ -407,7 +397,7 @@ def lddtree(
407
397
runpaths = parse_ld_paths (t .runpath , path = path , root = root )
408
398
elif t .entry .d_tag == "DT_NEEDED" :
409
399
if any (fnmatch (t .needed , e ) for e in exclude ):
410
- log .info (f "Excluding { t .needed } " )
400
+ log .info ("Excluding %s" , t .needed )
411
401
else :
412
402
libs .append (t .needed )
413
403
if runpaths :
@@ -457,7 +447,6 @@ def lddtree(
457
447
ldpaths ,
458
448
display = fullpath ,
459
449
exclude = exclude ,
460
- _first = False ,
461
450
_all_libs = _all_libs ,
462
451
)
463
452
_all_libs [lib ]["needed" ] = lret ["needed" ]
0 commit comments