diff options
author | Harmen Stoppels <harmenstoppels@gmail.com> | 2022-11-07 16:33:18 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-11-07 16:33:18 +0100 |
commit | 47df88404ae2fd1e662660f4f355152645c0490a (patch) | |
tree | be71c8030d114a6c54d71ee1ea61d0d59bbf6357 /lib | |
parent | 476e647c942add4d2cbb7700fecf0f3f5b75fcd8 (diff) | |
download | spack-47df88404ae2fd1e662660f4f355152645c0490a.tar.gz spack-47df88404ae2fd1e662660f4f355152645c0490a.tar.bz2 spack-47df88404ae2fd1e662660f4f355152645c0490a.tar.xz spack-47df88404ae2fd1e662660f4f355152645c0490a.zip |
Simplify repeated _add_dependency calls for same package (#33732)
Diffstat (limited to 'lib')
-rw-r--r-- | lib/spack/spack/spec.py | 36 |
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. |