Do not error when trying to convert corrupted compiler entries (#49759)
fixes #49717 If no compiler is listed in the 'packages' section of the configuration, Spack will currently try to: 1. Look for a legacy compilers.yaml to convert 2. Look for compilers in PATH in that order. If an entry in compilers.yaml is corrupted, that should not result in an obscure error. Instead, it should just be skipped. Signed-off-by: Massimiliano Culpo <massimiliano.culpo@gmail.com>
This commit is contained in:
parent
3e99a12ea2
commit
10f309273a
@ -7,6 +7,7 @@
|
|||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
import sys
|
import sys
|
||||||
|
import warnings
|
||||||
from typing import Any, Dict, List, Optional, Tuple
|
from typing import Any, Dict, List, Optional, Tuple
|
||||||
|
|
||||||
import archspec.cpu
|
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)
|
pkg_cls = spack.repo.PATH.get_pkg_class(pkg_name)
|
||||||
pattern = re.compile(r"|".join(finder.search_patterns(pkg=pkg_cls)))
|
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))]
|
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 s in detected:
|
||||||
for key in ("flags", "environment", "extra_rpaths"):
|
for key in ("flags", "environment", "extra_rpaths"):
|
||||||
if key in compiler_dict:
|
if key in compiler_dict:
|
||||||
|
@ -83,3 +83,12 @@ def tests_compiler_conversion_modules(mock_compiler):
|
|||||||
compiler_spec = CompilerFactory.from_legacy_yaml(mock_compiler)[0]
|
compiler_spec = CompilerFactory.from_legacy_yaml(mock_compiler)[0]
|
||||||
assert compiler_spec.external
|
assert compiler_spec.external
|
||||||
assert compiler_spec.external_modules == modules
|
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 == []
|
||||||
|
Loading…
Reference in New Issue
Block a user