6
6
7
7
from typing import TYPE_CHECKING
8
8
9
- from .._shutil import Run
10
9
from .rpath import RpathWheelRepairer
11
10
12
11
if TYPE_CHECKING :
@@ -28,17 +27,24 @@ class LinuxWheelRepairer(RpathWheelRepairer):
28
27
_origin_symbol = "$ORIGIN"
29
28
30
29
def get_library_rpath (self , artifact : Path ) -> list [str ]:
31
- from auditwheel . elfutils import elf_read_rpaths
30
+ import lief . ELF
32
31
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 )
38
38
39
39
def patch_library_rpath (self , artifact : Path , rpaths : list [str ]) -> None :
40
40
final_rpaths = set (rpaths )
41
41
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