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