From addcde4f358061053b013374bcf7400ef28acd4f Mon Sep 17 00:00:00 2001 From: Gregory Becker Date: Fri, 6 May 2016 12:05:27 -0700 Subject: [PATCH] Made spec hashes immutable once concrete --- lib/spack/spack/spec.py | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/lib/spack/spack/spec.py b/lib/spack/spack/spec.py index 8ff8281d5e5..b71c1d680c0 100644 --- a/lib/spack/spack/spec.py +++ b/lib/spack/spack/spec.py @@ -486,6 +486,7 @@ def __init__(self, spec_like, *dep_like, **kwargs): self.variants = other.variants self.variants.spec = self self.namespace = other.namespace + self.hash = other.hash # Specs are by default not assumed to be normal, but in some # cases we've read them from a file want to assume normal. @@ -754,12 +755,16 @@ def dag_hash(self, length=None): """ Return a hash of the entire spec DAG, including connectivity. """ - yaml_text = yaml.dump( - self.to_node_dict(), default_flow_style=True, width=sys.maxint) -# print yaml_text - sha = hashlib.sha1(yaml_text) - return base64.b32encode(sha.digest()).lower()[:length] - + if self.hash: + return self.hash + else: + yaml_text = yaml.dump( + self.to_node_dict(), default_flow_style=True, width=sys.maxint) + sha = hashlib.sha1(yaml_text) + b32_hash = base64.b32encode(sha.digest()).lower()[:length] + if self._concrete: + self.hash = b32_hash + return b32_hash def to_node_dict(self): params = dict( (name, v.value) for name, v in self.variants.items() ) @@ -2128,6 +2133,7 @@ def spec(self, name, check_valid_token = False): spec.dependents = DependencyMap() spec.dependencies = DependencyMap() spec.namespace = spec_namespace + spec.hash = None spec._normal = False spec._concrete = False