diff --git a/lib/spack/spack/compilers/config.py b/lib/spack/spack/compilers/config.py index 8214428278b..476bf193433 100644 --- a/lib/spack/spack/compilers/config.py +++ b/lib/spack/spack/compilers/config.py @@ -7,6 +7,7 @@ import os import re import sys +import warnings from typing import Any, Dict, List, Optional, Tuple import archspec.cpu @@ -337,7 +338,15 @@ def from_legacy_yaml(compiler_dict: Dict[str, Any]) -> List[spack.spec.Spec]: pkg_cls = spack.repo.PATH.get_pkg_class(pkg_name) pattern = re.compile(r"|".join(finder.search_patterns(pkg=pkg_cls))) filtered_paths = [x for x in candidate_paths if pattern.search(os.path.basename(x))] - detected = finder.detect_specs(pkg=pkg_cls, paths=filtered_paths) + try: + detected = finder.detect_specs(pkg=pkg_cls, paths=filtered_paths) + except Exception: + warnings.warn( + f"[{__name__}] cannot detect {pkg_name} from the " + f"following paths: {', '.join(filtered_paths)}" + ) + continue + for s in detected: for key in ("flags", "environment", "extra_rpaths"): if key in compiler_dict: diff --git a/lib/spack/spack/test/compilers/conversion.py b/lib/spack/spack/test/compilers/conversion.py index 84ce07f5ded..d9312c55b18 100644 --- a/lib/spack/spack/test/compilers/conversion.py +++ b/lib/spack/spack/test/compilers/conversion.py @@ -83,3 +83,12 @@ def tests_compiler_conversion_modules(mock_compiler): compiler_spec = CompilerFactory.from_legacy_yaml(mock_compiler)[0] assert compiler_spec.external assert compiler_spec.external_modules == modules + + +@pytest.mark.regression("49717") +def tests_compiler_conversion_corrupted_paths(mock_compiler): + """Tests that compiler entries with corrupted path do not raise""" + mock_compiler["paths"] = {"cc": "gcc", "cxx": "g++", "fc": "gfortran", "f77": "gfortran"} + # Test this call doesn't raise + compiler_spec = CompilerFactory.from_legacy_yaml(mock_compiler) + assert compiler_spec == []