spack gc: do not show uninstalled but needed specs (#42696)
This commit is contained in:
@@ -1687,7 +1687,11 @@ def root(key, record):
|
||||
with self.read_transaction():
|
||||
roots = [rec.spec for key, rec in self._data.items() if root(key, rec)]
|
||||
needed = set(id(spec) for spec in tr.traverse_nodes(roots, deptype=deptype))
|
||||
return [rec.spec for rec in self._data.values() if id(rec.spec) not in needed]
|
||||
return [
|
||||
rec.spec
|
||||
for rec in self._data.values()
|
||||
if id(rec.spec) not in needed and rec.installed
|
||||
]
|
||||
|
||||
def update_explicit(self, spec, explicit):
|
||||
"""
|
||||
|
@@ -6,9 +6,11 @@
|
||||
|
||||
import pytest
|
||||
|
||||
import spack.deptypes as dt
|
||||
import spack.environment as ev
|
||||
import spack.main
|
||||
import spack.spec
|
||||
import spack.traverse
|
||||
|
||||
gc = spack.main.SpackCommand("gc")
|
||||
add = spack.main.SpackCommand("add")
|
||||
@@ -19,11 +21,8 @@
|
||||
|
||||
@pytest.mark.db
|
||||
def test_gc_without_build_dependency(config, mutable_database):
|
||||
output = gc("-yb")
|
||||
assert "There are no unused specs." in output
|
||||
|
||||
output = gc("-y")
|
||||
assert "There are no unused specs." in output
|
||||
assert "There are no unused specs." in gc("-yb")
|
||||
assert "There are no unused specs." in gc("-y")
|
||||
|
||||
|
||||
@pytest.mark.db
|
||||
@@ -32,11 +31,9 @@ def test_gc_with_build_dependency(config, mutable_database):
|
||||
s.concretize()
|
||||
s.package.do_install(fake=True, explicit=True)
|
||||
|
||||
output = gc("-yb")
|
||||
assert "There are no unused specs." in output
|
||||
|
||||
output = gc("-y")
|
||||
assert "Successfully uninstalled cmake" in output
|
||||
assert "There are no unused specs." in gc("-yb")
|
||||
assert "Successfully uninstalled cmake" in gc("-y")
|
||||
assert "There are no unused specs." in gc("-y")
|
||||
|
||||
|
||||
@pytest.mark.db
|
||||
@@ -72,34 +69,39 @@ def test_gc_with_build_dependency_in_environment(config, mutable_database, mutab
|
||||
|
||||
with e:
|
||||
assert mutable_database.query_local("simple-inheritance")
|
||||
output = gc("-y")
|
||||
assert "Restricting garbage collection" in output
|
||||
assert "Successfully uninstalled cmake" in output
|
||||
fst = gc("-y")
|
||||
assert "Restricting garbage collection" in fst
|
||||
assert "Successfully uninstalled cmake" in fst
|
||||
snd = gc("-y")
|
||||
assert "Restricting garbage collection" in snd
|
||||
assert "There are no unused specs" in snd
|
||||
|
||||
|
||||
@pytest.mark.db
|
||||
def test_gc_except_any_environments(config, mutable_database, mutable_mock_env_path):
|
||||
s = spack.spec.Spec("simple-inheritance")
|
||||
s.concretize()
|
||||
s.package.do_install(fake=True, explicit=True)
|
||||
|
||||
"""Tests whether the garbage collector can remove all specs except those still needed in some
|
||||
environment (needed in the sense of roots + link/run deps)."""
|
||||
assert mutable_database.query_local("zmpi")
|
||||
|
||||
e = ev.create("test_gc")
|
||||
with e:
|
||||
add("simple-inheritance")
|
||||
install()
|
||||
assert mutable_database.query_local("simple-inheritance")
|
||||
e.add("simple-inheritance")
|
||||
e.concretize()
|
||||
e.install_all(fake=True)
|
||||
e.write()
|
||||
|
||||
assert mutable_database.query_local("simple-inheritance")
|
||||
assert not e.all_matching_specs(spack.spec.Spec("zmpi"))
|
||||
|
||||
output = gc("-yE")
|
||||
assert "Restricting garbage collection" not in output
|
||||
assert "Successfully uninstalled zmpi" in output
|
||||
assert not mutable_database.query_local("zmpi")
|
||||
|
||||
with e:
|
||||
output = gc("-yE")
|
||||
assert "Restricting garbage collection" not in output
|
||||
assert "There are no unused specs" not in output
|
||||
# All runtime specs in this env should still be installed.
|
||||
assert all(
|
||||
s.installed
|
||||
for s in spack.traverse.traverse_nodes(e.concrete_roots(), deptype=dt.LINK | dt.RUN)
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.db
|
||||
|
Reference in New Issue
Block a user