From f6851a56e846a0f59ea0b98a3f332aa49bd533a7 Mon Sep 17 00:00:00 2001 From: Massimiliano Culpo Date: Mon, 16 Dec 2024 20:50:18 +0100 Subject: [PATCH] compiler: add cc, cxx, and fortran properties These properties are implemented in the same way in each compiler package, at least for external specs. So, push the implementation to the base class for now. This needs to be revisited, to make the base class less dependent on C, C++, and Fortran. --- lib/spack/spack/build_systems/compiler.py | 35 +++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/lib/spack/spack/build_systems/compiler.py b/lib/spack/spack/build_systems/compiler.py index 7526d2e8a3d..fae6e70377b 100644 --- a/lib/spack/spack/build_systems/compiler.py +++ b/lib/spack/spack/build_systems/compiler.py @@ -165,6 +165,8 @@ def determine_variants(cls, exes: Sequence[Path], version_str: str) -> Tuple: #: Flag to activate OpenMP support openmp_flag: str = "-fopenmp" + required_libs: List[str] = [] + def standard_flag(self, *, language: str, standard: str) -> str: """Returns the flag used to enforce a given standard for a language""" if language not in self.supported_languages: @@ -288,6 +290,39 @@ def archspec_name(self) -> str: """Name that archspec uses to refer to this compiler""" return self.spec.name + @property + def cc(self) -> Optional[str]: + assert self.spec.concrete, "cannot retrieve C compiler, spec is not concrete" + if self.spec.external: + return self.spec.extra_attributes["compilers"].get("c", None) + return self._cc_path() + + def _cc_path(self) -> Optional[str]: + """Returns the path to the C compiler, if the package was installed by Spack""" + return None + + @property + def cxx(self) -> Optional[str]: + assert self.spec.concrete, "cannot retrieve C++ compiler, spec is not concrete" + if self.spec.external: + return self.spec.extra_attributes["compilers"].get("cxx", None) + return self._cxx_path() + + def _cxx_path(self) -> Optional[str]: + """Returns the path to the C++ compiler, if the package was installed by Spack""" + return None + + @property + def fortran(self): + assert self.spec.concrete, "cannot retrieve Fortran compiler, spec is not concrete" + if self.spec.external: + return self.spec.extra_attributes["compilers"].get("fortran", None) + return self._fortran_path() + + def _fortran_path(self) -> Optional[str]: + """Returns the path to the Fortran compiler, if the package was installed by Spack""" + return None + def _implicit_rpaths(pkg: spack.package_base.PackageBase) -> List[str]: detector = spack.compilers.libraries.CompilerPropertyDetector(pkg.spec)