summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGregory Becker <becker33@llnl.gov>2019-07-23 09:37:48 -0500
committerTodd Gamblin <tgamblin@llnl.gov>2019-07-23 08:58:49 -0700
commita086dda82f2f4cab362f59a71958602f9fc31d94 (patch)
treef5ec4839f4bb1c2a24a901ffe393b9d52dc9885c
parent4ff277370410e0551ed4a21da87d3da39d63638e (diff)
downloadspack-a086dda82f2f4cab362f59a71958602f9fc31d94.tar.gz
spack-a086dda82f2f4cab362f59a71958602f9fc31d94.tar.bz2
spack-a086dda82f2f4cab362f59a71958602f9fc31d94.tar.xz
spack-a086dda82f2f4cab362f59a71958602f9fc31d94.zip
hashing: fix caching of dependency hashes in to_node_dict
-rw-r--r--lib/spack/spack/hash_types.py11
-rw-r--r--lib/spack/spack/spec.py17
2 files changed, 17 insertions, 11 deletions
diff --git a/lib/spack/spack/hash_types.py b/lib/spack/spack/hash_types.py
index 01e31bb465..e4a238a93b 100644
--- a/lib/spack/spack/hash_types.py
+++ b/lib/spack/spack/hash_types.py
@@ -18,19 +18,22 @@ class SpecHashDescriptor(object):
We currently use different hashes for different use cases.
"""
- def __init__(self, deptype=('link', 'run'), package_hash=False):
+ def __init__(self, deptype=('link', 'run'), package_hash=False, attr=None):
self.deptype = dp.canonical_deptype(deptype)
self.package_hash = package_hash
+ self.attr = attr
#: Default Hash descriptor, used by Spec.dag_hash() and stored in the DB.
-dag_hash = SpecHashDescriptor(deptype=('link', 'run'), package_hash=False)
+dag_hash = SpecHashDescriptor(deptype=('link', 'run'), package_hash=False,
+ attr='_hash')
#: Hash descriptor that includes build dependencies.
build_hash = SpecHashDescriptor(
- deptype=('build', 'link', 'run'), package_hash=False)
+ deptype=('build', 'link', 'run'), package_hash=False, attr='_build_hash')
#: Full hash used in build pipelines to determine when to rebuild packages.
-full_hash = SpecHashDescriptor(deptype=('link', 'run'), package_hash=True)
+full_hash = SpecHashDescriptor(deptype=('link', 'run'), package_hash=True,
+ attr='_full_hash')
diff --git a/lib/spack/spack/spec.py b/lib/spack/spack/spec.py
index 009775acf4..6636f15c51 100644
--- a/lib/spack/spack/spec.py
+++ b/lib/spack/spack/spec.py
@@ -1305,7 +1305,7 @@ class Spec(object):
return b32_hash
- def _cached_hash(self, length, attr, 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
@@ -1315,13 +1315,16 @@ class Spec(object):
Arguments:
hash (SpecHashDescriptor): type of hash to generate.
"""
- hash_string = getattr(self, attr, None)
+ if not hash.attr:
+ 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)
if self.concrete:
- setattr(self, attr, hash_string)
+ setattr(self, hash.attr, hash_string)
return hash_string[:length]
@@ -1333,7 +1336,7 @@ class Spec(object):
revise this to include more detailed provenance when the
concretizer can more aggressievly reuse installed dependencies.
"""
- return self._cached_hash(length, '_hash', ht.dag_hash)
+ return self._cached_hash(ht.dag_hash, length)
def build_hash(self, length=None):
"""Hash used to store specs in environments.
@@ -1341,7 +1344,7 @@ class Spec(object):
This hash includes build dependencies, and we need to preserve
them to be able to rebuild an entire environment for a user.
"""
- return self._cached_hash(length, '_build_hash', ht.build_hash)
+ return self._cached_hash(ht.build_hash, length)
def full_hash(self, length=None):
"""Hash to determine when to rebuild packages in the build pipeline.
@@ -1352,7 +1355,7 @@ class Spec(object):
TODO: investigate whether to include build deps here.
"""
- return self._cached_hash(length, '_full_hash', ht.full_hash)
+ return self._cached_hash(ht.full_hash, length)
def dag_hash_bit_prefix(self, bits):
"""Get the first <bits> bits of the DAG hash as an integer type."""
@@ -1456,7 +1459,7 @@ class Spec(object):
d['dependencies'] = syaml_dict([
(name,
syaml_dict([
- ('hash', dspec.spec._spec_hash(hash)),
+ ('hash', dspec.spec._cached_hash(hash)),
('type', sorted(str(s) for s in dspec.deptypes))])
) for name, dspec in sorted(deps.items())
])