diff --git a/easybuild/tools/systemtools.py b/easybuild/tools/systemtools.py index 627da42bb6..cab4b00055 100644 --- a/easybuild/tools/systemtools.py +++ b/easybuild/tools/systemtools.py @@ -943,7 +943,9 @@ def get_glibc_version(): if os_type == LINUX: glibc_ver_str = get_tool_version('ldd') - glibc_ver_regex = re.compile(r"^ldd \([^)]*\) (\d[\d.]*).*$") + # note: get_tool_version replaces newlines with ';', + # hence the use of ';' below after the expected glibc version + glibc_ver_regex = re.compile(r"^ldd \(.+\) (\d[\d.]+);") res = glibc_ver_regex.search(glibc_ver_str) if res is not None: diff --git a/test/framework/systemtools.py b/test/framework/systemtools.py index 0841e3b76f..9186b750ec 100644 --- a/test/framework/systemtools.py +++ b/test/framework/systemtools.py @@ -325,7 +325,7 @@ def mocked_run_cmd(cmd, **kwargs): """Mocked version of run_cmd, with specified output for known commands.""" known_cmds = { "gcc --version": "gcc (GCC) 5.1.1 20150618 (Red Hat 5.1.1-4)", - "ldd --version": "ldd (GNU libc) 2.12", + "ldd --version": "ldd (GNU libc) 2.12; ", "sysctl -n hw.cpufrequency_max": "2400000000", "sysctl -n hw.ncpu": '10', "sysctl -n hw.memsize": '8589934592', @@ -791,6 +791,13 @@ def test_glibc_version_linux(self): st.run_cmd = mocked_run_cmd self.assertEqual(get_glibc_version(), '2.12') + def test_glibc_version_linux_gentoo(self): + """Test getting glibc version (mocked for Linux).""" + st.get_os_type = lambda: st.LINUX + ldd_version_out = "ldd (Gentoo 2.37-r3 (patchset 5)) 2.37; Copyright (C) 2023 Free Software Foundation, Inc." + st.get_tool_version = lambda _: ldd_version_out + self.assertEqual(get_glibc_version(), '2.37') + def test_glibc_version_linux_musl_libc(self): """Test getting glibc version (mocked for Linux).""" st.get_os_type = lambda: st.LINUX