concretizer: add mode to reuse dependencies only (#30990)

This adds a new mode for `concretizer:reuse` called `dependencies`,
which only reuses dependencies. Currently, `spack install foo` will
reuse older versions of `foo`, which might be surprising to users.
This commit is contained in:
Michael Kuhn
2023-03-14 09:22:20 +01:00
committed by GitHub
parent 03636cd6ac
commit 5bae742826
6 changed files with 40 additions and 23 deletions

View File

@@ -514,7 +514,15 @@ def add_concretizer_args(subparser):
dest="concretizer:reuse",
const=True,
default=None,
help="reuse installed dependencies/buildcaches when possible",
help="reuse installed packages/buildcaches when possible",
)
subgroup.add_argument(
"--reuse-deps",
action=ConfigSetAction,
dest="concretizer:reuse",
const="dependencies",
default=None,
help="reuse installed dependencies only",
)

View File

@@ -14,7 +14,9 @@
"type": "object",
"additionalProperties": False,
"properties": {
"reuse": {"type": "boolean"},
"reuse": {
"oneOf": [{"type": "boolean"}, {"type": "string", "enum": ["dependencies"]}]
},
"enable_node_namespace": {"type": "boolean"},
"targets": {
"type": "object",

View File

@@ -2502,7 +2502,7 @@ def _check_input_and_extract_concrete_specs(specs):
spack.spec.Spec.ensure_valid_variants(s)
return reusable
def _reusable_specs(self):
def _reusable_specs(self, specs):
reusable_specs = []
if self.reuse:
# Specs from the local Database
@@ -2524,6 +2524,13 @@ def _reusable_specs(self):
# TODO: update mirror configuration so it can indicate that the
# TODO: source cache (or any mirror really) doesn't have binaries.
pass
# If we only want to reuse dependencies, remove the root specs
if self.reuse == "dependencies":
reusable_specs = [
spec for spec in reusable_specs if not any(root in spec for root in specs)
]
return reusable_specs
def solve(self, specs, out=None, timers=False, stats=False, tests=False, setup_only=False):
@@ -2540,7 +2547,7 @@ def solve(self, specs, out=None, timers=False, stats=False, tests=False, setup_o
"""
# Check upfront that the variants are admissible
reusable_specs = self._check_input_and_extract_concrete_specs(specs)
reusable_specs.extend(self._reusable_specs())
reusable_specs.extend(self._reusable_specs(specs))
setup = SpackSolverSetup(tests=tests)
output = OutputConfiguration(timers=timers, stats=stats, out=out, setup_only=setup_only)
result, _, _ = self.driver.solve(setup, specs, reuse=reusable_specs, output=output)
@@ -2563,7 +2570,7 @@ def solve_in_rounds(self, specs, out=None, timers=False, stats=False, tests=Fals
tests (bool): add test dependencies to the solve
"""
reusable_specs = self._check_input_and_extract_concrete_specs(specs)
reusable_specs.extend(self._reusable_specs())
reusable_specs.extend(self._reusable_specs(specs))
setup = SpackSolverSetup(tests=tests)
# Tell clingo that we don't have to solve all the inputs at once

View File

@@ -122,19 +122,18 @@ def test_root_and_dep_match_returns_root(mock_packages, mutable_mock_env_path):
assert env_spec2
def test_concretizer_arguments(mutable_config, mock_packages):
@pytest.mark.parametrize(
"arg,config", [("--reuse", True), ("--fresh", False), ("--reuse-deps", "dependencies")]
)
def test_concretizer_arguments(mutable_config, mock_packages, arg, config):
"""Ensure that ConfigSetAction is doing the right thing."""
spec = spack.main.SpackCommand("spec")
assert spack.config.get("concretizer:reuse", None) is None
spec("--reuse", "zlib")
spec(arg, "zlib")
assert spack.config.get("concretizer:reuse", None) is True
spec("--fresh", "zlib")
assert spack.config.get("concretizer:reuse", None) is False
assert spack.config.get("concretizer:reuse", None) == config
def test_use_buildcache_type():