Пример #1
0
def test_create_include():
    r"""Test create_include."""
    target = 'target'
    tempdir = tempfile.gettempdir()
    fname_dll = os.path.join(tempdir, 'test.dll')
    fname_lib = os.path.join(tempdir, 'test.lib')
    for fname in [fname_dll, fname_lib]:
        with open(fname, 'w') as fd:
            fd.write('')
        assert(os.path.isfile(fname))
    testlist = [(['-DYGG'], [], ['ADD_DEFINITIONS(-DYGG)']),
                (['-Wall'], [], ['ADD_DEFINITIONS(-Wall)']),
                (['/nologo'], [], ['ADD_DEFINITIONS(/nologo)']),
                (['-Iinclude_dir'], [], ['INCLUDE_DIRECTORIES(include_dir)']),
                ([], ['-lm'], ['TARGET_LINK_LIBRARIES(%s -lm)' % target]),
                ([], ['-Llib_dir'], ['LINK_DIRECTORIES(lib_dir)']),
                ([], ['/LIBPATH:"lib_dir"'], ['LINK_DIRECTORIES(lib_dir)']),
                ([], ['m'], ['TARGET_LINK_LIBRARIES(%s m)' % target])]
    if CMakeConfigure.add_libraries:  # pragma: debug
        testlist += [([], [fname_dll], ['ADD_LIBRARY(test SHARED IMPORTED)']),
                     ([], [fname_lib], ['ADD_LIBRARY(test STATIC IMPORTED)'])]
    else:
        tempdir_cp = tempdir
        if platform._is_win:  # pragma: windows
            tempdir_cp = tempdir.replace('\\', re.escape('\\'))
        testlist += [([], [fname_dll], [('FIND_LIBRARY(TEST_LIBRARY NAMES %s '
                                         'test HINTS %s)')
                                        % (os.path.basename(fname_dll), tempdir_cp)]),
                     ([], [fname_lib], [('FIND_LIBRARY(TEST_LIBRARY NAMES %s '
                                         'test HINTS %s)')
                                        % (os.path.basename(fname_lib), tempdir_cp)])]
    from yggdrasil.drivers.CModelDriver import CModelDriver
    CModelDriver.compile_dependencies()
    CMakeModelDriver.compile_dependencies()
    kws = {'compiler': CModelDriver.get_tool('compiler'),
           'linker': CModelDriver.get_tool('linker')}
    for c, l, lines in testlist:
        out = CMakeConfigure.create_include(None, target, compiler_flags=c,
                                            linker_flags=l, verbose=True,
                                            **kws)
        for x in lines:
            try:
                assert(x in out)
            except AssertionError:  # pragma: debug
                print("Could not find '%s':" % x)
                pprint.pprint(out)
                raise
    for fname in [fname_dll, fname_lib]:
        os.remove(fname)
    assert_raises(ValueError, CMakeConfigure.create_include,
                  None, target, compiler_flags=['invalid'], **kws)
    assert_raises(ValueError, CMakeConfigure.create_include,
                  None, target, linker_flags=['-invalid'], **kws)
    assert_raises(ValueError, CMakeConfigure.create_include,
                  None, target, linker_flags=['/invalid'], **kws)
Пример #2
0
 def __init__(self, *args, **kwargs):
     super(TestCModelParam, self).__init__(*args, **kwargs)
     script_dir = os.path.dirname(self.src[0])
     self.args = [self.args[0], '1']
     if CModelDriver.is_installed():
         compiler = CModelDriver.get_tool('compiler')
         linker = CModelDriver.get_tool('linker')
         include_flag = compiler.create_flag('include_dirs', script_dir)
         library_flag = linker.create_flag('library_dirs', script_dir)
         self._inst_kwargs.update(compiler_flags=include_flag,
                                  linker_flags=library_flag)
Пример #3
0
def test_GCCCompiler_dll2a():
    r"""Test the dll2a method of the GCCCompiler class."""
    gcc = CModelDriver.get_tool('compiler', toolname='gcc', default=None)
    if gcc:
        kws = {'toolname': 'gcc'}
        if platform._is_win:
            kws['libtype'] = 'shared'
        dll = CModelDriver.get_dependency_library('python', **kws)
        gcc.dll2a(dll, overwrite=True)
    else:
        with pytest.raises(NotImplementedError):
            CModelDriver.get_tool('compiler', toolname='gcc')
Пример #4
0
def test_get_compilation_tool():
    r"""Test get_compilation_tool for different name variations."""
    from yggdrasil.drivers.CModelDriver import CModelDriver
    if CModelDriver.is_language_installed():
        tooltype = 'compiler'
        out = CModelDriver.get_tool('compiler').__class__
        toolname = out.toolname.lower()
        toolpath = os.path.join('somedir', toolname)
        toolfile = toolpath + '.exe'
        vals = [toolpath, toolfile]
        if platform._is_win:
            vals += [toolname.upper(), toolfile.upper()]
        for v in vals:
            assert_equal(CompiledModelDriver.get_compilation_tool(tooltype, v),
                         out)
        assert_raises(ValueError, CompiledModelDriver.get_compilation_tool,
                      'compiler', 'invalid')
    # else:
    #     assert_raises(NotImplementedError, CModelDriver.get_tool, 'compiler')
    #     assert_equal(CModelDriver.get_tool(
    #         'compiler', default='invalid'), 'invalid')
    assert_equal(
        CompiledModelDriver.get_compilation_tool('compiler',
                                                 'invalid',
                                                 default='invalid'), 'invalid')
Пример #5
0
def test_get_compilation_tool():
    r"""Test get_compilation_tool for different name variations."""
    from yggdrasil.drivers.CModelDriver import CModelDriver
    tooltype = 'compiler'
    out = CModelDriver.get_tool('compiler').__class__
    toolname = out.toolname.lower()
    toolpath = os.path.join('somedir', toolname)
    toolfile = toolpath + '.exe'
    vals = [toolname.upper(), toolpath, toolfile, toolfile.upper()]
    for v in vals:
        assert_equal(CompiledModelDriver.get_compilation_tool(tooltype, v), out)
    assert_raises(ValueError, CompiledModelDriver.get_compilation_tool,
                  'compiler', 'invalid')
Пример #6
0
    def set_env(self):
        r"""Get environment variables that should be set for the model process.

        Returns:
            dict: Environment variables for the model process.

        """
        out = super(RModelDriver, self).set_env()
        out['RETICULATE_PYTHON'] = PythonModelDriver.get_interpreter()
        c_linker = CModelDriver.get_tool('linker')
        search_dirs = c_linker.get_search_path(conda_only=True)
        out = CModelDriver.update_ld_library_path(out,
                                                  paths_to_add=search_dirs,
                                                  add_to_front=True)
        return out