Merge pull request #232 from LLNL/bugfix/package-cache-217

Bugfix/package cache 217
This commit is contained in:
Todd Gamblin 2015-12-14 19:54:57 -08:00
commit 3d39d035c1
3 changed files with 26 additions and 16 deletions

View File

@ -67,27 +67,28 @@ def get(self, spec, **kwargs):
if spec.virtual:
raise UnknownPackageError(spec.name)
key = hash(spec)
if kwargs.get('new', False):
if spec in self.instances:
del self.instances[spec]
if key in self.instances:
del self.instances[key]
if not spec in self.instances:
if not key in self.instances:
package_class = self.get_class_for_package_name(spec.name)
try:
copy = spec.copy()
self.instances[copy] = package_class(copy)
copy = spec.copy() # defensive copy. Package owns its spec.
self.instances[key] = package_class(copy)
except Exception, e:
if spack.debug:
sys.excepthook(*sys.exc_info())
raise FailedConstructorError(spec.name, e)
return self.instances[spec]
return self.instances[key]
@_autospec
def delete(self, spec):
"""Force a package to be recreated."""
del self.instances[spec]
del self.instances[spec.dag_hash()]
def purge(self):

View File

@ -1481,8 +1481,11 @@ def ne_dag(self, other):
def _cmp_node(self):
"""Comparison key for just *this node* and not its deps."""
return (self.name, self.versions, self.variants,
self.architecture, self.compiler)
return (self.name,
self.versions,
self.variants,
self.architecture,
self.compiler)
def eq_node(self, other):
@ -1496,11 +1499,15 @@ def ne_node(self, other):
def _cmp_key(self):
"""Comparison key for this node and all dependencies *without*
considering structure. This is the default, as
normalization will restore structure.
"""This returns a key for the spec *including* DAG structure.
The key is the concatenation of:
1. A tuple describing this node in the DAG.
2. The hash of each of this node's dependencies' cmp_keys.
"""
return self._cmp_node() + (self.sorted_deps(),)
return self._cmp_node() + (
tuple(hash(self.dependencies[name])
for name in sorted(self.dependencies)),)
def colorized(self):

View File

@ -340,16 +340,18 @@ def test_normalize_mpileaks(self):
self.assertEqual(spec, expected_flat)
self.assertTrue(spec.eq_dag(expected_flat))
self.assertEqual(spec, expected_normalized)
# Normalized has different DAG structure, so NOT equal.
self.assertNotEqual(spec, expected_normalized)
self.assertFalse(spec.eq_dag(expected_normalized))
self.assertEqual(spec, non_unique_nodes)
# Again, different DAG structure so not equal.
self.assertNotEqual(spec, non_unique_nodes)
self.assertFalse(spec.eq_dag(non_unique_nodes))
spec.normalize()
# After normalizing, spec_dag_equal should match the normalized spec.
self.assertEqual(spec, expected_flat)
self.assertNotEqual(spec, expected_flat)
self.assertFalse(spec.eq_dag(expected_flat))
self.assertEqual(spec, expected_normalized)