14
14
from subprocess import check_call
15
15
16
16
from auditwheel .patcher import ElfPatcher
17
- from auditwheel .pool import POOL
18
17
19
18
from .elfutils import elf_read_dt_needed , elf_read_rpaths , is_subdir
20
19
from .hashfile import hashfile
21
20
from .policy import WheelPolicies , get_replace_platforms
21
+ from .pool import POOL
22
22
from .wheel_abi import get_wheel_elfdata
23
23
from .wheeltools import InWheelCtx , add_platforms
24
24
@@ -83,25 +83,32 @@ def repair_wheel(
83
83
84
84
if not dest_dir .exists ():
85
85
dest_dir .mkdir ()
86
- new_soname , new_path = copylib (src_path , dest_dir , patcher , dry = True )
87
- if new_path not in POOL :
88
- POOL .submit (new_path , copylib , src_path , dest_dir , patcher )
89
- soname_map [soname ] = (new_soname , new_path )
90
- replacements .append ((soname , new_soname ))
86
+ new_soname , new_path = get_new_soname (src_path , dest_dir )
87
+ if soname not in soname_map :
88
+ soname_map [soname ] = (new_soname , new_path )
89
+ replacements .append ((soname , new_soname ))
91
90
92
- POOL .wait ( )
91
+ POOL .submit ( new_path , copylib , src_path , dest_dir , patcher )
93
92
94
93
if replacements :
95
- patcher .replace_needed ( fn , * replacements )
94
+ POOL . submit ( fn , patcher .replace_needed , fn , * replacements )
96
95
97
96
if len (ext_libs ) > 0 :
98
- new_fn = fn
99
- if _path_is_script (fn ):
100
- new_fn = _replace_elf_script_with_shim (match .group ("name" ), fn )
101
97
102
- new_rpath = os .path .relpath (dest_dir , new_fn .parent )
103
- new_rpath = os .path .join ("$ORIGIN" , new_rpath )
104
- append_rpath_within_wheel (new_fn , new_rpath , ctx .name , patcher )
98
+ def _patch_fn (fn : Path ) -> None :
99
+ new_fn = fn
100
+ if _path_is_script (fn ):
101
+ POOL .wait (fn )
102
+ new_fn = _replace_elf_script_with_shim (match .group ("name" ), fn )
103
+
104
+ new_rpath = os .path .relpath (dest_dir , new_fn .parent )
105
+ new_rpath = os .path .join ("$ORIGIN" , new_rpath )
106
+
107
+ append_rpath_within_wheel (new_fn , new_rpath , ctx .name , patcher )
108
+
109
+ POOL .submit_chain (fn , _patch_fn )
110
+
111
+ POOL .wait ()
105
112
106
113
# we grafted in a bunch of libraries and modified their sonames, but
107
114
# they may have internal dependencies (DT_NEEDED) on one another, so
@@ -133,9 +140,21 @@ def strip_symbols(libraries: Iterable[Path]) -> None:
133
140
check_call (["strip" , "-s" , lib ])
134
141
135
142
136
- def copylib (
137
- src_path : Path , dest_dir : Path , patcher : ElfPatcher , dry : bool = False
138
- ) -> tuple [str , Path ]:
143
+ def get_new_soname (src_path : Path , dest_dir : Path ) -> tuple [str , Path ]:
144
+ with open (src_path , "rb" ) as f :
145
+ shorthash = hashfile (f )[:8 ]
146
+ src_name = src_path .name
147
+ base , ext = src_name .split ("." , 1 )
148
+ if not base .endswith (f"-{ shorthash } " ):
149
+ new_soname = f"{ base } -{ shorthash } .{ ext } "
150
+ else :
151
+ new_soname = src_name
152
+
153
+ dest_path = dest_dir / new_soname
154
+ return new_soname , dest_path
155
+
156
+
157
+ def copylib (src_path : Path , dest_dir : Path , patcher : ElfPatcher ) -> None :
139
158
"""Graft a shared library from the system into the wheel and update the
140
159
relevant links.
141
160
@@ -148,19 +167,10 @@ def copylib(
148
167
# if the library has a RUNPATH/RPATH we clear it and set RPATH to point to
149
168
# its new location.
150
169
151
- with open (src_path , "rb" ) as f :
152
- shorthash = hashfile (f )[:8 ]
170
+ new_soname , dest_path = get_new_soname (src_path , dest_dir )
153
171
154
- src_name = src_path .name
155
- base , ext = src_name .split ("." , 1 )
156
- if not base .endswith (f"-{ shorthash } " ):
157
- new_soname = f"{ base } -{ shorthash } .{ ext } "
158
- else :
159
- new_soname = src_name
160
-
161
- dest_path = dest_dir / new_soname
162
- if dry or dest_path .exists ():
163
- return new_soname , dest_path
172
+ if dest_path .exists ():
173
+ return
164
174
165
175
logger .debug ("Grafting: %s -> %s" , src_path , dest_path )
166
176
rpaths = elf_read_rpaths (src_path )
@@ -174,8 +184,6 @@ def copylib(
174
184
if any (itertools .chain (rpaths ["rpaths" ], rpaths ["runpaths" ])):
175
185
patcher .set_rpath (dest_path , "$ORIGIN" )
176
186
177
- return new_soname , dest_path
178
-
179
187
180
188
def append_rpath_within_wheel (
181
189
lib_name : Path , rpath : str , wheel_base_dir : Path , patcher : ElfPatcher
0 commit comments