Partially revert f3ccb8e095121d4bccd562f1c851a2373da1b40a

This commit is contained in:
Harmen Stoppels 2024-12-09 10:05:17 +01:00
parent e995d0543e
commit 74a6b61b75
7 changed files with 55 additions and 54 deletions

View File

@ -33,6 +33,7 @@
import spack import spack
import spack.binary_distribution as bindist import spack.binary_distribution as bindist
import spack.builder import spack.builder
import spack.concretize
import spack.config as cfg import spack.config as cfg
import spack.error import spack.error
import spack.main import spack.main
@ -40,7 +41,6 @@
import spack.mirrors.utils import spack.mirrors.utils
import spack.paths import spack.paths
import spack.repo import spack.repo
import spack.solver.asp
import spack.spec import spack.spec
import spack.util.git import spack.util.git
import spack.util.gpg as gpg_util import spack.util.gpg as gpg_util
@ -707,7 +707,7 @@ def generate_gitlab_ci_yaml(
files (spack.yaml, spack.lock), etc should be written. GitLab files (spack.yaml, spack.lock), etc should be written. GitLab
requires this to be within the project directory. requires this to be within the project directory.
""" """
with spack.solver.asp.disable_compiler_existence_check(): with spack.concretize.disable_compiler_existence_check():
with env.write_transaction(): with env.write_transaction():
env.concretize() env.concretize()
env.write() env.write()

View File

@ -17,7 +17,6 @@
import spack.mirrors.mirror import spack.mirrors.mirror
import spack.mirrors.utils import spack.mirrors.utils
import spack.repo import spack.repo
import spack.solver.asp
import spack.spec import spack.spec
import spack.util.web as web_util import spack.util.web as web_util
from spack.cmd.common import arguments from spack.cmd.common import arguments
@ -517,7 +516,7 @@ def extend_with_dependencies(specs):
def concrete_specs_from_cli_or_file(args): def concrete_specs_from_cli_or_file(args):
tty.msg("Concretizing input specs") tty.msg("Concretizing input specs")
with spack.solver.asp.disable_compiler_existence_check(): with spack.concretize.disable_compiler_existence_check():
if args.specs: if args.specs:
specs = spack.cmd.parse_specs(args.specs, concretize=True) specs = spack.cmd.parse_specs(args.specs, concretize=True)
if not specs: if not specs:

View File

@ -5,7 +5,8 @@
"""High-level functions to concretize list of specs""" """High-level functions to concretize list of specs"""
import sys import sys
import time import time
from typing import Iterable, Sequence, Tuple, Union from contextlib import contextmanager
from typing import Iterable, Optional, Sequence, Tuple, Union
import llnl.util.tty as tty import llnl.util.tty as tty
@ -14,7 +15,26 @@
import spack.error import spack.error
import spack.repo import spack.repo
import spack.util.parallel import spack.util.parallel
from spack.spec import Spec from spack.spec import ArchSpec, CompilerSpec, Spec
CHECK_COMPILER_EXISTENCE = True
@contextmanager
def disable_compiler_existence_check():
global CHECK_COMPILER_EXISTENCE
CHECK_COMPILER_EXISTENCE, saved = False, CHECK_COMPILER_EXISTENCE
yield
CHECK_COMPILER_EXISTENCE = saved
@contextmanager
def enable_compiler_existence_check():
global CHECK_COMPILER_EXISTENCE
CHECK_COMPILER_EXISTENCE, saved = True, CHECK_COMPILER_EXISTENCE
yield
CHECK_COMPILER_EXISTENCE = saved
SpecPair = Tuple[Spec, Spec] SpecPair = Tuple[Spec, Spec]
SpecLike = Union[Spec, str] SpecLike = Union[Spec, str]
@ -210,3 +230,20 @@ def concretized(spec: Spec, tests: Union[bool, Iterable[str]] = False) -> Spec:
concretized = answer[node] concretized = answer[node]
return concretized return concretized
class UnavailableCompilerVersionError(spack.error.SpackError):
"""Raised when there is no available compiler that satisfies a
compiler spec."""
def __init__(self, compiler_spec: CompilerSpec, arch: Optional[ArchSpec] = None) -> None:
err_msg = f"No compilers with spec {compiler_spec} found"
if arch:
err_msg += f" for operating system {arch.os} and target {arch.target}."
super().__init__(
err_msg,
"Run 'spack compiler find' to add compilers or "
"'spack compilers' to see which compilers are already recognized"
" by spack.",
)

View File

@ -29,6 +29,7 @@
import spack.binary_distribution import spack.binary_distribution
import spack.compiler import spack.compiler
import spack.compilers import spack.compilers
import spack.concretize
import spack.config import spack.config
import spack.deptypes as dt import spack.deptypes as dt
import spack.environment as ev import spack.environment as ev
@ -47,7 +48,6 @@
import spack.version as vn import spack.version as vn
import spack.version.git_ref_lookup import spack.version.git_ref_lookup
from spack import traverse from spack import traverse
from spack.spec import ArchSpec, CompilerSpec
from .core import ( from .core import (
AspFunction, AspFunction,
@ -66,8 +66,6 @@
from .requirements import RequirementKind, RequirementParser, RequirementRule from .requirements import RequirementKind, RequirementParser, RequirementRule
from .version_order import concretization_version_order from .version_order import concretization_version_order
CHECK_COMPILER_EXISTENCE = True
GitOrStandardVersion = Union[spack.version.GitVersion, spack.version.StandardVersion] GitOrStandardVersion = Union[spack.version.GitVersion, spack.version.StandardVersion]
TransformFunction = Callable[[spack.spec.Spec, List[AspFunction]], List[AspFunction]] TransformFunction = Callable[[spack.spec.Spec, List[AspFunction]], List[AspFunction]]
@ -3105,6 +3103,7 @@ def with_input_specs(self, input_specs: List[spack.spec.Spec]) -> "CompilerParse
Args: Args:
input_specs: specs to be concretized input_specs: specs to be concretized
""" """
strict = spack.concretize.CHECK_COMPILER_EXISTENCE
default_os = str(spack.platforms.host().default_os) default_os = str(spack.platforms.host().default_os)
default_target = str(archspec.cpu.host().family) default_target = str(archspec.cpu.host().family)
for s in traverse.traverse_nodes(input_specs): for s in traverse.traverse_nodes(input_specs):
@ -3118,8 +3117,8 @@ def with_input_specs(self, input_specs: List[spack.spec.Spec]) -> "CompilerParse
continue continue
# Error when a compiler is not found and strict mode is enabled # Error when a compiler is not found and strict mode is enabled
if CHECK_COMPILER_EXISTENCE: if strict:
raise UnavailableCompilerVersionError(s.compiler) raise spack.concretize.UnavailableCompilerVersionError(s.compiler)
# Make up a compiler matching the input spec. This is for bootstrapping. # Make up a compiler matching the input spec. This is for bootstrapping.
compiler_cls = spack.compilers.class_for_compiler_name(s.compiler.name) compiler_cls = spack.compilers.class_for_compiler_name(s.compiler.name)
@ -4013,22 +4012,6 @@ def _specs_from_environment_included_concrete(env, included_concrete):
return [] return []
@contextmanager
def disable_compiler_existence_check():
global CHECK_COMPILER_EXISTENCE
CHECK_COMPILER_EXISTENCE, saved = False, CHECK_COMPILER_EXISTENCE
yield
CHECK_COMPILER_EXISTENCE = saved
@contextmanager
def enable_compiler_existence_check():
global CHECK_COMPILER_EXISTENCE
CHECK_COMPILER_EXISTENCE, saved = True, CHECK_COMPILER_EXISTENCE
yield
CHECK_COMPILER_EXISTENCE = saved
class ReuseStrategy(enum.Enum): class ReuseStrategy(enum.Enum):
ROOTS = enum.auto() ROOTS = enum.auto()
DEPENDENCIES = enum.auto() DEPENDENCIES = enum.auto()
@ -4312,20 +4295,3 @@ def __init__(self, provided, conflicts):
class InvalidSpliceError(spack.error.SpackError): class InvalidSpliceError(spack.error.SpackError):
"""For cases in which the splice configuration is invalid.""" """For cases in which the splice configuration is invalid."""
class UnavailableCompilerVersionError(spack.error.SpackError):
"""Raised when there is no available compiler that satisfies a
compiler spec."""
def __init__(self, compiler_spec: CompilerSpec, arch: Optional[ArchSpec] = None) -> None:
err_msg = f"No compilers with spec {compiler_spec} found"
if arch:
err_msg += f" for operating system {arch.os} and target {arch.target}."
super().__init__(
err_msg,
"Run 'spack compiler find' to add compilers or "
"'spack compilers' to see which compilers are already recognized"
" by spack.",
)

View File

@ -11,7 +11,6 @@
import spack.concretize import spack.concretize
import spack.operating_systems import spack.operating_systems
import spack.platforms import spack.platforms
import spack.solver.asp
from spack.spec import ArchSpec, Spec from spack.spec import ArchSpec, Spec
@ -134,6 +133,6 @@ def test_concretize_target_ranges(root_target_range, dep_target_range, result, m
spec = Spec( spec = Spec(
f"pkg-a %gcc@10 foobar=bar target={root_target_range} ^pkg-b target={dep_target_range}" f"pkg-a %gcc@10 foobar=bar target={root_target_range} ^pkg-b target={dep_target_range}"
) )
with spack.solver.asp.disable_compiler_existence_check(): with spack.concretize.disable_compiler_existence_check():
spec = spack.concretize.concretized(spec) spec = spack.concretize.concretized(spec)
assert spec.target == spec["pkg-b"].target == result assert spec.target == spec["pkg-b"].target == result

View File

@ -348,11 +348,11 @@ def test_concretize_with_restricted_virtual(self):
assert concrete["mpich2"].satisfies("mpich2@1.3.1:1.4") assert concrete["mpich2"].satisfies("mpich2@1.3.1:1.4")
def test_concretize_enable_disable_compiler_existence_check(self): def test_concretize_enable_disable_compiler_existence_check(self):
with spack.solver.asp.enable_compiler_existence_check(): with spack.concretize.enable_compiler_existence_check():
with pytest.raises(spack.solver.asp.UnavailableCompilerVersionError): with pytest.raises(spack.concretize.UnavailableCompilerVersionError):
check_concretize("dttop %gcc@=100.100") check_concretize("dttop %gcc@=100.100")
with spack.solver.asp.disable_compiler_existence_check(): with spack.concretize.disable_compiler_existence_check():
spec = check_concretize("dttop %gcc@=100.100") spec = check_concretize("dttop %gcc@=100.100")
assert spec.satisfies("%gcc@100.100") assert spec.satisfies("%gcc@100.100")
assert spec["dtlink3"].satisfies("%gcc@100.100") assert spec["dtlink3"].satisfies("%gcc@100.100")
@ -723,9 +723,9 @@ def test_concretize_propagate_variant_second_level_dep_not_in_source(self):
def test_no_matching_compiler_specs(self, mock_low_high_config): def test_no_matching_compiler_specs(self, mock_low_high_config):
# only relevant when not building compilers as needed # only relevant when not building compilers as needed
with spack.solver.asp.enable_compiler_existence_check(): with spack.concretize.enable_compiler_existence_check():
s = Spec("pkg-a %gcc@=0.0.0") s = Spec("pkg-a %gcc@=0.0.0")
with pytest.raises(spack.solver.asp.UnavailableCompilerVersionError): with pytest.raises(spack.concretize.UnavailableCompilerVersionError):
s = spack.concretize.concretized(s) s = spack.concretize.concretized(s)
def test_no_compilers_for_arch(self): def test_no_compilers_for_arch(self):
@ -951,7 +951,7 @@ def test_adjusting_default_target_based_on_compiler(
): ):
best_achievable = archspec.cpu.TARGETS[best_achievable] best_achievable = archspec.cpu.TARGETS[best_achievable]
expected = best_achievable if best_achievable < current_host else current_host expected = best_achievable if best_achievable < current_host else current_host
with spack.solver.asp.disable_compiler_existence_check(): with spack.concretize.disable_compiler_existence_check():
s = spack.concretize.concretized(Spec(spec)) s = spack.concretize.concretized(Spec(spec))
assert str(s.architecture.target) == str(expected) assert str(s.architecture.target) == str(expected)
@ -966,7 +966,7 @@ def test_compiler_version_matches_any_entry_in_compilers_yaml(self):
) )
# This compiler does not exist # This compiler does not exist
with pytest.raises(spack.solver.asp.UnavailableCompilerVersionError): with pytest.raises(spack.concretize.UnavailableCompilerVersionError):
spack.concretize.concretized(Spec("mpileaks %gcc@=10.2")) spack.concretize.concretized(Spec("mpileaks %gcc@=10.2"))
def test_concretize_anonymous(self): def test_concretize_anonymous(self):

View File

@ -7,8 +7,8 @@
import spack.compilers import spack.compilers
import spack.spec import spack.spec
from spack.concretize import UnavailableCompilerVersionError
from spack.solver import asp from spack.solver import asp
from spack.solver.asp import UnavailableCompilerVersionError
class TestCompilerParser: class TestCompilerParser: