Repository: spack/spack

Issue:
Warning on libc not found for non-existing compiler
### Steps to reproduce

Using a `compilers.yaml` with compiler definitions for two different systems, with the non-host definitions in a path that does not exist:
```yaml
compilers:
- compiler:
    spec: gcc@=9.4.0
    paths:
      cc: /usr/bin/gcc
      cxx: /usr/bin/g++
      f77: /usr/bin/gfortran
      fc: /usr/bin/gfortran
    flags: {}
    operating_system: ubuntu20.04
    target: x86_64
    modules: []
    environment: {}
    extra_rpaths: []
- compiler:
    spec: gcc@=9.3.0
    paths:
      cc: /some/path/gcc
      cxx: /some/path/g++
      f77: /some/path/gfortran
      fc: /some/path/gfortran
    flags: {}
    operating_system: ubuntu22.04
    target: x86_64
    modules: []
    environment: {}
    extra_rpaths: []
```
Concretitization always warns about not finding `libc` for the non-existing compiler:
```console
$ spack spec zlib-ng
```

### Error message

```console
==> Warning: cannot detect libc from gcc@=9.3.0. The compiler will not be used during concretization.
Input spec
--------------------------------
 -   zlib-ng

Concretized
--------------------------------
 -   zlib-ng@2.1.6%gcc@9.4.0+compat+new_strategies+opt+pic+shared build_system=autotools arch=linux-ubuntu20.04-icelake
 -       ^gcc-runtime@9.4.0%gcc@9.4.0 build_system=generic arch=linux-ubuntu20.04-icelake
[e]      ^glibc@2.31%gcc@9.4.0 build_system=autotools arch=linux-ubuntu20.04-icelake
 -       ^gmake@4.4.1%gcc@9.4.0~guile build_system=generic arch=linux-ubuntu20.04-icelake

```

### Information on your system

* **Spack:** 0.23.0.dev0 (7f3dd38ccc106142846f29f76b928fa58e0e3164)
* **Python:** 3.11.5
* **Platform:** linux-ubuntu20.04-icelake
* **Concretizer:** clingo

@becker33

### General information

- [X] I have run `spack debug report` and reported the version of Spack/Python/Platform
- [X] I have searched the issues of this repo and believe this is not a duplicate
- [X] I have run the failing commands in debug mode and reported the output


Discussion:

Resolving patch:
diff --git a/lib/spack/spack/solver/asp.py b/lib/spack/spack/solver/asp.py
--- a/lib/spack/spack/solver/asp.py
+++ b/lib/spack/spack/solver/asp.py
@@ -314,6 +314,10 @@ def using_libc_compatibility() -> bool:
     return spack.platforms.host().name == "linux"
 
 
+def c_compiler_runs(compiler: spack.compiler.Compiler) -> bool:
+    return compiler.compiler_verbose_output is not None
+
+
 def extend_flag_list(flag_list, new_flags):
     """Extend a list of flags, preserving order and precedence.
 
@@ -2975,6 +2979,13 @@ class CompilerParser:
     def __init__(self, configuration) -> None:
         self.compilers: Set[KnownCompiler] = set()
         for c in all_compilers_in_config(configuration):
+            if using_libc_compatibility() and not c_compiler_runs(c):
+                tty.debug(
+                    f"the C compiler {c.cc} does not exist, or does not run correctly."
+                    f" The compiler {c.spec} will not be used during concretization."
+                )
+                continue
+
             if using_libc_compatibility() and not c.default_libc:
                 warnings.warn(
                     f"cannot detect libc from {c.spec}. The compiler will not be used "


Test patch:
diff --git a/lib/spack/spack/test/conftest.py b/lib/spack/spack/test/conftest.py
--- a/lib/spack/spack/test/conftest.py
+++ b/lib/spack/spack/test/conftest.py
@@ -2053,3 +2053,11 @@ def _true(x):
 @pytest.fixture()
 def do_not_check_runtimes_on_reuse(monkeypatch):
     monkeypatch.setattr(spack.solver.asp, "_has_runtime_dependencies", _true)
+
+
+@pytest.fixture(autouse=True, scope="session")
+def _c_compiler_always_exists():
+    fn = spack.solver.asp.c_compiler_runs
+    spack.solver.asp.c_compiler_runs = _true
+    yield
+    spack.solver.asp.c_compiler_runs = fn