Raise UnsupportedCompilerFlag when a flag is not supported

This commit is contained in:
Massimiliano Culpo 2024-12-04 18:56:32 +01:00
parent ecd13e2df8
commit df92dad225
No known key found for this signature in database
GPG Key ID: 3E52BB992233066C
2 changed files with 9 additions and 10 deletions

View File

@ -15,6 +15,8 @@
import llnl.util.tty as tty
from llnl.util.lang import classproperty, memoized
import spack
import spack.compilers.error
import spack.compilers.libraries
import spack.config
import spack.package_base
@ -167,12 +169,13 @@ def determine_variants(cls, exes: Sequence[Path], version_str: str) -> Tuple:
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:
# FIXME (compiler as nodes): Use UnsupportedCompilerFlag ?
raise RuntimeError(f"{self.spec} does not provide the '{language}' language")
raise spack.compilers.error.UnsupportedCompilerFlag(
f"{self.spec} does not provide the '{language}' language"
)
try:
return self._standard_flag(language=language, standard=standard)
except (KeyError, RuntimeError) as e:
raise RuntimeError(
raise spack.compilers.error.UnsupportedCompilerFlag(
f"{self.spec} does not provide the '{language}' standard {standard}"
) from e

View File

@ -14,10 +14,6 @@ def __init__(self, compiler, paths):
class UnsupportedCompilerFlag(SpackError):
def __init__(self, compiler, feature, flag_name, ver_string=None):
super().__init__(
f"{compiler.name} ({ver_string if ver_string else compiler.version}) does not support"
f" {feature} (as compiler.{flag_name}). If you think it should, please edit the "
f"compiler.{compiler.name} subclass to implement the {flag_name} property and submit "
f"a pull request or issue."
)
"""Raised when a compiler does not support a flag type (e.g. a flag to enforce a
language standard).
"""