summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorHarmen Stoppels <me@harmenstoppels.nl>2024-11-05 12:30:32 +0100
committerGitHub <noreply@github.com>2024-11-05 12:30:32 +0100
commitdadb30f0e2cf64d6189bbabae2eaf9452bd53272 (patch)
tree1ecf87e01e24b1fe064e50309d5f3932c131f667 /lib
parentd45f682573e9f9b38b17fd2cbfd188da551b45f9 (diff)
downloadspack-dadb30f0e2cf64d6189bbabae2eaf9452bd53272.tar.gz
spack-dadb30f0e2cf64d6189bbabae2eaf9452bd53272.tar.bz2
spack-dadb30f0e2cf64d6189bbabae2eaf9452bd53272.tar.xz
spack-dadb30f0e2cf64d6189bbabae2eaf9452bd53272.zip
libc.py: detect glibc also in chinese locale (#47434)
Diffstat (limited to 'lib')
-rw-r--r--lib/spack/spack/util/libc.py24
1 files changed, 18 insertions, 6 deletions
diff --git a/lib/spack/spack/util/libc.py b/lib/spack/spack/util/libc.py
index 55e8e3d26b..148c4cb13a 100644
--- a/lib/spack/spack/util/libc.py
+++ b/lib/spack/spack/util/libc.py
@@ -9,20 +9,30 @@ import re
import shlex
import sys
from subprocess import PIPE, run
-from typing import List, Optional
+from typing import Dict, List, Optional
import spack.spec
import spack.util.elf
+#: Pattern to distinguish glibc from other libc implementations
+GLIBC_PATTERN = r"\b(?:Free Software Foundation|Roland McGrath|Ulrich Depper)\b"
+
+
+def _env() -> Dict[str, str]:
+ """Currently only set LC_ALL=C without clearing further environment variables"""
+ return {**os.environ, "LC_ALL": "C"}
+
def _libc_from_ldd(ldd: str) -> Optional["spack.spec.Spec"]:
try:
- result = run([ldd, "--version"], stdout=PIPE, stderr=PIPE, check=False)
+ result = run([ldd, "--version"], stdout=PIPE, stderr=PIPE, check=False, env=_env())
stdout = result.stdout.decode("utf-8")
except Exception:
return None
- if not re.search(r"\bFree Software Foundation\b", stdout):
+ # The string "Free Software Foundation" is sometimes translated and not detected, but the names
+ # of the authors are typically present.
+ if not re.search(GLIBC_PATTERN, stdout):
return None
version_str = re.match(r".+\(.+\) (.+)", stdout)
@@ -38,7 +48,7 @@ def default_search_paths_from_dynamic_linker(dynamic_linker: str) -> List[str]:
"""If the dynamic linker is glibc at a certain version, we can query the hard-coded library
search paths"""
try:
- result = run([dynamic_linker, "--help"], stdout=PIPE, stderr=PIPE, check=False)
+ result = run([dynamic_linker, "--help"], stdout=PIPE, stderr=PIPE, check=False, env=_env())
assert result.returncode == 0
out = result.stdout.decode("utf-8")
except Exception:
@@ -74,7 +84,9 @@ def libc_from_dynamic_linker(dynamic_linker: str) -> Optional["spack.spec.Spec"]
# Now try to figure out if glibc or musl, which is the only ones we support.
# In recent glibc we can simply execute the dynamic loader. In musl that's always the case.
try:
- result = run([dynamic_linker, "--version"], stdout=PIPE, stderr=PIPE, check=False)
+ result = run(
+ [dynamic_linker, "--version"], stdout=PIPE, stderr=PIPE, check=False, env=_env()
+ )
stdout = result.stdout.decode("utf-8")
stderr = result.stderr.decode("utf-8")
except Exception:
@@ -91,7 +103,7 @@ def libc_from_dynamic_linker(dynamic_linker: str) -> Optional["spack.spec.Spec"]
return spec
except Exception:
return None
- elif re.search(r"\bFree Software Foundation\b", stdout):
+ elif re.search(GLIBC_PATTERN, stdout):
# output is like "ld.so (...) stable release version 2.33."
match = re.search(r"version (\d+\.\d+(?:\.\d+)?)", stdout)
if not match: