summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorMassimiliano Culpo <massimiliano.culpo@gmail.com>2024-04-23 12:20:33 +0200
committerGitHub <noreply@github.com>2024-04-23 12:20:33 +0200
commit7d5e27d5e8232ce63c9d69ddd3bb733d4a18edf4 (patch)
tree18bc64465aebb919d7499aa00c6768d4240af180 /lib
parentd210425eef832c10a6c74365068a3262d20b576b (diff)
downloadspack-7d5e27d5e8232ce63c9d69ddd3bb733d4a18edf4.tar.gz
spack-7d5e27d5e8232ce63c9d69ddd3bb733d4a18edf4.tar.bz2
spack-7d5e27d5e8232ce63c9d69ddd3bb733d4a18edf4.tar.xz
spack-7d5e27d5e8232ce63c9d69ddd3bb733d4a18edf4.zip
Do not detect a compiler without a C compiler (#43778)
Diffstat (limited to 'lib')
-rw-r--r--lib/spack/spack/compilers/__init__.py5
-rw-r--r--lib/spack/spack/test/compilers/basics.py49
2 files changed, 52 insertions, 2 deletions
diff --git a/lib/spack/spack/compilers/__init__.py b/lib/spack/spack/compilers/__init__.py
index 678c1773ab..a52d787f02 100644
--- a/lib/spack/spack/compilers/__init__.py
+++ b/lib/spack/spack/compilers/__init__.py
@@ -967,10 +967,11 @@ def make_compiler_list(
make_mixed_toolchain(flat_compilers)
# Finally, create the compiler list
- compilers = []
+ compilers: List["spack.compiler.Compiler"] = []
for compiler_id, _, compiler in flat_compilers:
make_compilers = getattr(compiler_id.os, "make_compilers", _default_make_compilers)
- compilers.extend(make_compilers(compiler_id, compiler))
+ candidates = make_compilers(compiler_id, compiler)
+ compilers.extend(x for x in candidates if x.cc is not None)
return compilers
diff --git a/lib/spack/spack/test/compilers/basics.py b/lib/spack/spack/test/compilers/basics.py
index a5a5b8f662..84b48adba8 100644
--- a/lib/spack/spack/test/compilers/basics.py
+++ b/lib/spack/spack/test/compilers/basics.py
@@ -894,3 +894,52 @@ def test_compiler_executable_verification_success(tmpdir):
# Test that null entries don't fail
compiler.cc = None
compiler.verify_executables()
+
+
+@pytest.mark.parametrize(
+ "detected_versions,expected_length",
+ [
+ # If we detect a C compiler we expect the result to be valid
+ (
+ [
+ spack.compilers.DetectVersionArgs(
+ id=spack.compilers.CompilerID(
+ os="ubuntu20.04", compiler_name="clang", version="12.0.0"
+ ),
+ variation=spack.compilers.NameVariation(prefix="", suffix="-12"),
+ language="cc",
+ path="/usr/bin/clang-12",
+ ),
+ spack.compilers.DetectVersionArgs(
+ id=spack.compilers.CompilerID(
+ os="ubuntu20.04", compiler_name="clang", version="12.0.0"
+ ),
+ variation=spack.compilers.NameVariation(prefix="", suffix="-12"),
+ language="cxx",
+ path="/usr/bin/clang++-12",
+ ),
+ ],
+ 1,
+ ),
+ # If we detect only a C++ compiler we expect the result to be discarded
+ (
+ [
+ spack.compilers.DetectVersionArgs(
+ id=spack.compilers.CompilerID(
+ os="ubuntu20.04", compiler_name="clang", version="12.0.0"
+ ),
+ variation=spack.compilers.NameVariation(prefix="", suffix="-12"),
+ language="cxx",
+ path="/usr/bin/clang++-12",
+ )
+ ],
+ 0,
+ ),
+ ],
+)
+def test_detection_requires_c_compiler(detected_versions, expected_length):
+ """Tests that compilers automatically added to the configuration have
+ at least a C compiler.
+ """
+ result = spack.compilers.make_compiler_list(detected_versions)
+ assert len(result) == expected_length