From da06ad330338d56c3e052a9240c338cf51b9102d Mon Sep 17 00:00:00 2001 From: Massimiliano Culpo Date: Wed, 23 Oct 2024 17:14:31 +0200 Subject: [PATCH] Improve reporting when bootstrapping from source Signed-off-by: Massimiliano Culpo --- lib/spack/llnl/util/lang.py | 7 ++----- lib/spack/spack/bootstrap/clingo.py | 10 ++++++++-- lib/spack/spack/bootstrap/core.py | 18 ++++++++---------- lib/spack/spack/spec.py | 3 --- 4 files changed, 18 insertions(+), 20 deletions(-) diff --git a/lib/spack/llnl/util/lang.py b/lib/spack/llnl/util/lang.py index 922d515c65c..22ba9c84d17 100644 --- a/lib/spack/llnl/util/lang.py +++ b/lib/spack/llnl/util/lang.py @@ -996,11 +996,8 @@ def _receive_forwarded(self, context: str, exc: Exception, tb: List[str]): def grouped_message(self, with_tracebacks: bool = True) -> str: """Print out an error message coalescing all the forwarded errors.""" each_exception_message = [ - "{0} raised {1}: {2}{3}".format( - context, - exc.__class__.__name__, - exc, - "\n{0}".format("".join(tb)) if with_tracebacks else "", + "\n\t{0} raised {1}: {2}\n{3}".format( + context, exc.__class__.__name__, exc, f"\n{''.join(tb)}" if with_tracebacks else "" ) for context, exc, tb in self.exceptions ] diff --git a/lib/spack/spack/bootstrap/clingo.py b/lib/spack/spack/bootstrap/clingo.py index bdad160de0d..d68acc67bd4 100644 --- a/lib/spack/spack/bootstrap/clingo.py +++ b/lib/spack/spack/bootstrap/clingo.py @@ -62,9 +62,15 @@ def _valid_compiler_or_raise(self): ) candidates.sort(key=lambda x: x.version, reverse=True) best = candidates[0] - # FIXME (compiler as nodes): we need to find a better place for setting namespaces + # Get compilers for bootstrapping from the 'builtin' repository best.namespace = "builtin" - # TODO: check it has C and C++, and supports C++14 + # If the compiler does not support C++ 14, fail with a legible error message + try: + _ = best.package.standard_flag(language="cxx", standard="14") + except RuntimeError as e: + raise RuntimeError( + "cannot find a compiler supporting C++ 14 [needed to bootstrap clingo]" + ) from e return candidates[0] def _externals_from_yaml( diff --git a/lib/spack/spack/bootstrap/core.py b/lib/spack/spack/bootstrap/core.py index eebcbb497b4..586c6df6712 100644 --- a/lib/spack/spack/bootstrap/core.py +++ b/lib/spack/spack/bootstrap/core.py @@ -321,11 +321,10 @@ def create_bootstrapper(conf: ConfigDictionary): return _bootstrap_methods[btype](conf) -def source_is_enabled_or_raise(conf: ConfigDictionary): +def source_is_enabled(conf: ConfigDictionary): """Raise ValueError if the source is not enabled for bootstrapping""" trusted, name = spack.config.get("bootstrap:trusted"), conf["name"] - if not trusted.get(name, False): - raise ValueError("source is not trusted") + return trusted.get(name, False) def ensure_module_importable_or_raise(module: str, abstract_spec: Optional[str] = None): @@ -355,8 +354,10 @@ def ensure_module_importable_or_raise(module: str, abstract_spec: Optional[str] exception_handler = GroupedExceptionHandler() for current_config in bootstrapping_sources(): + if not source_is_enabled(current_config): + continue + with exception_handler.forward(current_config["name"], Exception): - source_is_enabled_or_raise(current_config) current_bootstrapper = create_bootstrapper(current_config) if current_bootstrapper.try_import(module, abstract_spec): return @@ -368,11 +369,7 @@ def ensure_module_importable_or_raise(module: str, abstract_spec: Optional[str] msg = f'cannot bootstrap the "{module}" Python module ' if abstract_spec: msg += f'from spec "{abstract_spec}" ' - if tty.is_debug(): - msg += exception_handler.grouped_message(with_tracebacks=True) - else: - msg += exception_handler.grouped_message(with_tracebacks=False) - msg += "\nRun `spack --debug ...` for more detailed errors" + msg += exception_handler.grouped_message(with_tracebacks=tty.is_debug()) raise ImportError(msg) @@ -410,8 +407,9 @@ def ensure_executables_in_path_or_raise( exception_handler = GroupedExceptionHandler() for current_config in bootstrapping_sources(): + if not source_is_enabled(current_config): + continue with exception_handler.forward(current_config["name"], Exception): - source_is_enabled_or_raise(current_config) current_bootstrapper = create_bootstrapper(current_config) if current_bootstrapper.try_search_path(executables, abstract_spec): # Additional environment variables needed diff --git a/lib/spack/spack/spec.py b/lib/spack/spack/spec.py index a8b85f4c3d6..185a555c36e 100644 --- a/lib/spack/spack/spec.py +++ b/lib/spack/spack/spec.py @@ -5316,9 +5316,6 @@ class DuplicateCompilerSpecError(spack.error.SpecError): class UnsupportedCompilerError(spack.error.SpecError): """Raised when the user asks for a compiler spack doesn't know about.""" - def __init__(self, compiler_name): - super().__init__("The '%s' compiler is not yet supported." % compiler_name) - class DuplicateArchitectureError(spack.error.SpecError): """Raised when the same architecture occurs in a spec twice."""