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.""" """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.
# #

View File

@ -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, {})
"""
# Get the enclosing package's scope and add deps to it.
dependencies = _caller_locals().setdefault("dependencies", {})
for string in specs: for string in specs:
for spec in spack.spec.parse(string): for spec in spack.spec.parse(string):
dependencies[spec.name] = spec package_map[spec.name] = spec
return relation_fun
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")
"""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. can use the providing package to satisfy the dependency.
""" """
# Get the enclosing package's scope and add deps to it. provides = _make_relation("provided")
provided = _caller_locals().setdefault("provided", [])
for name in args:
provided.append(name) """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): 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)