Move concretization into its own class.

Allows easy overriding of a single policy.
This commit is contained in:
Todd Gamblin 2013-11-23 15:18:43 -08:00
parent f31aaeed98
commit 6cf6eac3de
5 changed files with 73 additions and 56 deletions

View File

@ -15,7 +15,13 @@
from spack.spec import *
def concretize_version(spec):
class DefaultConcretizer(object):
"""This class doesn't have any state, it just provides some methods for
concretization. You can subclass it to override just some of the
default concretization strategies, or you can override all of them.
"""
def concretize_version(self, spec):
"""If the spec is already concrete, return. Otherwise take
the most recent available version, and default to the package's
version if there are no avaialble versions.
@ -34,7 +40,7 @@ def concretize_version(spec):
spec.versions = ver([pkg.version])
def concretize_architecture(spec):
def concretize_architecture(self, spec):
"""If the spec already had an architecture, return. Otherwise if
the root of the DAG has an architecture, then use that.
Otherwise take the system's default architecture.
@ -57,7 +63,7 @@ def concretize_architecture(spec):
spec.architecture = spack.arch.sys_type()
def concretize_compiler(spec):
def concretize_compiler(self, spec):
"""Currently just sets the compiler to gcc or throws an exception
if the compiler is set to something else.

View File

@ -5,6 +5,7 @@
from spack.util.filesystem import *
from spack.util.executable import *
from spack.directory_layout import DefaultDirectoryLayout
from spack.concretize import DefaultConcretizer
# This lives in $prefix/lib/spac/spack/__file__
prefix = ancestor(__file__, 4)
@ -31,6 +32,13 @@
#
install_layout = DefaultDirectoryLayout(install_path)
#
# This controls how things are concretized in spack.
# Replace it with a subclass if you want different
# policies.
#
concretizer = DefaultConcretizer()
# Version information
spack_version = Version("0.5")

View File

@ -81,4 +81,4 @@ def provides(*args):
# Get the enclosing package's scope and add deps to it.
provided = _caller_locals().setdefault("provided", [])
for name in args:
provides.append(name)
provided.append(name)

View File

@ -67,7 +67,6 @@
import tty
import spack.parse
import spack.error
import spack.concretize
import spack.compilers
import spack.compilers.gcc
import spack.packages as packages
@ -330,6 +329,8 @@ def virtual(self):
"""Right now, a spec is virtual if no package exists with its name.
TODO: revisit this -- might need to use a separate namespace and
be more explicit about this.
Possible idea: just use conventin and make virtual deps all
caps, e.g., MPI vs mpi.
"""
return not packages.exists(self.name)
@ -400,9 +401,9 @@ def _concretize_helper(self, presets):
if self.name in presets:
self.constrain(presets[self.name])
else:
spack.concretize.concretize_architecture(self)
spack.concretize.concretize_compiler(self)
spack.concretize.concretize_version(self)
spack.concretizer.concretize_architecture(self)
spack.concretizer.concretize_compiler(self)
spack.concretizer.concretize_version(self)
presets[self.name] = self

View File

@ -10,6 +10,8 @@ class Mpich(Package):
versions = '1.0.3, 1.3.2p1, 1.4.1p1, 3.0.4, 3.1b1'
provides('mpi')
def install(self, prefix):
configure("--prefix=%s" % prefix)
make()