Skip to content

Commit 6a8b109

Browse files
authored
Merge pull request #4290 from boegel/relax_glibc_version_pattern
fix regex for extracting glibc version from output of '`ldd --version`' in Gentoo Linux
2 parents 366e71d + b43bad7 commit 6a8b109

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

easybuild/tools/systemtools.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -943,7 +943,9 @@ def get_glibc_version():
943943

944944
if os_type == LINUX:
945945
glibc_ver_str = get_tool_version('ldd')
946-
glibc_ver_regex = re.compile(r"^ldd \([^)]*\) (\d[\d.]*).*$")
946+
# note: get_tool_version replaces newlines with ';',
947+
# hence the use of ';' below after the expected glibc version
948+
glibc_ver_regex = re.compile(r"^ldd \(.+\) (\d[\d.]+);")
947949
res = glibc_ver_regex.search(glibc_ver_str)
948950

949951
if res is not None:

test/framework/systemtools.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ def mocked_run_cmd(cmd, **kwargs):
325325
"""Mocked version of run_cmd, with specified output for known commands."""
326326
known_cmds = {
327327
"gcc --version": "gcc (GCC) 5.1.1 20150618 (Red Hat 5.1.1-4)",
328-
"ldd --version": "ldd (GNU libc) 2.12",
328+
"ldd --version": "ldd (GNU libc) 2.12; ",
329329
"sysctl -n hw.cpufrequency_max": "2400000000",
330330
"sysctl -n hw.ncpu": '10',
331331
"sysctl -n hw.memsize": '8589934592',
@@ -791,6 +791,13 @@ def test_glibc_version_linux(self):
791791
st.run_cmd = mocked_run_cmd
792792
self.assertEqual(get_glibc_version(), '2.12')
793793

794+
def test_glibc_version_linux_gentoo(self):
795+
"""Test getting glibc version (mocked for Linux)."""
796+
st.get_os_type = lambda: st.LINUX
797+
ldd_version_out = "ldd (Gentoo 2.37-r3 (patchset 5)) 2.37; Copyright (C) 2023 Free Software Foundation, Inc."
798+
st.get_tool_version = lambda _: ldd_version_out
799+
self.assertEqual(get_glibc_version(), '2.37')
800+
794801
def test_glibc_version_linux_musl_libc(self):
795802
"""Test getting glibc version (mocked for Linux)."""
796803
st.get_os_type = lambda: st.LINUX

0 commit comments

Comments
 (0)