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