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:
Todd Gamblin 2013-11-23 15:46:04 -08:00
parent 6cf6eac3de
commit 1247036141
3 changed files with 34 additions and 19 deletions

View file

@ -255,6 +255,11 @@ class SomePackage(Package):
"""List of specs of virtual packages provided by this package."""
provided = {}
"""List of specs of conflicting packages.
TODO: implement conflicts.
"""
conflicted = {}
#
# These are default values for instance variables.
#

View file

@ -62,23 +62,28 @@ def _caller_locals():
del stack
def depends_on(*specs):
"""Adds a dependencies local variable in the locals of
the calling class, based on args.
"""
# Get the enclosing package's scope and add deps to it.
dependencies = _caller_locals().setdefault("dependencies", {})
for string in specs:
for spec in spack.spec.parse(string):
dependencies[spec.name] = spec
def _make_relation(map_name):
def relation_fun(*specs):
package_map = _caller_locals().setdefault(map_name, {})
for string in specs:
for spec in spack.spec.parse(string):
package_map[spec.name] = spec
return relation_fun
def provides(*args):
"""Allows packages to provide a virtual dependency. If a package provides
"mpi", other packages can declare that they depend on "mpi", and spack
can use the providing package to satisfy the dependency.
"""
# Get the enclosing package's scope and add deps to it.
provided = _caller_locals().setdefault("provided", [])
for name in args:
provided.append(name)
"""Adds a dependencies local variable in the locals of
the calling class, based on args. """
depends_on = _make_relation("dependencies")
"""Allows packages to provide a virtual dependency. If a package provides
'mpi', other packages can declare that they depend on "mpi", and spack
can use the providing package to satisfy the dependency.
"""
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")

View file

@ -394,7 +394,12 @@ def preorder_traversal(self, visited=None, d=0, **kwargs):
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()):
self.dependencies[name]._concretize_helper(presets)