Simplify repeated _add_dependency calls for same package (#33732)
This commit is contained in:
parent
476e647c94
commit
47df88404a
@ -1558,26 +1558,24 @@ def _set_compiler(self, compiler):
|
||||
|
||||
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)
|
||||
if spec.name not in self._dependencies:
|
||||
self.add_dependency_edge(spec, deptypes)
|
||||
return
|
||||
except spack.error.UnsatisfiableSpecError:
|
||||
raise DuplicateDependencyError(
|
||||
"Cannot depend on incompatible specs '%s' and '%s'"
|
||||
% (dspec.spec, spec)
|
||||
)
|
||||
else:
|
||||
|
||||
# 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)
|
||||
|
||||
# create an edge and add to parent and child
|
||||
self.add_dependency_edge(spec, deptypes)
|
||||
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.
|
||||
|
Loading…
Reference in New Issue
Block a user