66
77from typing import TYPE_CHECKING
88
9- from .._shutil import Run
109from .rpath import RpathWheelRepairer
1110
1211if TYPE_CHECKING :
@@ -28,17 +27,24 @@ class LinuxWheelRepairer(RpathWheelRepairer):
2827 _origin_symbol = "$ORIGIN"
2928
3029 def get_library_rpath (self , artifact : Path ) -> list [str ]:
31- from auditwheel . elfutils import elf_read_rpaths
30+ import lief . ELF
3231
33- return [
34- path
35- for dt_rpaths in elf_read_rpaths (artifact ).values ()
36- for path in dt_rpaths
37- ]
32+ elf = lief .ELF .parse (artifact )
33+ if not elf .has (lief .ELF .DynamicEntry .TAG .RUNPATH ):
34+ # Early exit if library does not have rpaths
35+ return []
36+ elf_rpaths = elf .get (lief .ELF .DynamicEntry .TAG .RUNPATH )
37+ return list (elf_rpaths .paths )
3838
3939 def patch_library_rpath (self , artifact : Path , rpaths : list [str ]) -> None :
4040 final_rpaths = set (rpaths )
4141 if final_rpaths :
42- run = Run ()
43- run .live ("patchelf" , "--remove-rpath" , artifact )
44- run .live ("patchelf" , "--set-rpath" , ":" .join (final_rpaths ), artifact )
42+ import lief .ELF
43+
44+ elf_rpaths = lief .ELF .DynamicEntryRunPath ()
45+ for rpath in final_rpaths :
46+ elf_rpaths .append (rpath )
47+ elf = lief .ELF .parse (artifact )
48+ elf .remove (lief .ELF .DynamicEntry .TAG .RUNPATH )
49+ elf .add (elf_rpaths )
50+ elf .write (str (artifact ))
0 commit comments