Skip to content

Commit 6dbbd12

Browse files
committed
gh-90548: Fix musl version detection with --strip-all
1 parent 0cbbfc4 commit 6dbbd12

3 files changed

Lines changed: 17 additions & 1 deletion

File tree

Lib/platform.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,7 @@ def libc_ver(executable=None, lib='', version='', chunksize=16384):
194194
| (GLIBC_([0-9.]+))
195195
| (libc(_\w+)?\.so(?:\.(\d[0-9.]*))?)
196196
| (musl-([0-9.]+))
197+
| (libc.musl(?:-\w+)?.so(?:\.(\d[0-9.]*))?)
197198
""",
198199
re.ASCII | re.VERBOSE)
199200

@@ -219,7 +220,10 @@ def libc_ver(executable=None, lib='', version='', chunksize=16384):
219220
continue
220221
if not m:
221222
break
222-
libcinit, glibc, glibcversion, so, threads, soversion, musl, muslversion = [
223+
(
224+
libcinit, glibc, glibcversion, so, threads, soversion,
225+
musl, muslversion, musl_so, musl_sover
226+
) = [
223227
s.decode('latin1') if s is not None else s
224228
for s in m.groups()]
225229
if libcinit and not lib:
@@ -241,6 +245,10 @@ def libc_ver(executable=None, lib='', version='', chunksize=16384):
241245
lib = 'musl'
242246
if not ver or V(muslversion) > V(ver):
243247
ver = muslversion
248+
elif musl_so:
249+
lib = 'musl'
250+
if musl_sover and (not ver or V(musl_sover) > V(ver)):
251+
ver = musl_sover
244252
pos = m.end()
245253
return lib, version if ver is None else ver
246254

Lib/test/test_platform.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -565,6 +565,8 @@ def test_libc_ver(self):
565565
# musl uses semver, but we accept some variations anyway:
566566
(b'/aports/main/musl/src/musl-12.5', ('musl', '12.5')),
567567
(b'/aports/main/musl/src/musl-1.2.5.7', ('musl', '1.2.5.7')),
568+
(b'libc.musl.so.1', ('musl', '1')),
569+
(b'libc.musl-x86_64.so.1.2.5', ('musl', '1.2.5')),
568570
(b'', ('', '')),
569571
):
570572
with open(filename, 'wb') as fp:
@@ -583,6 +585,10 @@ def test_libc_ver(self):
583585
(b'GLIBC_1.23.4\0GLIBC_1.9\0GLIBC_1.21\0', ('glibc', '1.23.4')),
584586
(b'libc.so.2.4\0libc.so.9\0libc.so.23.1\0', ('libc', '23.1')),
585587
(b'musl-1.4.1\0musl-2.1.1\0musl-2.0.1\0', ('musl', '2.1.1')),
588+
(
589+
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',
590+
('musl', '2.1.1'),
591+
),
586592
(b'no match here, so defaults are used', ('test', '100.1.0')),
587593
):
588594
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)