summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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)