From 497b426aa37fb0e5948b38be58c9f0f5958cc4a8 Mon Sep 17 00:00:00 2001 From: Theofilos Manitaras Date: Tue, 24 Nov 2020 16:59:04 +0100 Subject: [PATCH 1/3] Fix SingleSource when guessing of language fails * The SingleSource build system now raises an exception when it fails to guess the programming language of the source file. * Add unittests. --- reframe/core/buildsystems.py | 6 +++--- unittests/test_buildsystems.py | 17 +++++++++++++++++ unittests/test_pipeline.py | 15 +++++++++++++++ 3 files changed, 35 insertions(+), 3 deletions(-) diff --git a/reframe/core/buildsystems.py b/reframe/core/buildsystems.py index ee820c45f7..7c1338ad3e 100644 --- a/reframe/core/buildsystems.py +++ b/reframe/core/buildsystems.py @@ -375,7 +375,6 @@ def emit_build_commands(self, environ): raise BuildSystemError( 'a source file is required when using the %s build system' % type(self).__name__) - cc = self._cc(environ) cxx = self._cxx(environ) ftn = self._ftn(environ) @@ -426,8 +425,9 @@ def emit_build_commands(self, environ): cmd_parts += [nvcc, *cppflags, *cxxflags, self.srcfile, '-o', executable, *ldflags] else: - BuildSystemError('could not guess language of file: %s' % - self.srcfile) + raise BuildSystemError( + f'could not guess language of file: {self.srcfile}' + ) return [' '.join(cmd_parts)] diff --git a/unittests/test_buildsystems.py b/unittests/test_buildsystems.py index 3cf698aaff..0fa886d332 100644 --- a/unittests/test_buildsystems.py +++ b/unittests/test_buildsystems.py @@ -235,3 +235,20 @@ def test_compiler_pick(lang): } assert ([f'{compilers[lang]} {build_system.srcfile} -o foo.x'] == build_system.emit_build_commands(ProgEnvironment('testenv'))) + + +def test_singlesource_unknown_language(): + build_system = bs.SingleSource() + build_system.cc = 'cc' + build_system.cxx = 'CC' + build_system.ftn = 'ftn' + build_system.nvcc = 'nvcc' + build_system.srcfile = 'foo.bar' + compilers = { + 'C': build_system.cc, + 'C++': build_system.cxx, + 'Fortran': build_system.ftn, + 'CUDA': build_system.nvcc + } + with pytest.raises(BuildSystemError, match='could not guess language'): + build_system.emit_build_commands(ProgEnvironment('testenv')) diff --git a/unittests/test_pipeline.py b/unittests/test_pipeline.py index 1e330a072f..b4187fdf35 100644 --- a/unittests/test_pipeline.py +++ b/unittests/test_pipeline.py @@ -457,6 +457,21 @@ def __init__(self): test.compile() +def test_sourcepath_non_existent(local_exec_ctx): + @fixtures.custom_prefix('unittests/resources/checks') + class MyTest(rfm.CompileOnlyRegressionTest): + def __init__(self): + self.valid_prog_environs = ['*'] + self.valid_systems = ['*'] + + test = MyTest() + test.setup(*local_exec_ctx) + test.sourcepath = 'non_existent.c' + test.compile() + with pytest.raises(BuildError): + test.compile_wait() + + def test_extra_resources(testsys_system): @fixtures.custom_prefix('unittests/resources/checks') class MyTest(HelloTest): From c579d36e0cf131da6a91614caa350b78cb685bbd Mon Sep 17 00:00:00 2001 From: Theofilos Manitaras Date: Tue, 24 Nov 2020 17:09:43 +0100 Subject: [PATCH 2/3] Fix deleted line --- reframe/core/buildsystems.py | 1 + 1 file changed, 1 insertion(+) diff --git a/reframe/core/buildsystems.py b/reframe/core/buildsystems.py index 7c1338ad3e..db16ca3fb5 100644 --- a/reframe/core/buildsystems.py +++ b/reframe/core/buildsystems.py @@ -375,6 +375,7 @@ def emit_build_commands(self, environ): raise BuildSystemError( 'a source file is required when using the %s build system' % type(self).__name__) + cc = self._cc(environ) cxx = self._cxx(environ) ftn = self._ftn(environ) From 699899efe0659687639ef47739ab36058bd4c0de Mon Sep 17 00:00:00 2001 From: Theofilos Manitaras Date: Wed, 25 Nov 2020 16:56:30 +0100 Subject: [PATCH 3/3] Address PR comments --- unittests/test_buildsystems.py | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/unittests/test_buildsystems.py b/unittests/test_buildsystems.py index 0fa886d332..fdd2017715 100644 --- a/unittests/test_buildsystems.py +++ b/unittests/test_buildsystems.py @@ -239,16 +239,6 @@ def test_compiler_pick(lang): def test_singlesource_unknown_language(): build_system = bs.SingleSource() - build_system.cc = 'cc' - build_system.cxx = 'CC' - build_system.ftn = 'ftn' - build_system.nvcc = 'nvcc' build_system.srcfile = 'foo.bar' - compilers = { - 'C': build_system.cc, - 'C++': build_system.cxx, - 'Fortran': build_system.ftn, - 'CUDA': build_system.nvcc - } with pytest.raises(BuildSystemError, match='could not guess language'): build_system.emit_build_commands(ProgEnvironment('testenv'))