diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/spack/spack/cmd/gc.py | 8 | ||||
-rw-r--r-- | lib/spack/spack/test/cmd/gc.py | 16 |
2 files changed, 23 insertions, 1 deletions
diff --git a/lib/spack/spack/cmd/gc.py b/lib/spack/spack/cmd/gc.py index c7d023602e..63e7aacfb8 100644 --- a/lib/spack/spack/cmd/gc.py +++ b/lib/spack/spack/cmd/gc.py @@ -41,7 +41,7 @@ def setup_parser(subparser): help="do not remove installed build-only dependencies of roots\n" "(default is to keep only link & run dependencies)", ) - spack.cmd.common.arguments.add_common_arguments(subparser, ["yes_to_all"]) + spack.cmd.common.arguments.add_common_arguments(subparser, ["yes_to_all", "constraint"]) def roots_from_environments(args, active_env): @@ -97,6 +97,12 @@ def gc(parser, args): root_hashes = None specs = spack.store.STORE.db.unused_specs(root_hashes=root_hashes, deptype=deptype) + + # limit search to constraint specs if provided + if args.constraint: + hashes = set(spec.dag_hash() for spec in args.specs()) + specs = [spec for spec in specs if spec.dag_hash() in hashes] + if not specs: tty.msg("There are no unused specs. Spack's store is clean.") return diff --git a/lib/spack/spack/test/cmd/gc.py b/lib/spack/spack/test/cmd/gc.py index 2eab41a4fb..d997be59b2 100644 --- a/lib/spack/spack/test/cmd/gc.py +++ b/lib/spack/spack/test/cmd/gc.py @@ -36,6 +36,22 @@ def test_gc_with_build_dependency(mutable_database): @pytest.mark.db +def test_gc_with_constraints(mutable_database): + s_cmake1 = spack.spec.Spec("simple-inheritance ^cmake@3.4.3").concretized() + s_cmake2 = spack.spec.Spec("simple-inheritance ^cmake@3.23.1").concretized() + PackageInstaller([s_cmake1.package], explicit=True, fake=True).install() + PackageInstaller([s_cmake2.package], explicit=True, fake=True).install() + + assert "There are no unused specs." in gc("python") + + assert "Successfully uninstalled cmake@3.4.3" in gc("-y", "cmake@3.4.3") + assert "There are no unused specs." in gc("-y", "cmake@3.4.3") + + assert "Successfully uninstalled cmake" in gc("-y", "cmake@3.23.1") + assert "There are no unused specs." in gc("-y", "cmake") + + +@pytest.mark.db def test_gc_with_environment(mutable_database, mutable_mock_env_path): s = spack.spec.Spec("simple-inheritance") s.concretize() |