From 6dbbd125f941a9f1d6ebd39bfddadf44521cd0e9 Mon Sep 17 00:00:00 2001 From: Marc Mueller <30130371+cdce8p@users.noreply.github.com> Date: Sat, 16 Aug 2025 16:00:31 +0200 Subject: [PATCH 1/3] gh-90548: Fix musl version detection with --strip-all --- Lib/platform.py | 10 +++++++++- Lib/test/test_platform.py | 6 ++++++ .../2025-08-16-18-11-41.gh-issue-90548.q3aJUK.rst | 2 ++ 3 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 Misc/NEWS.d/next/Library/2025-08-16-18-11-41.gh-issue-90548.q3aJUK.rst diff --git a/Lib/platform.py b/Lib/platform.py index da15bb4717bb96..5dbe7f0bcd7ff5 100644 --- a/Lib/platform.py +++ b/Lib/platform.py @@ -194,6 +194,7 @@ def libc_ver(executable=None, lib='', version='', chunksize=16384): | (GLIBC_([0-9.]+)) | (libc(_\w+)?\.so(?:\.(\d[0-9.]*))?) | (musl-([0-9.]+)) + | (libc.musl(?:-\w+)?.so(?:\.(\d[0-9.]*))?) """, re.ASCII | re.VERBOSE) @@ -219,7 +220,10 @@ def libc_ver(executable=None, lib='', version='', chunksize=16384): continue if not m: break - libcinit, glibc, glibcversion, so, threads, soversion, musl, muslversion = [ + ( + libcinit, glibc, glibcversion, so, threads, soversion, + musl, muslversion, musl_so, musl_sover + ) = [ s.decode('latin1') if s is not None else s for s in m.groups()] if libcinit and not lib: @@ -241,6 +245,10 @@ def libc_ver(executable=None, lib='', version='', chunksize=16384): lib = 'musl' if not ver or V(muslversion) > V(ver): ver = muslversion + elif musl_so: + lib = 'musl' + if musl_sover and (not ver or V(musl_sover) > V(ver)): + ver = musl_sover pos = m.end() return lib, version if ver is None else ver diff --git a/Lib/test/test_platform.py b/Lib/test/test_platform.py index 479649053abc01..2ba09d98737eae 100644 --- a/Lib/test/test_platform.py +++ b/Lib/test/test_platform.py @@ -565,6 +565,8 @@ def test_libc_ver(self): # musl uses semver, but we accept some variations anyway: (b'/aports/main/musl/src/musl-12.5', ('musl', '12.5')), (b'/aports/main/musl/src/musl-1.2.5.7', ('musl', '1.2.5.7')), + (b'libc.musl.so.1', ('musl', '1')), + (b'libc.musl-x86_64.so.1.2.5', ('musl', '1.2.5')), (b'', ('', '')), ): with open(filename, 'wb') as fp: @@ -583,6 +585,10 @@ def test_libc_ver(self): (b'GLIBC_1.23.4\0GLIBC_1.9\0GLIBC_1.21\0', ('glibc', '1.23.4')), (b'libc.so.2.4\0libc.so.9\0libc.so.23.1\0', ('libc', '23.1')), (b'musl-1.4.1\0musl-2.1.1\0musl-2.0.1\0', ('musl', '2.1.1')), + ( + 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', + ('musl', '2.1.1'), + ), (b'no match here, so defaults are used', ('test', '100.1.0')), ): with open(filename, 'wb') as f: diff --git a/Misc/NEWS.d/next/Library/2025-08-16-18-11-41.gh-issue-90548.q3aJUK.rst b/Misc/NEWS.d/next/Library/2025-08-16-18-11-41.gh-issue-90548.q3aJUK.rst new file mode 100644 index 00000000000000..f6e24af30fec1c --- /dev/null +++ b/Misc/NEWS.d/next/Library/2025-08-16-18-11-41.gh-issue-90548.q3aJUK.rst @@ -0,0 +1,2 @@ +Fix ``musl`` detection for :func:`platform.libc_ver` on Alpine Linux if +compiled with --strip-all. From 10d946270de54f40434c088e0093ea8bbf11511a Mon Sep 17 00:00:00 2001 From: Marc Mueller <30130371+cdce8p@users.noreply.github.com> Date: Sun, 17 Aug 2025 01:08:18 +0200 Subject: [PATCH 2/3] Update Lib/platform.py Co-authored-by: Adam Turner <9087854+AA-Turner@users.noreply.github.com> --- Lib/platform.py | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/Lib/platform.py b/Lib/platform.py index 5dbe7f0bcd7ff5..70fda3f605241b 100644 --- a/Lib/platform.py +++ b/Lib/platform.py @@ -220,12 +220,10 @@ def libc_ver(executable=None, lib='', version='', chunksize=16384): continue if not m: break - ( - libcinit, glibc, glibcversion, so, threads, soversion, - musl, muslversion, musl_so, musl_sover - ) = [ - s.decode('latin1') if s is not None else s - for s in m.groups()] + decoded_groups = [s.decode('latin1') if s is not None else s + for s in m.groups()] + (libcinit, glibc, glibcversion, so, threads, soversion, + musl, muslversion, musl_so, musl_sover) = decoded_groups if libcinit and not lib: lib = 'libc' elif glibc: From cf036f46435024d513f6bbc35519bea17bfcca3e Mon Sep 17 00:00:00 2001 From: Adam Turner <9087854+AA-Turner@users.noreply.github.com> Date: Sun, 17 Aug 2025 00:10:04 +0100 Subject: [PATCH 3/3] Update Lib/platform.py --- Lib/platform.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lib/platform.py b/Lib/platform.py index 70fda3f605241b..9b9d27d5816eac 100644 --- a/Lib/platform.py +++ b/Lib/platform.py @@ -223,7 +223,7 @@ def libc_ver(executable=None, lib='', version='', chunksize=16384): decoded_groups = [s.decode('latin1') if s is not None else s for s in m.groups()] (libcinit, glibc, glibcversion, so, threads, soversion, - musl, muslversion, musl_so, musl_sover) = decoded_groups + musl, muslversion, musl_so, musl_sover) = decoded_groups if libcinit and not lib: lib = 'libc' elif glibc: