From 848de2153c56dd558e78e843defd02fef5804a92 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eric=20M=C3=BCller?= Date: Fri, 26 Nov 2021 11:18:13 +0100 Subject: [PATCH] [spack] Add test support --- spack/package.py | 40 ++++++++++++++++++++++++++++++++-------- 1 file changed, 32 insertions(+), 8 deletions(-) diff --git a/spack/package.py b/spack/package.py index ab062893a4..b33450c38a 100644 --- a/spack/package.py +++ b/spack/package.py @@ -4,6 +4,7 @@ # SPDX-License-Identifier: (Apache-2.0 OR MIT) from spack import * +import glob class Genn(PythonPackage): @@ -16,23 +17,30 @@ class Genn(PythonPackage): version('4.6.0', sha256='5e5ca94fd3a56b5b963a4911ea1b2130df6fa7dcdde3b025bd8cb85d4c2d3236') conflicts('%gcc@:4.9.3') - depends_on('gmake', type='build') + depends_on('gmake', type='build') + depends_on('googletest', type=('build', 'run', 'test')) + depends_on('lcov', type=('build', 'run', 'test')) variant('cuda', default=True, description='Enable CUDA support') depends_on('cuda', when='+cuda') variant('python', default=True, description='Enable PyGeNN') extends('python', when='+python') - depends_on('python@3.8.0:', when='+python') - depends_on('py-numpy@1.17.0:', when='+python') - depends_on('py-six', when='+python') - depends_on('py-deprecated', when='+python') - depends_on('py-psutil', when='+python') - depends_on('py-importlib-metadata@1.0.0:', when='+python') - depends_on('swig', when='+python') + depends_on('python@3.8.0:', when='+python', type=('build', 'run', 'test')) + depends_on('py-numpy@1.17.0:', when='+python', type=('build', 'run', 'test')) + depends_on('py-six', when='+python', type=('build', 'run', 'test')) + depends_on('py-deprecated', when='+python', type=('build', 'run', 'test')) + depends_on('py-psutil', when='+python', type=('build', 'run', 'test')) + depends_on('py-importlib-metadata@1.0.0:', when='+python', type=('build', 'run', 'test')) + depends_on('swig', when='+python', type=('build', 'run', 'test')) patch('include_path.patch') + def patch(self): + files = glob.glob("tests/**/Makefile", recursive=True) + filter_file('\$\(GTEST_DIR\)/src/gtest-all\.cc \$\(GTEST_DIR\)/src/gtest_main\.cc', + '-L$(GTEST_DIR) -lgtest', *files) + def build(self, spec, prefix): make('PREFIX={}'.format(prefix), 'install') if '+python' in self.spec: @@ -44,6 +52,8 @@ def install(self, spec, prefix): install_tree('include', prefix.include) mkdirp(prefix.src.genn) install_tree('src/genn', prefix.src.genn) + install_tree('tests', prefix.tests) + install('version.txt', prefix) if '+python' in self.spec: super(Genn, self).install(spec, prefix) @@ -53,3 +63,17 @@ def setup_run_environment(self, env): env.append_path('CUDA_PATH', self.spec['cuda'].prefix) if '+python' in self.spec: super(Genn, self).setup_run_environment(env) + + def test(self): + env['GTEST_DIR'] = self.spec['googletest'].prefix + # workaround for https://github.com/spack/spack/issues/20553 + env['PATH'] = '{}:{}'.format(self.spec['lcov'].prefix.bin, env['PATH']) + # overriding automatic python testing + with working_dir(self.prefix.tests): + # FIXME: + # * expects a non-zero return code for errors + # * also too slow for a simple install test? + # ⇒ provide another simple install test? + self.run_test('run_tests.sh') + if '+python' in self.spec: + super(Genn, self).test(self)