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