summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/spack/spack/spec.py36
1 files changed, 17 insertions, 19 deletions
diff --git a/lib/spack/spack/spec.py b/lib/spack/spack/spec.py
index 30a67a55a8..ef4c3b7ab0 100644
--- a/lib/spack/spack/spec.py
+++ b/lib/spack/spack/spec.py
@@ -1558,26 +1558,24 @@ class Spec(object):
def _add_dependency(self, spec, deptypes):
"""Called by the parser to add another spec as a dependency."""
- if spec.name in self._dependencies:
- # allow redundant compatible dependency specifications
- # depspec equality checks by name, so we need to check components
- # separately to test whether the specs are identical
- orig = self._dependencies[spec.name]
- for dspec in orig:
- if deptypes == dspec.deptypes:
- try:
- dspec.spec.constrain(spec)
- return
- except spack.error.UnsatisfiableSpecError:
- raise DuplicateDependencyError(
- "Cannot depend on incompatible specs '%s' and '%s'"
- % (dspec.spec, spec)
- )
- else:
- raise DuplicateDependencyError("Cannot depend on '%s' twice" % spec)
+ if spec.name not in self._dependencies:
+ self.add_dependency_edge(spec, deptypes)
+ return
- # create an edge and add to parent and child
- self.add_dependency_edge(spec, deptypes)
+ # Keep the intersection of constraints when a dependency is added
+ # multiple times. Currently we only allow identical edge types.
+ orig = self._dependencies[spec.name]
+ try:
+ dspec = next(dspec for dspec in orig if deptypes == dspec.deptypes)
+ except StopIteration:
+ raise DuplicateDependencyError("Cannot depend on '%s' twice" % spec)
+
+ try:
+ dspec.spec.constrain(spec)
+ except spack.error.UnsatisfiableSpecError:
+ raise DuplicateDependencyError(
+ "Cannot depend on incompatible specs '%s' and '%s'" % (dspec.spec, spec)
+ )
def add_dependency_edge(self, dependency_spec, deptype):
"""Add a dependency edge to this spec.