Skip to content

Commit 6b64146

Browse files
committed
build_systems: factored build-time test running into base class
1 parent cf1e03d commit 6b64146

File tree

3 files changed

+29
-32
lines changed

3 files changed

+29
-32
lines changed

lib/spack/spack/build_systems/autotools.py

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,8 @@
3030
from subprocess import PIPE
3131
from subprocess import check_call
3232

33-
import llnl.util.tty as tty
3433
from llnl.util.filesystem import working_dir
35-
from spack.package import PackageBase, run_after, on_package_attributes
34+
from spack.package import PackageBase, run_after
3635

3736

3837
class AutotoolsPackage(PackageBase):
@@ -60,6 +59,8 @@ class AutotoolsPackage(PackageBase):
6059
build_targets = []
6160
install_targets = ['install']
6261

62+
build_time_test_callbacks = ['check']
63+
6364
def do_patch_config_guess(self):
6465
"""Some packages ship with an older config.guess and need to have
6566
this updated when installed on a newer architecture."""
@@ -176,20 +177,7 @@ def install(self, spec, prefix):
176177
with working_dir(self.build_directory()):
177178
inspect.getmodule(self).make(*self.install_targets)
178179

179-
@run_after('build')
180-
@on_package_attributes(run_tests=True)
181-
def _run_default_function(self):
182-
"""This function is run after build if ``self.run_tests == True``
183-
184-
It will search for a method named ``check`` and run it. A sensible
185-
default is provided in the base class.
186-
"""
187-
try:
188-
fn = getattr(self, 'check')
189-
tty.msg('Trying default sanity checks [check]')
190-
fn()
191-
except AttributeError:
192-
tty.msg('Skipping default sanity checks [method `check` not implemented]') # NOQA: ignore=E501
180+
run_after('build')(PackageBase._run_default_build_time_test_callbacks)
193181

194182
def check(self):
195183
"""Default test: search the Makefile for targets ``test`` and ``check``

lib/spack/spack/build_systems/cmake.py

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,10 @@
2626
import inspect
2727
import platform
2828

29-
import llnl.util.tty as tty
3029
import spack.build_environment
3130
from llnl.util.filesystem import working_dir, join_path
3231
from spack.directives import depends_on
33-
from spack.package import PackageBase, run_after, on_package_attributes
32+
from spack.package import PackageBase, run_after
3433

3534

3635
class CMakePackage(PackageBase):
@@ -56,6 +55,8 @@ class CMakePackage(PackageBase):
5655
build_targets = []
5756
install_targets = ['install']
5857

58+
build_time_test_callbacks = ['check']
59+
5960
depends_on('cmake', type='build')
6061

6162
def build_type(self):
@@ -126,20 +127,7 @@ def install(self, spec, prefix):
126127
with working_dir(self.build_directory()):
127128
inspect.getmodule(self).make(*self.install_targets)
128129

129-
@run_after('build')
130-
@on_package_attributes(run_tests=True)
131-
def _run_default_function(self):
132-
"""This function is run after build if ``self.run_tests == True``
133-
134-
It will search for a method named ``check`` and run it. A sensible
135-
default is provided in the base class.
136-
"""
137-
try:
138-
fn = getattr(self, 'check')
139-
tty.msg('Trying default build sanity checks [check]')
140-
fn()
141-
except AttributeError:
142-
tty.msg('Skipping default build sanity checks [method `check` not implemented]') # NOQA: ignore=E501
130+
run_after('build')(PackageBase._run_default_build_time_test_callbacks)
143131

144132
def check(self):
145133
"""Default test: search the Makefile for the target ``test``

lib/spack/spack/package.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1709,6 +1709,27 @@ def rpath_args(self):
17091709
"""
17101710
return " ".join("-Wl,-rpath,%s" % p for p in self.rpath)
17111711

1712+
build_time_test_callbacks = None
1713+
1714+
@on_package_attributes(run_tests=True)
1715+
def _run_default_build_time_test_callbacks(self):
1716+
"""Tries to call all the methods that are listed in the attribute
1717+
``build_time_test_callbacks`` if ``self.run_tests is True``.
1718+
1719+
If ``build_time_test_callbacks is None`` returns immediately.
1720+
"""
1721+
if self.build_time_test_callbacks is None:
1722+
return
1723+
1724+
for name in self.build_time_test_callbacks:
1725+
try:
1726+
fn = getattr(self, name)
1727+
tty.msg('RUN-TESTS: build-time tests [{0}]'.format(name))
1728+
fn()
1729+
except AttributeError:
1730+
msg = 'RUN-TESTS: method not implemented [{0}]'
1731+
tty.warn(msg.format(name))
1732+
17121733

17131734
class Package(PackageBase):
17141735
phases = ['install']

0 commit comments

Comments
 (0)