bugfix: tests trying to ignore package changes should use build_hash

- [x] update test to use `build_hash` instead of `dag_hash`, as we're testing for
      graph structure, and specifically NOT testing for package changes.
- [x] make hash descriptors callable on specs to simplify syntax for invoking them
- [x] make `Spec.spec_hash()` public
This commit is contained in:
Todd Gamblin 2022-04-29 09:59:59 -07:00
parent 7c1d566959
commit 15eb98368d
3 changed files with 15 additions and 5 deletions

View file

@ -33,6 +33,10 @@ def attr(self):
"""Private attribute stored on spec"""
return '_' + self.name
def __call__(self, spec):
"""Run this hash on the provided spec."""
return spec.spec_hash(self)
#: Spack's deployment hash. Includes all inputs that can affect how a package is built.
dag_hash = SpecHashDescriptor(

View file

@ -1754,7 +1754,7 @@ def prefix(self):
def prefix(self, value):
self._prefix = spack.util.prefix.Prefix(pth.convert_to_platform_path(value))
def _spec_hash(self, hash):
def spec_hash(self, hash):
"""Utility method for computing different types of Spec hashes.
Arguments:
@ -1771,7 +1771,7 @@ def _spec_hash(self, hash):
def _cached_hash(self, hash, length=None):
"""Helper function for storing a cached hash on the spec.
This will run _spec_hash() with the deptype and package_hash
This will run spec_hash() with the deptype and package_hash
parameters, and if this spec is concrete, it will store the value
in the supplied attribute on this spec.
@ -1779,13 +1779,13 @@ def _cached_hash(self, hash, length=None):
hash (spack.hash_types.SpecHashDescriptor): type of hash to generate.
"""
if not hash.attr:
return self._spec_hash(hash)[:length]
return self.spec_hash(hash)[:length]
hash_string = getattr(self, hash.attr, None)
if hash_string:
return hash_string[:length]
else:
hash_string = self._spec_hash(hash)
hash_string = self.spec_hash(hash)
if self.concrete:
setattr(self, hash.attr, hash_string)

View file

@ -16,6 +16,7 @@
import spack.compilers
import spack.concretize
import spack.error
import spack.hash_types as ht
import spack.platforms
import spack.repo
import spack.variant as vt
@ -1287,7 +1288,12 @@ def test_reuse_installed_packages_when_package_def_changes(
new_root_without_reuse = Spec('root').concretized()
assert root.dag_hash() == new_root_with_reuse.dag_hash()
# validate that the graphs are the same with reuse, but not without
assert ht.build_hash(root) == ht.build_hash(new_root_with_reuse)
assert ht.build_hash(root) != ht.build_hash(new_root_without_reuse)
# package hashes are different, so dag hashes will be different
assert root.dag_hash() != new_root_with_reuse.dag_hash()
assert root.dag_hash() != new_root_without_reuse.dag_hash()
@pytest.mark.regression('20784')