Ejemplo n.º 1
0
    def test_32bit_makefile(self):
        if platform.machine() != 'i386':
            py.test.skip("i386 only")
        plat32 = Darwin_i386()
        plat64 = Darwin_x86_64()
        eci = ExternalCompilationInfo()
        cfile_content =r'''
        #include <stdio.h>
        #include <limits.h>

        int main() {
                printf("%d\n", INT_MAX < LONG_MAX);
                return 0;
        }
        '''

        tmpdir = udir.join('32_makefile' + self.__class__.__name__).ensure(dir=1)
        cfile = tmpdir.join('test_int_size.c')
        cfile.write(cfile_content)
        mk = plat32.gen_makefile([cfile], ExternalCompilationInfo(),
                               path=tmpdir)
        mk.write()
        plat32.execute_makefile(mk)
        res = plat32.execute(tmpdir.join('test_int_size'))
        self.check_res(res, '0\n')
        if host_factory == Darwin_x86_64:
            tmpdir = udir.join('64_makefile' + self.__class__.__name__).ensure(dir=1)
            cfile = tmpdir.join('test_int_size.c')
            cfile.write(cfile_content)
            mk = plat64.gen_makefile([cfile], ExternalCompilationInfo(),
                                   path=tmpdir)
            mk.write()
            plat64.execute_makefile(mk)
            res = plat64.execute(tmpdir.join('test_int_size'))
            self.check_res(res, '1\n')
Ejemplo n.º 2
0
 def test_merge2(self):
     e1 = ExternalCompilationInfo(pre_include_bits=['1'],
                                  link_files=['1.c'])
     e2 = ExternalCompilationInfo(pre_include_bits=['2'],
                                  link_files=['1.c', '2.c'])
     e3 = ExternalCompilationInfo(pre_include_bits=['3'],
                                  link_files=['1.c', '2.c', '3.c'])
     e = e1.merge(e2)
     e = e.merge(e3, e3)
     assert e.pre_include_bits == ('1', '2', '3')
     assert e.link_files == ('1.c', '2.c', '3.c')
Ejemplo n.º 3
0
 def test_convert_sources_to_c_files(self):
     eci = ExternalCompilationInfo(
         separate_module_sources = ['xxx'],
         separate_module_files = ['x.c'],
     )
     cache_dir = udir.join('test_convert_sources').ensure(dir=1)
     neweci = eci.convert_sources_to_files(cache_dir)
     assert not neweci.separate_module_sources
     res = neweci.separate_module_files
     assert len(res) == 2
     assert res[0] == 'x.c'
     assert str(res[1]).startswith(str(cache_dir))
     e = ExternalCompilationInfo()
     assert e.convert_sources_to_files() is e
Ejemplo n.º 4
0
 def test_merge(self):
     e1 = ExternalCompilationInfo(pre_include_bits=['1'],
                                  includes=['x.h'],
                                  post_include_bits=['p1'])
     e2 = ExternalCompilationInfo(
         pre_include_bits=['2'],
         includes=['x.h', 'y.h'],
         post_include_bits=['p2'],
     )
     e3 = ExternalCompilationInfo(pre_include_bits=['3'],
                                  includes=['y.h', 'z.h'],
                                  post_include_bits=['p1', 'p3'])
     e = e1.merge(e2, e3)
     assert e.pre_include_bits == ('1', '2', '3')
     assert e.includes == ('x.h', 'y.h', 'z.h')
     assert e.post_include_bits == ('p1', 'p2', 'p3')
Ejemplo n.º 5
0
 def test_from_linker_flags(self):
     flags = ('-L/some/lib/path -L/other/lib/path '
              '-lmylib1 -lmylib2 -?1 -!2')
     eci = ExternalCompilationInfo.from_linker_flags(flags)
     assert eci.libraries == ('mylib1', 'mylib2')
     assert eci.library_dirs == ('/some/lib/path', '/other/lib/path')
     assert eci.link_extra == ('-?1', '-!2')
Ejemplo n.º 6
0
 def test_nice_errors(self):
     cfile = udir.join('test_nice_errors.c')
     cfile.write('')
     try:
         self.platform.compile([cfile], ExternalCompilationInfo())
     except CompilationError, e:
         filename = cfile.dirpath().join(cfile.purebasename + '.errors')
         assert filename.read('r') == e.err
Ejemplo n.º 7
0
 def test_merge2(self):
     e1 = ExternalCompilationInfo(
         pre_include_bits  = ['1'],
         link_files = ['1.c']
     )
     e2 = ExternalCompilationInfo(
         pre_include_bits  = ['2'],
         link_files = ['1.c', '2.c']
     )
     e3 = ExternalCompilationInfo(
         pre_include_bits  = ['3'],
         link_files = ['1.c', '2.c', '3.c']
     )
     e = e1.merge(e2)
     e = e.merge(e3, e3)
     assert e.pre_include_bits == ('1', '2', '3')
     assert e.link_files == ('1.c', '2.c', '3.c')
Ejemplo n.º 8
0
 def test_from_linker_flags(self):
     flags = ('-L/some/lib/path -L/other/lib/path '
              '-lmylib1 -lmylib2 -?1 -!2')
     eci = ExternalCompilationInfo.from_linker_flags(flags)
     assert eci.libraries == ('mylib1', 'mylib2')
     assert eci.library_dirs == ('/some/lib/path',
                                 '/other/lib/path')
     assert eci.link_extra == ('-?1', '-!2')
Ejemplo n.º 9
0
    def test_standalone_library(self):
        tmpdir = udir.join('standalone_library').ensure(dir=1)
        c_file = tmpdir.join('stand1.c')
        c_file.write('''
        #include <math.h>
        #include <stdio.h>

        int main()
        {
            printf("%f\\n", pow(2.0, 2.0));
        }''')
        if sys.platform != 'win32':
            eci = ExternalCompilationInfo(libraries=['m'], )
        else:
            eci = ExternalCompilationInfo()
        executable = self.platform.compile([c_file], eci)
        res = self.platform.execute(executable)
        assert res.out.startswith('4.0')
Ejemplo n.º 10
0
 def test_make_shared_lib(self):
     eci = ExternalCompilationInfo(separate_module_sources=[
         '''
         int get()
         {
             return 42;
         }'''
     ],
                                   export_symbols=['get'])
     neweci = eci.compile_shared_lib()
     assert len(neweci.libraries) == 1
     try:
         import ctypes
     except ImportError:
         py.test.skip("Need ctypes for that test")
     assert ctypes.CDLL(neweci.libraries[0]).get() == 42
     assert not neweci.separate_module_sources
     assert not neweci.separate_module_files
Ejemplo n.º 11
0
 def test_make_shared_lib(self):
     eci = ExternalCompilationInfo(
         separate_module_sources = ['''
         int get()
         {
             return 42;
         }'''],
         export_symbols = ['get']
     )
     neweci = eci.compile_shared_lib()
     assert len(neweci.libraries) == 1
     try:
         import ctypes
     except ImportError:
         py.test.skip("Need ctypes for that test")
     assert ctypes.CDLL(neweci.libraries[0]).get() == 42
     assert not neweci.separate_module_sources
     assert not neweci.separate_module_files
Ejemplo n.º 12
0
    def test_platforms(self):
        from platformer import Platform

        class Maemo(Platform):
            def __init__(self, cc=None):
                self.cc = cc
        
        eci = ExternalCompilationInfo(platform=Maemo())
        eci2 = ExternalCompilationInfo()
        assert eci != eci2
        assert hash(eci) != hash(eci2)
        assert repr(eci) != repr(eci2)
        py.test.raises(Exception, eci2.merge, eci)
        assert eci.merge(eci).platform == Maemo()
        assert (ExternalCompilationInfo(platform=Maemo(cc='xxx')) !=
                ExternalCompilationInfo(platform=Maemo(cc='yyy')))
        assert (repr(ExternalCompilationInfo(platform=Maemo(cc='xxx'))) !=
                repr(ExternalCompilationInfo(platform=Maemo(cc='yyy'))))
Ejemplo n.º 13
0
 def test_from_compiler_flags(self):
     flags = ('-I/some/include/path -I/other/include/path '
              '-DMACRO1 -D_MACRO2=baz -?1 -!2')
     eci = ExternalCompilationInfo.from_compiler_flags(flags)
     assert eci.pre_include_bits == ('#define MACRO1 1',
                                     '#define _MACRO2 baz')
     assert eci.includes == ()
     assert eci.include_dirs == ('/some/include/path',
                                 '/other/include/path')
     assert eci.compile_extra == ('-?1', '-!2')
Ejemplo n.º 14
0
 def test_from_compiler_flags(self):
     flags = ('-I/some/include/path -I/other/include/path '
              '-DMACRO1 -D_MACRO2=baz -?1 -!2')
     eci = ExternalCompilationInfo.from_compiler_flags(flags)
     assert eci.pre_include_bits == ('#define MACRO1 1',
                                     '#define _MACRO2 baz')
     assert eci.includes == ()
     assert eci.include_dirs == ('/some/include/path',
                                 '/other/include/path')
     assert eci.compile_extra == ('-?1', '-!2')
Ejemplo n.º 15
0
 def test_merge(self):
     e1 = ExternalCompilationInfo(
         pre_include_bits   = ['1'],
         includes           = ['x.h'],
         post_include_bits  = ['p1']
     )
     e2 = ExternalCompilationInfo(
         pre_include_bits   = ['2'],
         includes           = ['x.h', 'y.h'],
         post_include_bits  = ['p2'],
     )
     e3 = ExternalCompilationInfo(
         pre_include_bits   = ['3'],
         includes           = ['y.h', 'z.h'],
         post_include_bits  = ['p1', 'p3']
     )
     e = e1.merge(e2, e3)
     assert e.pre_include_bits == ('1', '2', '3')
     assert e.includes == ('x.h', 'y.h', 'z.h')
     assert e.post_include_bits == ('p1', 'p2', 'p3')
Ejemplo n.º 16
0
 def test_preprocess_localbase(self):
     tmpdir = udir.join('test_preprocess_localbase').ensure(dir=1)
     eci = ExternalCompilationInfo()
     os.environ['PLATFORMER_LOCALBASE'] = '/foo/baz'
     try:
         mk = self.platform.gen_makefile(['blip.c'], eci, path=tmpdir)
         mk.write()
     finally:
         del os.environ['PLATFORMER_LOCALBASE']
     Makefile = tmpdir.join('Makefile').read()
     assert 'INCLUDEDIRS = -I/foo/baz/include' in Makefile
     assert 'LIBDIRS = -L/foo/baz/lib' in Makefile
Ejemplo n.º 17
0
 def test_simple_enough(self):
     cfile = udir.join('test_simple_enough.c')
     cfile.write('''
     #include <stdio.h>
     int main()
     {
         printf("42\\n");
         return 0;
     }
     ''')
     executable = self.platform.compile([cfile], ExternalCompilationInfo())
     res = self.platform.execute(executable)
     self.check_res(res)
Ejemplo n.º 18
0
 def test_includes_outside_scratchbox(self):
     cfile = udir.join('test_includes_outside_scratchbox.c')
     cfile.write('''
     #include <stdio.h>
     #include "test.h"
     int main()
     {
         printf("%d\\n", XXX_STUFF);
         return 0;
     }
     ''')
     includedir = py.path.local(__file__).dirpath().join('include')
     eci = ExternalCompilationInfo(include_dirs=(includedir, ))
     executable = self.platform.compile([cfile], eci)
     res = self.platform.execute(executable)
     self.check_res(res)
Ejemplo n.º 19
0
    def test_platforms(self):
        from platformer import Platform

        class Maemo(Platform):
            def __init__(self, cc=None):
                self.cc = cc

        eci = ExternalCompilationInfo(platform=Maemo())
        eci2 = ExternalCompilationInfo()
        assert eci != eci2
        assert hash(eci) != hash(eci2)
        assert repr(eci) != repr(eci2)
        py.test.raises(Exception, eci2.merge, eci)
        assert eci.merge(eci).platform == Maemo()
        assert (ExternalCompilationInfo(platform=Maemo(cc='xxx')) !=
                ExternalCompilationInfo(platform=Maemo(cc='yyy')))
        assert (repr(ExternalCompilationInfo(platform=Maemo(cc='xxx'))) !=
                repr(ExternalCompilationInfo(platform=Maemo(cc='yyy'))))
Ejemplo n.º 20
0
    def test_longsize(self):
        if platform.machine() != 'i386':
            py.test.skip("i386 only")
        cfile = udir.join('test_int_size.c')
        cfile.write(r'''
        #include <stdio.h>
        #include <limits.h>

        int main() {
                printf("%ld\n", LONG_MAX);
                return 0;
        }
        ''')
        eci = ExternalCompilationInfo()
        executable = self.platform.compile([cfile], eci)
        res = self.platform.execute(executable)
        self.check_res(res, str(sys.maxint) + '\n')
Ejemplo n.º 21
0
 def test_use_eci(self):
     tmpdir = udir.join('use_eci').ensure(dir=1)
     hfile = tmpdir.join('needed.h')
     hfile.write('#define SOMEHASHDEFINE 42\n')
     eci = ExternalCompilationInfo(include_dirs=[tmpdir])
     cfile = udir.join('use_eci_c.c')
     cfile.write('''
     #include <stdio.h>
     #include "needed.h"
     int main()
     {
         printf("%d\\n", SOMEHASHDEFINE);
         return 0;
     }
     ''')
     executable = self.platform.compile([cfile], eci)
     res = self.platform.execute(executable)
     self.check_res(res)
Ejemplo n.º 22
0
 def test_convert_sources_to_c_files(self):
     eci = ExternalCompilationInfo(
         separate_module_sources=['xxx'],
         separate_module_files=['x.c'],
     )
     cache_dir = udir.join('test_convert_sources').ensure(dir=1)
     neweci = eci.convert_sources_to_files(cache_dir)
     assert not neweci.separate_module_sources
     res = neweci.separate_module_files
     assert len(res) == 2
     assert res[0] == 'x.c'
     assert str(res[1]).startswith(str(cache_dir))
     e = ExternalCompilationInfo()
     assert e.convert_sources_to_files() is e
Ejemplo n.º 23
0
 def test_simple_makefile(self):
     tmpdir = udir.join('simple_makefile' + self.__class__.__name__).ensure(dir=1)
     cfile = tmpdir.join('test_simple_enough.c')
     cfile.write('''
     #include <stdio.h>
     int main()
     {
         printf("42\\n");
         return 0;
     }
     ''')
     mk = self.platform.gen_makefile([cfile], ExternalCompilationInfo(),
                            path=tmpdir)
     mk.write()
     self.platform.execute_makefile(mk)
     res = self.platform.execute(tmpdir.join('test_simple_enough'))
     assert res.out == '42\n'
     if self.strict_on_stderr:
         assert res.err == ''
     assert res.returncode == 0
     assert '-lrt' in tmpdir.join("Makefile").read()
Ejemplo n.º 24
0
 def test_two_files(self):
     cfile = udir.join('test_two_files.c')
     cfile.write('''
     #include <stdio.h>
     int func();
     int main()
     {
         printf("%d\\n", func());
         return 0;
     }
     ''')
     cfile2 = udir.join('implement1.c')
     cfile2.write('''
     int func()
     {
         return 42;
     }
     ''')
     executable = self.platform.compile([cfile, cfile2],
                                        ExternalCompilationInfo())
     res = self.platform.execute(executable)
     self.check_res(res)
Ejemplo n.º 25
0
    def test_64_32_results(self):
        if platform.machine() != 'i386':
            py.test.skip("i386 only")
        plat32 = Darwin_i386()
        plat64 = Darwin_x86_64()
        cfile = udir.join('test_int_size.c')
        cfile.write(r'''
        #include <stdio.h>
        #include <limits.h>

        int main() {
                printf("%d\n", INT_MAX < LONG_MAX);
                return 0;
        }
        ''')
        eci = ExternalCompilationInfo()
        executable = plat32.compile([cfile], eci)
        res = plat32.execute(executable)
        self.check_res(res, '0\n')
        if host_factory == Darwin_x86_64:
            executable = plat64.compile([cfile], eci)
            res = plat64.execute(executable)
            self.check_res(res, '1\n')
Ejemplo n.º 26
0
    def test_frameworks(self):
        objcfile = udir.join('test_simple.m')
        objcfile.write(r'''
        #import <Foundation/Foundation.h>
        #include "test.h"

        int main (int argc, const char * argv[]) {
            NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
            NSArray *args = [[NSProcessInfo processInfo] arguments];
            NSCountedSet *cset = [[NSCountedSet alloc] initWithArray:args];

            printf("%d\n", XXX_STUFF);

            [cset release];
            [pool release];
            return 0;
        }
        ''')
        includedir = py.path.local(__file__).dirpath().join('include')
        eci = ExternalCompilationInfo(frameworks=('Cocoa',),
                                      include_dirs=(includedir,))
        executable = self.platform.compile([objcfile], eci)
        res = self.platform.execute(executable)
        self.check_res(res)
Ejemplo n.º 27
0
 def test_from_config_tool(self):
     sdlconfig = py.path.local.sysfind('sdl-config')
     if not sdlconfig:
         py.test.skip("sdl-config not installed")
     eci = ExternalCompilationInfo.from_config_tool('sdl-config')
     assert 'SDL' in eci.libraries
Ejemplo n.º 28
0
 def test_link_files(self):
     tmpdir = udir.join('link_files' + self.__class__.__name__).ensure(dir=1)
     eci = ExternalCompilationInfo(link_files=['/foo/bar.a'])
     mk = self.platform.gen_makefile(['blip.c'], eci, path=tmpdir)
     mk.write()
     assert 'LINKFILES = /foo/bar.a' in tmpdir.join('Makefile').read()
Ejemplo n.º 29
0
 def test_from_config_tool(self):
     sdlconfig = py.path.local.sysfind('sdl-config')
     if not sdlconfig:
         py.test.skip("sdl-config not installed")
     eci = ExternalCompilationInfo.from_config_tool('sdl-config')
     assert 'SDL' in eci.libraries