From 1247036141c1d063f3abd448bb4877659d979bf1 Mon Sep 17 00:00:00 2001 From: Todd Gamblin Date: Sat, 23 Nov 2013 15:46:04 -0800 Subject: 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. --- lib/spack/spack/package.py | 5 +++++ lib/spack/spack/relations.py | 41 +++++++++++++++++++++++------------------ lib/spack/spack/spec.py | 7 ++++++- 3 files changed, 34 insertions(+), 19 deletions(-) (limited to 'lib') diff --git a/lib/spack/spack/package.py b/lib/spack/spack/package.py index e15a1f97eb..59ce6afd7e 100644 --- a/lib/spack/spack/package.py +++ b/lib/spack/spack/package.py @@ -255,6 +255,11 @@ class Package(object): """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. # diff --git a/lib/spack/spack/relations.py b/lib/spack/spack/relations.py index 0d1983257b..323c9db2ac 100644 --- a/lib/spack/spack/relations.py +++ b/lib/spack/spack/relations.py @@ -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") diff --git a/lib/spack/spack/spec.py b/lib/spack/spack/spec.py index d14957c23b..e6d508c074 100644 --- a/lib/spack/spack/spec.py +++ b/lib/spack/spack/spec.py @@ -394,7 +394,12 @@ class Spec(object): 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) -- cgit v1.2.3-70-g09d2