build systems: simpler, clearer decorators: run_after, run_before (#2860)
* PackageMeta: `run_before` is an alias of `precondition`, `run_after` an alias of `sanity_check` * PackageMeta: removed `precondition` and `sanity_check` * PackageMeta: decorators are now free-standing * package: modified/added docstrings. Fixed the semantics of `on_package_attributes`. * package: added unit test assertion as side effects of install * build_systems: factored build-time test running into base class * r: updated decorators in package.py * docs: updated decorator names
This commit is contained in:

committed by
Todd Gamblin

parent
90d47a3ead
commit
fc866ae0fe
@@ -22,9 +22,10 @@
|
||||
# License along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
##############################################################################
|
||||
from spack import *
|
||||
import os
|
||||
|
||||
from spack import *
|
||||
|
||||
|
||||
def check(condition, msg):
|
||||
"""Raise an install error if condition is False."""
|
||||
@@ -39,6 +40,28 @@ class CmakeClient(CMakePackage):
|
||||
|
||||
version('1.0', '4cb3ff35b2472aae70f542116d616e63')
|
||||
|
||||
callback_counter = 0
|
||||
|
||||
flipped = False
|
||||
run_this = True
|
||||
check_this_is_None = None
|
||||
did_something = False
|
||||
|
||||
@run_after('cmake')
|
||||
@run_before('cmake', 'build', 'install')
|
||||
def increment(self):
|
||||
self.callback_counter += 1
|
||||
|
||||
@run_after('cmake')
|
||||
@on_package_attributes(run_this=True, check_this_is_None=None)
|
||||
def flip(self):
|
||||
self.flipped = True
|
||||
|
||||
@run_after('cmake')
|
||||
@on_package_attributes(does_not_exist=None)
|
||||
def do_not_execute(self):
|
||||
self.did_something = True
|
||||
|
||||
def setup_environment(self, spack_env, run_env):
|
||||
spack_cc # Ensure spack module-scope variable is avaiabl
|
||||
check(from_cmake == "from_cmake",
|
||||
@@ -67,11 +90,15 @@ def setup_dependent_package(self, module, dspec):
|
||||
"setup_dependent_package.")
|
||||
|
||||
def cmake(self, spec, prefix):
|
||||
pass
|
||||
assert self.callback_counter == 1
|
||||
|
||||
build = cmake
|
||||
def build(self, spec, prefix):
|
||||
assert self.did_something is False
|
||||
assert self.flipped is True
|
||||
assert self.callback_counter == 3
|
||||
|
||||
def install(self, spec, prefix):
|
||||
assert self.callback_counter == 4
|
||||
# check that cmake is in the global scope.
|
||||
global cmake
|
||||
check(cmake is not None, "No cmake was in environment!")
|
||||
|
@@ -49,7 +49,7 @@ class Cmor(AutotoolsPackage):
|
||||
depends_on('python@:2.7', when='+python')
|
||||
depends_on('py-numpy', type=('build', 'run'), when='+python')
|
||||
|
||||
@AutotoolsPackage.precondition('configure')
|
||||
@run_before('configure')
|
||||
def validate(self):
|
||||
if '+fortran' in self.spec and not self.compiler.fc:
|
||||
msg = 'cannot build a fortran variant without a fortran compiler'
|
||||
|
@@ -47,7 +47,7 @@ class H5hut(AutotoolsPackage):
|
||||
# install: .libs/libH5hut.a: No such file or directory
|
||||
parallel = False
|
||||
|
||||
@AutotoolsPackage.precondition('configure')
|
||||
@run_before('configure')
|
||||
def validate(self):
|
||||
"""Checks if Fortran compiler is available."""
|
||||
|
||||
|
@@ -70,7 +70,7 @@ class Hdf5(AutotoolsPackage):
|
||||
depends_on('szip', when='+szip')
|
||||
depends_on('zlib@1.1.2:')
|
||||
|
||||
@AutotoolsPackage.precondition('configure')
|
||||
@run_before('configure')
|
||||
def validate(self):
|
||||
"""
|
||||
Checks if incompatible variants have been activated at the same time
|
||||
@@ -170,7 +170,7 @@ def configure(self, spec, prefix):
|
||||
arg for arg in m.group(1).split(' ') if arg != '-l'),
|
||||
'libtool')
|
||||
|
||||
@AutotoolsPackage.sanity_check('install')
|
||||
@run_after('install')
|
||||
def check_install(self):
|
||||
# Build and run a small program to test the installed HDF5 library
|
||||
spec = self.spec
|
||||
|
@@ -86,7 +86,7 @@ def setup_dependent_package(self, module, dep_spec):
|
||||
join_path(self.prefix.lib, 'libmpi.{0}'.format(dso_suffix))
|
||||
]
|
||||
|
||||
@AutotoolsPackage.precondition('autoreconf')
|
||||
@run_before('autoreconf')
|
||||
def die_without_fortran(self):
|
||||
# Until we can pass variants such as +fortran through virtual
|
||||
# dependencies depends_on('mpi'), require Fortran compiler to
|
||||
@@ -106,7 +106,7 @@ def configure_args(self):
|
||||
'--{0}-ibverbs'.format('with' if '+verbs' in spec else 'without')
|
||||
]
|
||||
|
||||
@AutotoolsPackage.sanity_check('install')
|
||||
@run_after('install')
|
||||
def filter_compilers(self):
|
||||
"""Run after install to make the MPI compilers use the
|
||||
compilers that Spack built the package with.
|
||||
|
@@ -68,7 +68,7 @@ def blas_libs(self):
|
||||
def lapack_libs(self):
|
||||
return self.blas_libs
|
||||
|
||||
@MakefilePackage.precondition('edit')
|
||||
@run_before('edit')
|
||||
def check_compilers(self):
|
||||
# As of 06/2016 there is no mechanism to specify that packages which
|
||||
# depends on Blas/Lapack need C or/and Fortran symbols. For now
|
||||
@@ -126,7 +126,7 @@ def build_targets(self):
|
||||
|
||||
return self.make_defs + targets
|
||||
|
||||
@MakefilePackage.sanity_check('build')
|
||||
@run_after('build')
|
||||
def check_build(self):
|
||||
make('tests', *self.make_defs)
|
||||
|
||||
@@ -138,7 +138,7 @@ def install_targets(self):
|
||||
]
|
||||
return make_args + self.make_defs
|
||||
|
||||
@MakefilePackage.sanity_check('install')
|
||||
@run_after('install')
|
||||
def check_install(self):
|
||||
spec = self.spec
|
||||
# Openblas may pass its own test but still fail to compile Lapack
|
||||
|
@@ -145,7 +145,7 @@ def verbs(self):
|
||||
elif self.spec.satisfies('@1.7:'):
|
||||
return 'verbs'
|
||||
|
||||
@AutotoolsPackage.precondition('autoreconf')
|
||||
@run_before('autoreconf')
|
||||
def die_without_fortran(self):
|
||||
# Until we can pass variants such as +fortran through virtual
|
||||
# dependencies depends_on('mpi'), require Fortran compiler to
|
||||
@@ -239,7 +239,7 @@ def configure_args(self):
|
||||
|
||||
return config_args
|
||||
|
||||
@AutotoolsPackage.sanity_check('install')
|
||||
@run_after('install')
|
||||
def filter_compilers(self):
|
||||
"""Run after install to make the MPI compilers use the
|
||||
compilers that Spack built the package with.
|
||||
|
@@ -44,7 +44,7 @@ class PyBasemap(PythonPackage):
|
||||
def setup_environment(self, spack_env, run_env):
|
||||
spack_env.set('GEOS_DIR', self.spec['geos'].prefix)
|
||||
|
||||
@PythonPackage.sanity_check('install')
|
||||
@run_after('install')
|
||||
def post_install_patch(self):
|
||||
spec = self.spec
|
||||
# We are not sure if this fix is needed before Python 3.5.2.
|
||||
|
@@ -95,7 +95,7 @@ class PyMatplotlib(PythonPackage):
|
||||
# depends_on('ttconv')
|
||||
depends_on('py-six@1.9.0:', type=('build', 'run'))
|
||||
|
||||
@PythonPackage.sanity_check('install')
|
||||
@run_after('install')
|
||||
def set_backend(self):
|
||||
spec = self.spec
|
||||
prefix = self.prefix
|
||||
|
@@ -65,7 +65,7 @@ class PyYt(PythonPackage):
|
||||
depends_on("py-sympy", type=('build', 'run'))
|
||||
depends_on("python @2.7:2.999,3.4:")
|
||||
|
||||
@PythonPackage.sanity_check('install')
|
||||
@run_after('install')
|
||||
def check_install(self):
|
||||
# The Python interpreter path can be too long for this
|
||||
# yt = Executable(join_path(prefix.bin, "yt"))
|
||||
|
@@ -113,7 +113,7 @@ def configure_args(self):
|
||||
|
||||
return config_args
|
||||
|
||||
@AutotoolsPackage.sanity_check('install')
|
||||
@run_after('install')
|
||||
def copy_makeconf(self):
|
||||
# Make a copy of Makeconf because it will be needed to properly build R
|
||||
# dependencies in Spack.
|
||||
@@ -121,7 +121,7 @@ def copy_makeconf(self):
|
||||
dst_makeconf = join_path(self.etcdir, 'Makeconf.spack')
|
||||
shutil.copy(src_makeconf, dst_makeconf)
|
||||
|
||||
@AutotoolsPackage.sanity_check('install')
|
||||
@run_after('install')
|
||||
def filter_compilers(self):
|
||||
"""Run after install to tell the configuration files and Makefiles
|
||||
to use the compilers that Spack built the package with.
|
||||
|
@@ -55,7 +55,7 @@ def setup_environment(self, spack_env, env):
|
||||
def build_directory(self):
|
||||
return 'unix'
|
||||
|
||||
@AutotoolsPackage.sanity_check('install')
|
||||
@run_after('install')
|
||||
def symlink_tclsh(self):
|
||||
with working_dir(self.prefix.bin):
|
||||
symlink('tclsh{0}'.format(self.version.up_to(2)), 'tclsh')
|
||||
|
@@ -379,7 +379,7 @@ def cmake_args(self):
|
||||
])
|
||||
return options
|
||||
|
||||
@CMakePackage.sanity_check('install')
|
||||
@run_after('install')
|
||||
def filter_python(self):
|
||||
# When trilinos is built with Python, libpytrilinos is included
|
||||
# through cmake configure files. Namely, Trilinos_LIBRARIES in
|
||||
|
Reference in New Issue
Block a user