Skip to content

Commit 5be4c97

Browse files
cdce8pAA-Turner
authored andcommitted
pythongh-90548: Fix musl version detection with --strip-all (python#137864)
Co-authored-by: Adam Turner <[email protected]>
1 parent 61c2357 commit 5be4c97

File tree

3 files changed

+17
-3
lines changed

3 files changed

+17
-3
lines changed

Lib/platform.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,7 @@ def libc_ver(executable=None, lib='', version='', chunksize=16384):
199199
| (GLIBC_([0-9.]+))
200200
| (libc(_\w+)?\.so(?:\.(\d[0-9.]*))?)
201201
| (musl-([0-9.]+))
202+
| (libc.musl(?:-\w+)?.so(?:\.(\d[0-9.]*))?)
202203
""",
203204
re.ASCII | re.VERBOSE)
204205

@@ -224,9 +225,10 @@ def libc_ver(executable=None, lib='', version='', chunksize=16384):
224225
continue
225226
if not m:
226227
break
227-
libcinit, glibc, glibcversion, so, threads, soversion, musl, muslversion = [
228-
s.decode('latin1') if s is not None else s
229-
for s in m.groups()]
228+
decoded_groups = [s.decode('latin1') if s is not None else s
229+
for s in m.groups()]
230+
(libcinit, glibc, glibcversion, so, threads, soversion,
231+
musl, muslversion, musl_so, musl_sover) = decoded_groups
230232
if libcinit and not lib:
231233
lib = 'libc'
232234
elif glibc:
@@ -246,6 +248,10 @@ def libc_ver(executable=None, lib='', version='', chunksize=16384):
246248
lib = 'musl'
247249
if not ver or V(muslversion) > V(ver):
248250
ver = muslversion
251+
elif musl_so:
252+
lib = 'musl'
253+
if musl_sover and (not ver or V(musl_sover) > V(ver)):
254+
ver = musl_sover
249255
pos = m.end()
250256
return lib, version if ver is None else ver
251257

Lib/test/test_platform.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -567,6 +567,8 @@ def test_libc_ver(self):
567567
# musl uses semver, but we accept some variations anyway:
568568
(b'/aports/main/musl/src/musl-12.5', ('musl', '12.5')),
569569
(b'/aports/main/musl/src/musl-1.2.5.7', ('musl', '1.2.5.7')),
570+
(b'libc.musl.so.1', ('musl', '1')),
571+
(b'libc.musl-x86_64.so.1.2.5', ('musl', '1.2.5')),
570572
(b'', ('', '')),
571573
):
572574
with open(filename, 'wb') as fp:
@@ -585,6 +587,10 @@ def test_libc_ver(self):
585587
(b'GLIBC_1.23.4\0GLIBC_1.9\0GLIBC_1.21\0', ('glibc', '1.23.4')),
586588
(b'libc.so.2.4\0libc.so.9\0libc.so.23.1\0', ('libc', '23.1')),
587589
(b'musl-1.4.1\0musl-2.1.1\0musl-2.0.1\0', ('musl', '2.1.1')),
590+
(
591+
b'libc.musl-x86_64.so.1.4.1\0libc.musl-x86_64.so.2.1.1\0libc.musl-x86_64.so.2.0.1',
592+
('musl', '2.1.1'),
593+
),
588594
(b'no match here, so defaults are used', ('test', '100.1.0')),
589595
):
590596
with open(filename, 'wb') as f:
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Fix ``musl`` detection for :func:`platform.libc_ver` on Alpine Linux if
2+
compiled with --strip-all.

0 commit comments

Comments
 (0)