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):
|
def _add_dependency(self, spec, deptypes):
|
||||||
"""Called by the parser to add another spec as a dependency."""
|
"""Called by the parser to add another spec as a dependency."""
|
||||||
if spec.name in self._dependencies:
|
if spec.name not in self._dependencies:
|
||||||
# allow redundant compatible dependency specifications
|
self.add_dependency_edge(spec, deptypes)
|
||||||
# depspec equality checks by name, so we need to check components
|
return
|
||||||
# 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)
|
|
||||||
|
|
||||||
# create an edge and add to parent and child
|
# Keep the intersection of constraints when a dependency is added
|
||||||
self.add_dependency_edge(spec, deptypes)
|
# 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):
|
def add_dependency_edge(self, dependency_spec, deptype):
|
||||||
"""Add a dependency edge to this spec.
|
"""Add a dependency edge to this spec.
|
||||||
|
Loading…
Reference in New Issue
Block a user