Esempio n. 1
0
    def test_flags_lib(self):
        lib1 = self.Path('/path/to/lib/libfoo.jar')
        lib2 = self.Path('/path/to/lib/libbar.jar')

        self.assertEqual(self.compiler.flags(opts.option_list(
            opts.lib(file_types.StaticLibrary(lib1, 'jvm'))
        )), ['-cp', lib1])
        self.assertEqual(self.compiler.flags(opts.option_list(
            opts.lib(file_types.StaticLibrary(lib1, 'jvm')),
            opts.lib(file_types.StaticLibrary(lib2, 'jvm'))
        )), ['-cp', lib1 + os.pathsep + lib2])
Esempio n. 2
0
    def test_flags_lib_dir(self):
        libdir = self.Path('/path/to/lib')
        lib = self.Path('/path/to/lib/foo.so')

        # Lib dir
        self.assertEqual(
            self.linker.flags(
                opts.option_list(opts.lib_dir(file_types.Directory(libdir)))),
            ['/LIBPATH:' + libdir])
        self.assertEqual(
            self.linker.flags(opts.option_list(
                opts.lib_dir(file_types.Directory(libdir))),
                              mode='pkg-config'), ['-L' + libdir])

        # Shared library
        self.assertEqual(
            self.linker.flags(
                opts.option_list(
                    opts.lib(file_types.SharedLibrary(lib, 'native')))), [])

        # Static library
        self.assertEqual(
            self.linker.flags(
                opts.option_list(
                    opts.lib(file_types.StaticLibrary(lib, 'native')))), [])

        # Mixed
        self.assertEqual(
            self.linker.flags(
                opts.option_list(
                    opts.lib_dir(file_types.Directory(libdir)),
                    opts.lib(file_types.SharedLibrary(lib, 'native')))),
            ['/LIBPATH:' + libdir])
Esempio n. 3
0
 def test_src_file(self):
     expected = file_types.WholeArchive(
         file_types.StaticLibrary(Path('static', Root.srcdir),
                                  self.env.target_platform.object_format,
                                  'c'))
     self.assertSameFile(link.whole_archive(self.builtin_dict, 'static'),
                         expected)
Esempio n. 4
0
 def test_convert_from_dual_invalid_args(self):
     lib = file_types.DualUseLibrary(
         file_types.SharedLibrary(Path('shared', Root.srcdir), None),
         file_types.StaticLibrary(Path('static', Root.srcdir), None)
     )
     self.assertRaises(TypeError, self.context['static_library'], lib,
                       files=['foo.cpp'])
Esempio n. 5
0
    def test_libs(self):
        self.env.library_mode = LibraryMode(True, False)

        result = self.builtin_dict['object_file'](file='main.java', libs='lib')
        self.assertEqual(
            result.creator.libs,
            [file_types.StaticLibrary(Path('lib', Root.srcdir), 'java')])
Esempio n. 6
0
 def test_convert_to_shared(self):
     self.env.library_mode = LibraryMode(True, False)
     lib = file_types.DualUseLibrary(
         file_types.SharedLibrary(Path('shared', Root.srcdir), None),
         file_types.StaticLibrary(Path('static', Root.srcdir), None))
     result = self.builtin_dict['library'](lib)
     self.assertEqual(result, lib.shared)
Esempio n. 7
0
 def test_identity(self):
     self.env.library_mode = LibraryMode(True, True)
     expected = file_types.DualUseLibrary(
         file_types.SharedLibrary(Path('shared', Root.srcdir), None),
         file_types.StaticLibrary(Path('static', Root.srcdir), None)
     )
     self.assertIs(self.context['library'](expected), expected)
Esempio n. 8
0
 def test_no_dist(self):
     expected = file_types.StaticLibrary(
         Path('static', Root.srcdir),
         self.env.target_platform.object_format, 'c')
     self.assertSameFile(
         self.context['static_library']('static', dist=False), expected)
     self.assertEqual(list(self.build.sources()), [self.bfgfile])
Esempio n. 9
0
    def test_lib_flags_lib(self):
        lib = self.Path('/path/to/lib/foo.lib')

        self.assertEqual(
            self.linker.lib_flags(
                opts.option_list(
                    opts.lib(file_types.SharedLibrary(lib, 'native')))), [lib])
        self.assertEqual(
            self.linker.lib_flags(opts.option_list(
                opts.lib(file_types.SharedLibrary(lib, 'native'))),
                                  mode='pkg-config'), ['-lfoo'])

        self.assertEqual(
            self.linker.lib_flags(
                opts.option_list(
                    opts.lib(
                        file_types.WholeArchive(
                            file_types.SharedLibrary(lib, 'native'))))),
            ['/WHOLEARCHIVE:' + lib])

        version = ('Microsoft (R) C/C++ Optimizing Compiler Version ' +
                   '18.00.25831 for x86')
        with mock.patch('bfg9000.shell.which', mock_which):
            linker = MsvcBuilder(self.env, known_langs['c++'], ['cl'],
                                 version).linker('executable')
        with self.assertRaises(TypeError):
            linker.lib_flags(
                opts.option_list(
                    opts.lib(
                        file_types.WholeArchive(
                            file_types.StaticLibrary(lib, 'native')))))

        with self.assertRaises(TypeError):
            self.linker.lib_flags(
                opts.option_list(opts.lib(Framework('cocoa'))))
Esempio n. 10
0
 def test_convert_to_static(self):
     self.env.library_mode = LibraryMode(False, True)
     lib = file_types.DualUseLibrary(
         file_types.SharedLibrary(Path('shared', Root.srcdir), None),
         file_types.StaticLibrary(Path('static', Root.srcdir), None)
     )
     self.assertEqual(self.context['library'](lib), lib.static)
Esempio n. 11
0
 def test_convert_invalid_args(self):
     self.env.library_mode = LibraryMode(False, True)
     lib = file_types.DualUseLibrary(
         file_types.SharedLibrary(Path('shared', Root.srcdir), None),
         file_types.StaticLibrary(Path('static', Root.srcdir), None)
     )
     self.assertRaises(TypeError, self.context['library'], lib,
                       files=['foo.cpp'])
Esempio n. 12
0
    def test_src_file(self):
        expected = file_types.StaticLibrary(
            Path('static', Root.srcdir),
            self.env.target_platform.object_format, 'c')
        self.assertSameFile(self.context['static_library']('static'), expected)
        self.assertEqual(list(self.build.sources()), [self.bfgfile, expected])

        self.context['project'](lang='c++')
        expected.lang = 'c++'
        self.assertSameFile(self.context['static_library']('static'), expected)
Esempio n. 13
0
    def test_src_file(self):
        self.env.library_mode = LibraryMode(True, True)
        expected = file_types.StaticLibrary(
            Path('library', Root.srcdir),
            self.env.target_platform.object_format, 'c'
        )
        self.assertSameFile(self.builtin_dict['library']('library'), expected)
        self.assertEqual(list(self.build.sources()), [self.bfgfile, expected])

        self.builtin_dict['project'](lang='c++')
        expected.lang = 'c++'
        self.assertSameFile(self.builtin_dict['library']('library'), expected)
Esempio n. 14
0
 def test_src_file(self):
     result = self.builtin_dict['static_library']('static')
     self.assertEqual(
         result, file_types.StaticLibrary(Path('static', Root.srcdir),
                                          None))
Esempio n. 15
0
    def test_flags_lib_dir(self):
        libdir = Path('/path/to/lib')
        lib = Path('/path/to/lib/libfoo.a')
        output = file_types.Executable(Path('exe'), 'native')

        if self.env.target_platform.name == 'linux':
            rpath = rpath_with_output = ['-Wl,-rpath,' + libdir]
        elif self.env.target_platform.name == 'darwin':
            rpath = []
            rpath_with_output = [jbos('-Wl,-rpath,', '@loader_path')]
        else:
            rpath = rpath_with_output = []

        # Lib dir
        self.assertEqual(
            self.linker.flags(
                opts.option_list(opts.lib_dir(file_types.Directory(libdir)))),
            ['-L' + libdir])

        # Shared library
        self.assertEqual(
            self.linker.flags(
                opts.option_list(
                    opts.lib(file_types.SharedLibrary(lib, 'native')))),
            ['-L' + libdir] + rpath)
        self.assertEqual(
            self.linker.flags(
                opts.option_list(
                    opts.lib(file_types.SharedLibrary(lib, 'native'))),
                output), ['-L' + libdir] + rpath_with_output)

        if self.env.target_platform.name == 'linux':
            libdir2 = Path('foo')
            lib2 = Path('foo/libbar.a')

            with self.assertRaises(ValueError):
                self.linker.flags(
                    opts.option_list(
                        opts.lib(file_types.SharedLibrary(lib2, 'native'))))
            self.assertEqual(
                self.linker.flags(
                    opts.option_list(
                        opts.lib(file_types.SharedLibrary(lib2, 'native'))),
                    output),
                ['-L' + libdir2,
                 jbos('-Wl,-rpath,', '$ORIGIN/foo')])

        # Static library
        self.assertEqual(
            self.linker.flags(
                opts.option_list(
                    opts.lib(file_types.StaticLibrary(lib, 'native')))), [])
        self.assertEqual(
            self.linker.flags(opts.option_list(
                opts.lib(file_types.StaticLibrary(lib, 'native'))),
                              mode='pkg-config'), ['-L' + libdir])

        # Generic library
        self.assertEqual(
            self.linker.flags(
                opts.option_list(opts.lib(file_types.Library(lib, 'native')))),
            ['-L' + libdir])

        mingw_lib = Path('/path/to/lib/foo.lib')
        self.assertEqual(
            self.linker.flags(
                opts.option_list(
                    opts.lib(file_types.Library(mingw_lib, 'native')))), [])
        with self.assertRaises(ValueError):
            self.linker.flags(opts.option_list(
                opts.lib(file_types.Library(mingw_lib, 'native'))),
                              mode='pkg-config')

        # Framework
        self.assertEqual(
            self.linker.flags(opts.option_list(opts.lib(Framework('cocoa')))),
            [])

        # Mixed
        self.assertEqual(
            self.linker.flags(
                opts.option_list(
                    opts.lib_dir(file_types.Directory(libdir)),
                    opts.lib(file_types.SharedLibrary(lib, 'native')))),
            ['-L' + libdir] + rpath)
        self.assertEqual(
            self.linker.flags(
                opts.option_list(
                    opts.lib_dir(file_types.Directory(libdir)),
                    opts.lib(file_types.SharedLibrary(lib, 'native'))),
                output), ['-L' + libdir] + rpath_with_output)
Esempio n. 16
0
 def test_convert_from_dual(self):
     lib = file_types.DualUseLibrary(
         file_types.SharedLibrary(Path('shared', Root.srcdir), None),
         file_types.StaticLibrary(Path('static', Root.srcdir), None)
     )
     self.assertIs(self.context['static_library'](lib), lib.static)
Esempio n. 17
0
 def test_src_file(self):
     self.env.library_mode = LibraryMode(True, True)
     result = self.builtin_dict['library']('library')
     self.assertEqual(
         result, file_types.StaticLibrary(Path('library', Root.srcdir),
                                          None))
Esempio n. 18
0
 def test_src_file_explicit_static(self):
     result = self.builtin_dict['library']('library', kind='static')
     self.assertEqual(
         result, file_types.StaticLibrary(Path('library', Root.srcdir),
                                          None))
Esempio n. 19
0
 def test_identity(self):
     ex = file_types.StaticLibrary(Path('static', Root.srcdir), None)
     self.assertIs(self.context['static_library'](ex), ex)
Esempio n. 20
0
 def test_src_file_explicit_static(self):
     expected = file_types.StaticLibrary(
         Path('library', Root.srcdir),
         self.env.target_platform.object_format, 'c')
     self.assertSameFile(
         self.builtin_dict['library']('library', kind='static'), expected)
Esempio n. 21
0
 def test_identity(self):
     lib = file_types.WholeArchive(
         file_types.StaticLibrary(Path('static', Root.srcdir), None))
     result = self.builtin_dict['whole_archive'](lib)
     self.assertEqual(result, lib)
Esempio n. 22
0
 def test_src_file(self):
     self.env.library_mode = LibraryMode(True, True)
     expected = file_types.StaticLibrary(
         Path('library', Root.srcdir),
         self.env.target_platform.object_format, 'c')
     self.assertSameFile(self.builtin_dict['library']('library'), expected)
Esempio n. 23
0
 def test_src_file(self):
     result = link.whole_archive(self.builtin_dict, 'static')
     self.assertEqual(
         result,
         file_types.WholeArchive(
             file_types.StaticLibrary(Path('static', Root.srcdir), None)))
Esempio n. 24
0
 def test_convert_from_static(self):
     lib = file_types.StaticLibrary(Path('static', Root.srcdir), None)
     result = self.builtin_dict['whole_archive'](lib)
     self.assertEqual(result, file_types.WholeArchive(lib))
Esempio n. 25
0
 def test_convert_from_static(self):
     lib = file_types.StaticLibrary(Path('static', Root.srcdir), None)
     result = self.context['whole_archive'](lib)
     self.assertSameFile(result, file_types.WholeArchive(lib))
Esempio n. 26
0
 def test_convert_from_dual(self):
     lib = file_types.DualUseLibrary(
         file_types.SharedLibrary(Path('shared', Root.srcdir), None),
         file_types.StaticLibrary(Path('static', Root.srcdir), None))
     result = self.builtin_dict['shared_library'](lib)
     self.assertEqual(result, lib.shared)
Esempio n. 27
0
 def test_identity(self):
     expected = file_types.WholeArchive(
         file_types.StaticLibrary(Path('static', Root.srcdir), None)
     )
     self.assertIs(self.context['whole_archive'](expected), expected)
Esempio n. 28
0
    def test_lib_flags_lib(self):
        lib = Path('/path/to/lib/libfoo.a')

        # Shared library
        self.assertEqual(
            self.linker.lib_flags(
                opts.option_list(
                    opts.lib(file_types.SharedLibrary(lib, 'native')))),
            ['-lfoo'])
        self.assertEqual(
            self.linker.lib_flags(opts.option_list(
                opts.lib(file_types.SharedLibrary(lib, 'native'))),
                                  mode='pkg-config'), ['-lfoo'])

        # Static library
        self.assertEqual(
            self.linker.lib_flags(
                opts.option_list(
                    opts.lib(file_types.StaticLibrary(lib, 'native')))), [lib])
        self.assertEqual(
            self.linker.lib_flags(opts.option_list(
                opts.lib(file_types.StaticLibrary(lib, 'native'))),
                                  mode='pkg-config'), ['-lfoo'])

        # Whole archive
        flags = self.linker.lib_flags(
            opts.option_list(
                opts.lib(
                    file_types.WholeArchive(
                        file_types.StaticLibrary(lib, 'native')))))
        if self.env.target_platform.name == 'darwin':
            self.assertEqual(flags, ['-Wl,-force_load', lib])
        else:
            self.assertEqual(
                flags, ['-Wl,--whole-archive', lib, '-Wl,--no-whole-archive'])

        # Generic library
        self.assertEqual(
            self.linker.lib_flags(
                opts.option_list(opts.lib(file_types.Library(lib, 'native')))),
            ['-lfoo'])

        mingw_lib = Path('/path/to/lib/foo.lib')
        self.assertEqual(
            self.linker.lib_flags(
                opts.option_list(
                    opts.lib(file_types.Library(mingw_lib, 'native')))),
            [mingw_lib])
        with self.assertRaises(ValueError):
            self.linker.lib_flags(opts.option_list(
                opts.lib(file_types.Library(mingw_lib, 'native'))),
                                  mode='pkg-config')

        # Framework
        fw = opts.lib(Framework('cocoa'))
        if self.env.target_platform.name == 'darwin':
            self.assertEqual(self.linker.lib_flags(opts.option_list(fw)),
                             ['-framework', 'cocoa'])
        else:
            with self.assertRaises(TypeError):
                self.linker.lib_flags(opts.option_list(fw))

        # String
        self.assertEqual(
            self.linker.lib_flags(opts.option_list(opts.lib('foo'))),
            ['-lfoo'])
Esempio n. 29
0
 def test_convert_from_static_invalid_args(self):
     lib = file_types.StaticLibrary(Path('static', Root.srcdir), None)
     self.assertRaises(TypeError, self.context['whole_archive'], lib,
                       files=['foo.cpp'])
Esempio n. 30
0
 def test_output_file(self):
     fmt = self.env.target_platform.object_format
     self.assertEqual(
         self.ar.output_file('foo', AttrDict(input_langs=['c++'])),
         file_types.StaticLibrary(Path('libfoo.a'), fmt, ['c++']))