Skip to content

Commit 80b7152

Browse files
committed
chore: remove duplicate libraries
1 parent 6f6e921 commit 80b7152

File tree

1 file changed

+20
-5
lines changed

1 file changed

+20
-5
lines changed

src/auditwheel/repair.py

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@
55
import re
66
import shutil
77
import stat
8-
from collections import OrderedDict
8+
from collections import OrderedDict, defaultdict
99
from os.path import abspath, basename, dirname, exists, isabs
1010
from os.path import join as pjoin
1111
from subprocess import check_call
12-
from typing import Dict, Iterable, List, Optional, Tuple
12+
from typing import Dict, Iterable, List, Optional, Set, Tuple
1313

1414
from auditwheel.patcher import ElfPatcher
1515

@@ -73,6 +73,8 @@ def repair_wheel(
7373
for fn, v in external_refs_by_fn.items():
7474
ext_libs = v[abis[0]]["libs"] # type: Dict[str, str]
7575
replacements = [] # type: List[Tuple[str, str]]
76+
src_path_to_real_sonames = {} # type: Dict[str, str]
77+
same_soname_libs = defaultdict(set) # type: Dict[str, Set[str]]
7678
for soname, src_path in ext_libs.items():
7779
if src_path is None:
7880
raise ValueError(
@@ -83,10 +85,23 @@ def repair_wheel(
8385
% soname
8486
)
8587

86-
if not copy_site_libs and "site-packages" in str(src_path).split(
87-
os.path.sep
88-
):
88+
real_soname = patcher.get_soname(src_path)
89+
src_path_to_real_sonames[soname] = real_soname
90+
same_soname_libs[real_soname].add(soname)
91+
92+
if not copy_site_libs:
93+
for soname, src_path in ext_libs.items():
94+
if "site-packages" in str(src_path).split(os.path.sep):
95+
try:
96+
del same_soname_libs[src_path_to_real_sonames[soname]]
97+
except KeyError:
98+
pass
99+
100+
for real_soname, sonames in same_soname_libs.items():
101+
if len(sonames) == 0:
89102
continue
103+
soname = sonames.pop() # only keep one .so file (remove duplicates)
104+
src_path = ext_libs[soname]
90105

91106
new_soname, new_path = copylib(src_path, dest_dir, patcher)
92107
soname_map[soname] = (new_soname, new_path)

0 commit comments

Comments
 (0)