@@ -27,35 +27,39 @@ def get_rpath(self, file_name: Path) -> str:
2727 raise NotImplementedError
2828
2929
30- def _verify_patchelf () -> None :
31- """This function looks for the ``patchelf`` external binary in the PATH,
30+ def _verify_patchelf () -> str :
31+ """This function looks for the ``lief-patchelf`` or `` patchelf`` external binary in the PATH,
3232 checks for the required version, and throws an exception if a proper
3333 version can't be found. Otherwise, silence is golden
3434 """
35- if not which ("patchelf" ):
36- msg = "Cannot find required utility `patchelf` in PATH"
37- raise ValueError (msg )
38- try :
39- version = check_output (["patchelf" , "--version" ]).decode ("utf-8" )
40- except CalledProcessError :
41- msg = "Could not call `patchelf` binary"
42- raise ValueError (msg ) from None
43-
44- m = re .match (r"patchelf\s+(\d+(.\d+)?)" , version )
45- if m and tuple (int (x ) for x in m .group (1 ).split ("." )) >= (0 , 14 ):
46- return
47- msg = f"patchelf { version } found. auditwheel repair requires patchelf >= 0.14."
48- raise ValueError (msg )
35+ result = which ("lief-patchelf" )
36+ if result is None :
37+ result = which ("patchelf" )
38+ if not result :
39+ msg = "Cannot find required utility `patchelf` in PATH"
40+ raise ValueError (msg )
41+ try :
42+ version = check_output (["patchelf" , "--version" ]).decode ("utf-8" )
43+ except CalledProcessError :
44+ msg = "Could not call `patchelf` binary"
45+ raise ValueError (msg ) from None
46+
47+ m = re .match (r"patchelf\s+(\d+(.\d+)?)" , version )
48+ if not (m and tuple (int (x ) for x in m .group (1 ).split ("." )) >= (0 , 14 )):
49+ msg = f"patchelf { version } found. auditwheel repair requires patchelf >= 0.14."
50+ raise ValueError (msg )
51+
52+ return result
4953
5054
5155class Patchelf (ElfPatcher ):
5256 def __init__ (self ) -> None :
53- _verify_patchelf ()
57+ self . patchelf_path = _verify_patchelf ()
5458
5559 def replace_needed (self , file_name : Path , * old_new_pairs : tuple [str , str ]) -> None :
5660 check_call (
5761 [
58- "patchelf" ,
62+ self . patchelf_path ,
5963 * chain .from_iterable (("--replace-needed" , * pair ) for pair in old_new_pairs ),
6064 file_name ,
6165 ],
@@ -64,18 +68,20 @@ def replace_needed(self, file_name: Path, *old_new_pairs: tuple[str, str]) -> No
6468 def remove_needed (self , file_name : Path , * sonames : str ) -> None :
6569 check_call (
6670 [
67- "patchelf" ,
71+ self . patchelf_path ,
6872 * chain .from_iterable (("--remove-needed" , soname ) for soname in sonames ),
6973 file_name ,
7074 ],
7175 )
7276
7377 def set_soname (self , file_name : Path , new_so_name : str ) -> None :
74- check_call (["patchelf" , "--set-soname" , new_so_name , file_name ])
78+ check_call ([self . patchelf_path , "--set-soname" , new_so_name , file_name ])
7579
7680 def set_rpath (self , file_name : Path , rpath : str ) -> None :
77- check_call (["patchelf" , "--remove-rpath" , file_name ])
78- check_call (["patchelf" , "--force-rpath" , "--set-rpath" , rpath , file_name ])
81+ check_call ([self . patchelf_path , "--remove-rpath" , file_name ])
82+ check_call ([self . patchelf_path , "--force-rpath" , "--set-rpath" , rpath , file_name ])
7983
8084 def get_rpath (self , file_name : Path ) -> str :
81- return check_output (["patchelf" , "--print-rpath" , file_name ]).decode ("utf-8" ).strip ()
85+ return (
86+ check_output ([self .patchelf_path , "--print-rpath" , file_name ]).decode ("utf-8" ).strip ()
87+ )
0 commit comments