Generalize package relations like depends_on, provides, conflicts.
All of these do the same thing. So they are all now generalized to a single closure function; just the name of the updated variable in the package is different.
This commit is contained in:
parent
6cf6eac3de
commit
1247036141
3 changed files with 34 additions and 19 deletions
|
@ -255,6 +255,11 @@ class SomePackage(Package):
|
||||||
"""List of specs of virtual packages provided by this package."""
|
"""List of specs of virtual packages provided by this package."""
|
||||||
provided = {}
|
provided = {}
|
||||||
|
|
||||||
|
"""List of specs of conflicting packages.
|
||||||
|
TODO: implement conflicts.
|
||||||
|
"""
|
||||||
|
conflicted = {}
|
||||||
|
|
||||||
#
|
#
|
||||||
# These are default values for instance variables.
|
# These are default values for instance variables.
|
||||||
#
|
#
|
||||||
|
|
|
@ -62,23 +62,28 @@ def _caller_locals():
|
||||||
del stack
|
del stack
|
||||||
|
|
||||||
|
|
||||||
def depends_on(*specs):
|
def _make_relation(map_name):
|
||||||
"""Adds a dependencies local variable in the locals of
|
def relation_fun(*specs):
|
||||||
the calling class, based on args.
|
package_map = _caller_locals().setdefault(map_name, {})
|
||||||
"""
|
for string in specs:
|
||||||
# Get the enclosing package's scope and add deps to it.
|
for spec in spack.spec.parse(string):
|
||||||
dependencies = _caller_locals().setdefault("dependencies", {})
|
package_map[spec.name] = spec
|
||||||
for string in specs:
|
return relation_fun
|
||||||
for spec in spack.spec.parse(string):
|
|
||||||
dependencies[spec.name] = spec
|
|
||||||
|
|
||||||
|
|
||||||
def provides(*args):
|
"""Adds a dependencies local variable in the locals of
|
||||||
"""Allows packages to provide a virtual dependency. If a package provides
|
the calling class, based on args. """
|
||||||
"mpi", other packages can declare that they depend on "mpi", and spack
|
depends_on = _make_relation("dependencies")
|
||||||
can use the providing package to satisfy the dependency.
|
|
||||||
"""
|
|
||||||
# Get the enclosing package's scope and add deps to it.
|
"""Allows packages to provide a virtual dependency. If a package provides
|
||||||
provided = _caller_locals().setdefault("provided", [])
|
'mpi', other packages can declare that they depend on "mpi", and spack
|
||||||
for name in args:
|
can use the providing package to satisfy the dependency.
|
||||||
provided.append(name)
|
"""
|
||||||
|
provides = _make_relation("provided")
|
||||||
|
|
||||||
|
|
||||||
|
"""Packages can declare conflicts with other packages.
|
||||||
|
This can be as specific as you like: use regular spec syntax.
|
||||||
|
"""
|
||||||
|
conflicts = _make_relation("conflicted")
|
||||||
|
|
|
@ -394,7 +394,12 @@ def preorder_traversal(self, visited=None, d=0, **kwargs):
|
||||||
|
|
||||||
|
|
||||||
def _concretize_helper(self, presets):
|
def _concretize_helper(self, presets):
|
||||||
"""Recursive helper function for concretize()."""
|
"""Recursive helper function for concretize().
|
||||||
|
This concretizes everything bottom-up. As things are
|
||||||
|
concretized, they're added to the presets, and ancestors
|
||||||
|
will prefer the settings of their children.
|
||||||
|
"""
|
||||||
|
# Concretize deps first -- this is a bottom-up process.
|
||||||
for name in sorted(self.dependencies.keys()):
|
for name in sorted(self.dependencies.keys()):
|
||||||
self.dependencies[name]._concretize_helper(presets)
|
self.dependencies[name]._concretize_helper(presets)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue