diff --git a/loopy/target/c/c_execution.py b/loopy/target/c/c_execution.py index f7622936c05207c02f8f7065f44b75f3fbff6221..60947c7f77d09582868304ded121386bbb3aab68 100644 --- a/loopy/target/c/c_execution.py +++ b/loopy/target/c/c_execution.py @@ -236,7 +236,11 @@ class CCompiler(object): libraries=[], library_dirs=[], defines=[], - source_suffix='c') + undefines=[], + source_suffix='c', + so_ext='.so', + o_ext='.o', + include_dirs=[]) if toolchain is None: # copy in all differing values @@ -283,15 +287,16 @@ class CCompiler(object): class CPlusPlusCompiler(CCompiler): """Subclass of CCompiler to invoke a C++ compiler.""" - def __init__(self, cc='g++', cflags='-std=c++98 -O3 -fPIC'.split(), + def __init__(self, toolchain=None, + cc='g++', cflags='-std=c++98 -O3 -fPIC'.split(), ldflags=[], libraries=[], include_dirs=[], library_dirs=[], defines=[], source_suffix='cpp'): super(CPlusPlusCompiler, self).__init__( - cc=cc, cflags=cflags, ldflags=ldflags, libraries=libraries, - include_dirs=include_dirs, library_dirs=library_dirs, - defines=defines, source_suffix=source_suffix) + toolchain=toolchain, cc=cc, cflags=cflags, ldflags=ldflags, + libraries=libraries, include_dirs=include_dirs, + library_dirs=library_dirs, defines=defines, source_suffix=source_suffix) class IDIToCDLL(object): diff --git a/test/test_c_execution.py b/test/test_c_execution.py index c355893e4c08f405c6a09cca43849489c145bc4d..bf168c11d838248947a2806123053e63c13ccbeb 100644 --- a/test/test_c_execution.py +++ b/test/test_c_execution.py @@ -323,14 +323,24 @@ def test_missing_compilers(): b=np.arange(10, dtype=np.int32))[1], np.arange(10)) import os path_store = os.environ["PATH"] + ccomp = None try: # test with path wiped out such that we can't find gcc with pytest.raises(ExecError): os.environ["PATH"] = '' - __test(eval_tester, ExecutableCTarget) + ccomp = CCompiler() + __test(eval_tester, ExecutableCTarget, compiler=ccomp) finally: - # make sure we restore the path regardless for future testing + # make sure we restore the path os.environ["PATH"] = path_store + # and, with the path restored we should now be able to properly execute with + # the default (non-guessed) toolchain! + __test(eval_tester, ExecutableCTarget, compiler=ccomp) + + # and test that we will fail if we remove a required attribute + del ccomp.toolchain.undefines + with pytest.raises(AttributeError): + __test(eval_tester, ExecutableCTarget, compiler=ccomp) # next test that some made up compiler can be specified ccomp = CCompiler(cc='foo')