From 7d5e27d5e8232ce63c9d69ddd3bb733d4a18edf4 Mon Sep 17 00:00:00 2001 From: Massimiliano Culpo Date: Tue, 23 Apr 2024 12:20:33 +0200 Subject: Do not detect a compiler without a C compiler (#43778) --- lib/spack/spack/compilers/__init__.py | 5 ++-- lib/spack/spack/test/compilers/basics.py | 49 ++++++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+), 2 deletions(-) (limited to 'lib') 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 -- cgit v1.2.3-70-g09d2