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:
		@@ -13,8 +13,9 @@ concretizer:
 | 
			
		||||
  # Whether to consider installed packages or packages from buildcaches when
 | 
			
		||||
  # concretizing specs. If `true`, we'll try to use as many installs/binaries
 | 
			
		||||
  # as possible, rather than building. If `false`, we'll always give you a fresh
 | 
			
		||||
  # concretization.
 | 
			
		||||
  reuse: true
 | 
			
		||||
  # concretization. If `dependencies`, we'll only reuse dependencies but
 | 
			
		||||
  # give you a fresh concretization for your root specs.
 | 
			
		||||
  reuse: dependencies
 | 
			
		||||
  # Options that tune which targets are considered for concretization. The
 | 
			
		||||
  # concretization process is very sensitive to the number targets, and the time
 | 
			
		||||
  # needed to reach a solution increases noticeably with the number of targets
 | 
			
		||||
 
 | 
			
		||||
@@ -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",
 | 
			
		||||
    )
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -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",
 | 
			
		||||
 
 | 
			
		||||
@@ -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
 | 
			
		||||
 
 | 
			
		||||
@@ -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():
 | 
			
		||||
 
 | 
			
		||||
@@ -480,7 +480,7 @@ _spack_bootstrap_mirror() {
 | 
			
		||||
_spack_build_env() {
 | 
			
		||||
    if $list_options
 | 
			
		||||
    then
 | 
			
		||||
        SPACK_COMPREPLY="-h --help --clean --dirty -U --fresh --reuse --dump --pickle"
 | 
			
		||||
        SPACK_COMPREPLY="-h --help --clean --dirty -U --fresh --reuse --reuse-deps --dump --pickle"
 | 
			
		||||
    else
 | 
			
		||||
        _all_packages
 | 
			
		||||
    fi
 | 
			
		||||
@@ -716,7 +716,7 @@ _spack_compilers() {
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
_spack_concretize() {
 | 
			
		||||
    SPACK_COMPREPLY="-h --help -f --force --test -q --quiet -U --fresh --reuse"
 | 
			
		||||
    SPACK_COMPREPLY="-h --help -f --force --test -q --quiet -U --fresh --reuse --reuse-deps"
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
_spack_config() {
 | 
			
		||||
@@ -868,7 +868,7 @@ _spack_deprecate() {
 | 
			
		||||
_spack_dev_build() {
 | 
			
		||||
    if $list_options
 | 
			
		||||
    then
 | 
			
		||||
        SPACK_COMPREPLY="-h --help -j --jobs -d --source-path -i --ignore-dependencies -n --no-checksum --deprecated --keep-prefix --skip-patch -q --quiet --drop-in --test -b --before -u --until --clean --dirty -U --fresh --reuse"
 | 
			
		||||
        SPACK_COMPREPLY="-h --help -j --jobs -d --source-path -i --ignore-dependencies -n --no-checksum --deprecated --keep-prefix --skip-patch -q --quiet --drop-in --test -b --before -u --until --clean --dirty -U --fresh --reuse --reuse-deps"
 | 
			
		||||
    else
 | 
			
		||||
        _all_packages
 | 
			
		||||
    fi
 | 
			
		||||
@@ -1177,7 +1177,7 @@ _spack_info() {
 | 
			
		||||
_spack_install() {
 | 
			
		||||
    if $list_options
 | 
			
		||||
    then
 | 
			
		||||
        SPACK_COMPREPLY="-h --help --only -u --until -j --jobs --overwrite --fail-fast --keep-prefix --keep-stage --dont-restage --use-cache --no-cache --cache-only --use-buildcache --include-build-deps --no-check-signature --show-log-on-error --source -n --no-checksum --deprecated -v --verbose --fake --only-concrete --add --no-add -f --file --clean --dirty --test --log-format --log-file --help-cdash --cdash-upload-url --cdash-build --cdash-site --cdash-track --cdash-buildstamp -y --yes-to-all -U --fresh --reuse"
 | 
			
		||||
        SPACK_COMPREPLY="-h --help --only -u --until -j --jobs --overwrite --fail-fast --keep-prefix --keep-stage --dont-restage --use-cache --no-cache --cache-only --use-buildcache --include-build-deps --no-check-signature --show-log-on-error --source -n --no-checksum --deprecated -v --verbose --fake --only-concrete --add --no-add -f --file --clean --dirty --test --log-format --log-file --help-cdash --cdash-upload-url --cdash-build --cdash-site --cdash-track --cdash-buildstamp -y --yes-to-all -U --fresh --reuse --reuse-deps"
 | 
			
		||||
    else
 | 
			
		||||
        _all_packages
 | 
			
		||||
    fi
 | 
			
		||||
@@ -1449,7 +1449,7 @@ _spack_module_tcl_setdefault() {
 | 
			
		||||
_spack_patch() {
 | 
			
		||||
    if $list_options
 | 
			
		||||
    then
 | 
			
		||||
        SPACK_COMPREPLY="-h --help -n --no-checksum --deprecated -U --fresh --reuse"
 | 
			
		||||
        SPACK_COMPREPLY="-h --help -n --no-checksum --deprecated -U --fresh --reuse --reuse-deps"
 | 
			
		||||
    else
 | 
			
		||||
        _all_packages
 | 
			
		||||
    fi
 | 
			
		||||
@@ -1677,7 +1677,7 @@ _spack_restage() {
 | 
			
		||||
_spack_solve() {
 | 
			
		||||
    if $list_options
 | 
			
		||||
    then
 | 
			
		||||
        SPACK_COMPREPLY="-h --help --show -l --long -L --very-long -I --install-status -y --yaml -j --json -c --cover -N --namespaces -t --types --timers --stats -U --fresh --reuse"
 | 
			
		||||
        SPACK_COMPREPLY="-h --help --show -l --long -L --very-long -I --install-status -y --yaml -j --json -c --cover -N --namespaces -t --types --timers --stats -U --fresh --reuse --reuse-deps"
 | 
			
		||||
    else
 | 
			
		||||
        _all_packages
 | 
			
		||||
    fi
 | 
			
		||||
@@ -1686,7 +1686,7 @@ _spack_solve() {
 | 
			
		||||
_spack_spec() {
 | 
			
		||||
    if $list_options
 | 
			
		||||
    then
 | 
			
		||||
        SPACK_COMPREPLY="-h --help -l --long -L --very-long -I --install-status -y --yaml -j --json --format -c --cover -N --namespaces -t --types -U --fresh --reuse"
 | 
			
		||||
        SPACK_COMPREPLY="-h --help -l --long -L --very-long -I --install-status -y --yaml -j --json --format -c --cover -N --namespaces -t --types -U --fresh --reuse --reuse-deps"
 | 
			
		||||
    else
 | 
			
		||||
        _all_packages
 | 
			
		||||
    fi
 | 
			
		||||
@@ -1695,7 +1695,7 @@ _spack_spec() {
 | 
			
		||||
_spack_stage() {
 | 
			
		||||
    if $list_options
 | 
			
		||||
    then
 | 
			
		||||
        SPACK_COMPREPLY="-h --help -n --no-checksum --deprecated -p --path -U --fresh --reuse"
 | 
			
		||||
        SPACK_COMPREPLY="-h --help -n --no-checksum --deprecated -p --path -U --fresh --reuse --reuse-deps"
 | 
			
		||||
    else
 | 
			
		||||
        _all_packages
 | 
			
		||||
    fi
 | 
			
		||||
@@ -1785,7 +1785,7 @@ _spack_test_remove() {
 | 
			
		||||
_spack_test_env() {
 | 
			
		||||
    if $list_options
 | 
			
		||||
    then
 | 
			
		||||
        SPACK_COMPREPLY="-h --help --clean --dirty -U --fresh --reuse --dump --pickle"
 | 
			
		||||
        SPACK_COMPREPLY="-h --help --clean --dirty -U --fresh --reuse --reuse-deps --dump --pickle"
 | 
			
		||||
    else
 | 
			
		||||
        _all_packages
 | 
			
		||||
    fi
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user