10
10
from pathlib import Path
11
11
from typing import Optional , TypeVar
12
12
13
+ from elftools .elf .elffile import ELFFile
14
+
15
+ from auditwheel .pool import POOL
16
+
13
17
from . import json
14
18
from .architecture import Architecture
15
19
from .elfutils import (
@@ -94,6 +98,55 @@ def get_wheel_elfdata(
94
98
shared_libraries_with_invalid_machine = []
95
99
96
100
platform_wheel = False
101
+
102
+ def inner (fn : Path , elf : ELFFile ) -> None :
103
+ nonlocal \
104
+ platform_wheel , \
105
+ shared_libraries_in_purelib , \
106
+ uses_ucs2_symbols , \
107
+ uses_PyFPE_jbuf
108
+
109
+ so_name = fn .name
110
+
111
+ log .debug ("processing: %s" , fn )
112
+ elftree = ldd (fn , exclude = exclude )
113
+
114
+ try :
115
+ arch = elftree .platform .baseline_architecture
116
+ if arch != wheel_policy .architecture .baseline :
117
+ shared_libraries_with_invalid_machine .append (so_name )
118
+ log .warning ("ignoring: %s with %s architecture" , so_name , arch )
119
+ return
120
+ except ValueError :
121
+ shared_libraries_with_invalid_machine .append (so_name )
122
+ log .warning ("ignoring: %s with unknown architecture" , so_name )
123
+ return
124
+
125
+ platform_wheel = True
126
+
127
+ for key , value in elf_find_versioned_symbols (elf ):
128
+ log .debug ("key %s, value %s" , key , value )
129
+ versioned_symbols [key ].add (value )
130
+
131
+ is_py_ext , py_ver = elf_is_python_extension (fn , elf )
132
+
133
+ # If the ELF is a Python extention, we definitely need to
134
+ # include its external dependencies.
135
+ if is_py_ext :
136
+ full_elftree [fn ] = elftree
137
+ uses_PyFPE_jbuf |= elf_references_PyFPE_jbuf (elf )
138
+ if py_ver == 2 :
139
+ uses_ucs2_symbols |= any (True for _ in elf_find_ucs2_symbols (elf ))
140
+ full_external_refs [fn ] = wheel_policy .lddtree_external_references (
141
+ elftree , ctx .path
142
+ )
143
+ else :
144
+ # If the ELF is not a Python extension, it might be
145
+ # included in the wheel already because auditwheel repair
146
+ # vendored it, so we will check whether we should include
147
+ # its internal references later.
148
+ nonpy_elftree [fn ] = elftree
149
+
97
150
for fn , elf in elf_file_filter (ctx .iter_files ()):
98
151
# Check for invalid binary wheel format: no shared library should
99
152
# be found in purelib
@@ -104,49 +157,8 @@ def get_wheel_elfdata(
104
157
if any (p .name == "purelib" for p in fn .parents ):
105
158
shared_libraries_in_purelib .append (so_name )
106
159
107
- # If at least one shared library exists in purelib, this is going
108
- # to fail and there's no need to do further checks
109
160
if not shared_libraries_in_purelib :
110
- log .debug ("processing: %s" , fn )
111
- elftree = ldd (fn , exclude = exclude )
112
-
113
- try :
114
- arch = elftree .platform .baseline_architecture
115
- if arch != wheel_policy .architecture .baseline :
116
- shared_libraries_with_invalid_machine .append (so_name )
117
- log .warning ("ignoring: %s with %s architecture" , so_name , arch )
118
- continue
119
- except ValueError :
120
- shared_libraries_with_invalid_machine .append (so_name )
121
- log .warning ("ignoring: %s with unknown architecture" , so_name )
122
- continue
123
-
124
- platform_wheel = True
125
-
126
- for key , value in elf_find_versioned_symbols (elf ):
127
- log .debug ("key %s, value %s" , key , value )
128
- versioned_symbols [key ].add (value )
129
-
130
- is_py_ext , py_ver = elf_is_python_extension (fn , elf )
131
-
132
- # If the ELF is a Python extention, we definitely need to
133
- # include its external dependencies.
134
- if is_py_ext :
135
- full_elftree [fn ] = elftree
136
- uses_PyFPE_jbuf |= elf_references_PyFPE_jbuf (elf )
137
- if py_ver == 2 :
138
- uses_ucs2_symbols |= any (
139
- True for _ in elf_find_ucs2_symbols (elf )
140
- )
141
- full_external_refs [fn ] = wheel_policy .lddtree_external_references (
142
- elftree , ctx .path
143
- )
144
- else :
145
- # If the ELF is not a Python extension, it might be
146
- # included in the wheel already because auditwheel repair
147
- # vendored it, so we will check whether we should include
148
- # its internal references later.
149
- nonpy_elftree [fn ] = elftree
161
+ POOL .submit (fn , inner , fn , elf )
150
162
151
163
# If at least one shared library exists in purelib, raise an error
152
164
if shared_libraries_in_purelib :
@@ -164,6 +176,8 @@ def get_wheel_elfdata(
164
176
wheel_policy .architecture , shared_libraries_with_invalid_machine
165
177
)
166
178
179
+ POOL .wait ()
180
+
167
181
# Get a list of all external libraries needed by ELFs in the wheel.
168
182
needed_libs = {
169
183
lib
0 commit comments