summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTodd Gamblin <tgamblin@llnl.gov>2014-04-14 14:11:58 -0700
committerTodd Gamblin <tgamblin@llnl.gov>2014-04-14 14:11:58 -0700
commit50f74c117e52ecd9bd2594ccbdc9caaffba19c01 (patch)
tree5dffc77b8e997a9d7319f11db54c7b6278b8b501
parent9fa99030eb1958b5bf2e1693443556438f363c30 (diff)
downloadspack-50f74c117e52ecd9bd2594ccbdc9caaffba19c01.tar.gz
spack-50f74c117e52ecd9bd2594ccbdc9caaffba19c01.tar.bz2
spack-50f74c117e52ecd9bd2594ccbdc9caaffba19c01.tar.xz
spack-50f74c117e52ecd9bd2594ccbdc9caaffba19c01.zip
Fix for SPACK-22: Consistent dependency hashing.
The dependency hash wasn't being generated in a consistent way: when read from .spec file in the install directory, the spec DAG was not normalized, but when generated on install, it was. Thus the same spec can have two possible hashes, which is obviously not good. In this commit: - Added a dep_hash function to spec, which should be used to get the dependency hash in all cases. This function normalizes the spec before generating the hash. - removed sha1 functions from Spec and DependencyHash. The one on Spec is not needed and is confusing (it hashed the whole spec, not just hash the deps) and the one on DependencyHash wasn't guaranteed to be safe because it can't normalize its parent spec before hashing. Hopefully this makes things consistent and easy.
-rw-r--r--lib/spack/spack/spec.py29
1 files changed, 15 insertions, 14 deletions
diff --git a/lib/spack/spack/spec.py b/lib/spack/spack/spec.py
index 6ec66d1afa..275372f1ba 100644
--- a/lib/spack/spack/spec.py
+++ b/lib/spack/spack/spec.py
@@ -270,12 +270,6 @@ class DependencyMap(HashableMap):
return all(d.concrete for d in self.values())
- def sha1(self):
- sha = hashlib.sha1()
- sha.update(str(self))
- return sha.hexdigest()
-
-
def __str__(self):
sorted_dep_names = sorted(self.keys())
return ''.join(
@@ -284,7 +278,7 @@ class DependencyMap(HashableMap):
@key_ordering
class Spec(object):
- def __init__(self, spec_like, *dep_like):
+ def __init__(self, spec_like, *dep_like, **kwargs):
# Copy if spec_like is a Spec.
if isinstance(spec_like, Spec):
self._dup(spec_like)
@@ -477,6 +471,19 @@ class Spec(object):
return Prefix(spack.install_layout.path_for_spec(self))
+ def dep_hash(self, length=None):
+ """Return a hash representing the dependencies of this spec
+ This will always normalize first so that the hash is consistent.
+ """
+ self.normalize()
+
+ sha = hashlib.sha1()
+ sha.update(str(self.dependencies))
+ full_hash = sha.hexdigest()
+
+ return full_hash[:length]
+
+
def _concretize_helper(self, presets=None, visited=None):
"""Recursive helper function for concretize().
This concretizes everything bottom-up. As things are
@@ -1047,7 +1054,7 @@ class Spec(object):
write(c + str(self.architecture), c)
elif c == '#':
if self.dependencies:
- out.write('-' + self.dependencies.sha1()[:8])
+ out.write('-' + self.dep_hash(8))
elif c == '$':
out.write('$')
escape = False
@@ -1111,12 +1118,6 @@ class Spec(object):
return out
- def sha1(self):
- sha = hashlib.sha1()
- sha.update(str(self))
- return sha.hexdigest()
-
-
def __repr__(self):
return str(self)