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.
This commit is contained in:
parent
9fa99030eb
commit
50f74c117e
1 changed files with 15 additions and 14 deletions
|
@ -270,12 +270,6 @@ def concrete(self):
|
|||
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 @@ def __str__(self):
|
|||
|
||||
@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 @@ def prefix(self):
|
|||
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 @@ def write(s, c):
|
|||
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 @@ def tree(self, **kwargs):
|
|||
return out
|
||||
|
||||
|
||||
def sha1(self):
|
||||
sha = hashlib.sha1()
|
||||
sha.update(str(self))
|
||||
return sha.hexdigest()
|
||||
|
||||
|
||||
def __repr__(self):
|
||||
return str(self)
|
||||
|
||||
|
|
Loading…
Reference in a new issue