Repository: spack/spack

Issue:
Installation issue: conduit/apcomp/ascent +fortran
### Steps to reproduce the issue

compilers.yaml
```yaml
compilers:
- compiler:
    spec: gcc@11.2.0
    paths:
      cc: cc
      cxx: CC
      f77: ftn
      fc: ftn # Fortran compiler specified here
    flags: {}
    operating_system: sles15
    target: any
    modules:
    - PrgEnv-gnu
    - gcc/11.2.0
    environment: {}
    extra_rpaths: []
```

```console
spack install ascent +fortran
```

Building conduit by itself it seems like everything is fine. `conduit +fortran` all builds, no problem. Or so it seems until `ascent +fortran` tries to configure when all of the sudden it can't find the conduit.mod file.

I went digging around and finally found the culprit, the listed projects _silently_ hide turning off fortran when it is requested, even if there is a valid fortran compiler available. Either `self.compiler.fc` is not set for some reason or `SPACK_FC` is not set in the hostconfig stage context reliably (it is in the `spack-build-env.txt` file for what it is worth). Just removing all of the f_compiler logic fixes this issue, but my sense around these projects is they have some reason for doing all of these things.

This will always fail to build whatever project _downstream_ needs `conduit +fortran` but never fail to build a `conduit +fortran`. This is really not ideal, if a spec is specified the package should build to that spec or not build at all.

hostconfig:
[perlmutter-ascent-host-config.cmake.txt](https://github.com/spack/spack/files/7942267/perlmutter-ascent-host-config.cmake.txt)


### Information on your system

On Perlmutter
[perlmutter-ascent-build-out.txt](https://github.com/spack/spack/files/7942904/perlmutter-ascent-build-out.txt)
[perlmutter-ascent-build-env.txt](https://github.com/spack/spack/files/7942905/perlmutter-ascent-build-env.txt)

```
* **Spack:** 0.17.1-823-28565749ff
* **Python:** 3.6.13
* **Platform:** cray-sles15-zen3
* **Concretizer:** clingo
```

### Additional information

My environment is setup using the [spack-confg for perlmutter](https://github.com/spack/spack-configs/tree/main/NERSC/perlmutter/e4s-21.11/site_config) with some minor modifications around nvidia/cuda stuff which should affect this at all. I also added the `gcc@11.2.0` compiler, it is now the default in the `PrgEnv-gnu`.

@cyrush 

### General information

- [X] I have run `spack debug report` and reported the version of Spack/Python/Platform
- [X] I have run `spack maintainers <name-of-the-package>` and **@mentioned** any maintainers
- [X] I have uploaded the build log and environment files
- [X] I have searched the issues of this repo and believe this is not a duplicate


Discussion:
I just realized why this is failing. `self.compiler.fc` is set to `ftn`, not the full path. So when this check looks to see if the fortran compiler file exists, it fails. This is not a good check because there is no requirement in the `compilers.yaml` to specify the full path, partial paths that use the `PATH` variable configured by the `module load` are valid, and common.

Resolving patch:
diff --git a/var/spack/repos/builtin/packages/ascent/package.py b/var/spack/repos/builtin/packages/ascent/package.py
--- a/var/spack/repos/builtin/packages/ascent/package.py
+++ b/var/spack/repos/builtin/packages/ascent/package.py
@@ -269,11 +269,6 @@ def hostconfig(self, spec, prefix):
         #######################
         c_compiler = env["SPACK_CC"]
         cpp_compiler = env["SPACK_CXX"]
-        f_compiler = None
-
-        if self.compiler.fc:
-            # even if this is set, it may not exist so do one more sanity check
-            f_compiler = env["SPACK_FC"]
 
         #######################################################################
         # Directly fetch the names of the actual compilers to create a
@@ -323,12 +318,9 @@ def hostconfig(self, spec, prefix):
         cfg.write(cmake_cache_entry("CMAKE_CXX_COMPILER", cpp_compiler))
 
         cfg.write("# fortran compiler used by spack\n")
-        if "+fortran" in spec and f_compiler is not None:
+        if "+fortran" in spec:
             cfg.write(cmake_cache_entry("ENABLE_FORTRAN", "ON"))
-            cfg.write(cmake_cache_entry("CMAKE_Fortran_COMPILER",
-                                        f_compiler))
         else:
-            cfg.write("# no fortran compiler found\n\n")
             cfg.write(cmake_cache_entry("ENABLE_FORTRAN", "OFF"))
 
         # shared vs static libs
diff --git a/var/spack/repos/builtin/packages/conduit/package.py b/var/spack/repos/builtin/packages/conduit/package.py
--- a/var/spack/repos/builtin/packages/conduit/package.py
+++ b/var/spack/repos/builtin/packages/conduit/package.py
@@ -291,13 +291,7 @@ def hostconfig(self, spec, prefix):
         #######################
         c_compiler = env["SPACK_CC"]
         cpp_compiler = env["SPACK_CXX"]
-        f_compiler = None
-
-        if self.compiler.fc:
-            # even if this is set, it may not exist
-            # do one more sanity check
-            if os.path.isfile(env["SPACK_FC"]):
-                f_compiler  = env["SPACK_FC"]
+        f_compiler = env["SPACK_FC"]
 
         #######################################################################
         # Directly fetch the names of the actual compilers to create a
@@ -345,12 +339,9 @@ def hostconfig(self, spec, prefix):
         cfg.write(cmake_cache_entry("CMAKE_CXX_COMPILER", cpp_compiler))
 
         cfg.write("# fortran compiler used by spack\n")
-        if "+fortran" in spec and f_compiler is not None:
+        if "+fortran" in spec:
             cfg.write(cmake_cache_entry("ENABLE_FORTRAN", "ON"))
-            cfg.write(cmake_cache_entry("CMAKE_Fortran_COMPILER",
-                                        f_compiler))
         else:
-            cfg.write("# no fortran compiler found\n\n")
             cfg.write(cmake_cache_entry("ENABLE_FORTRAN", "OFF"))
 
         if "+shared" in spec:


Test patch: