Пример #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])
Пример #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])
Пример #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)
Пример #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'])
Пример #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')])
Пример #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)
Пример #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)
Пример #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])
Пример #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'))))
Пример #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)
Пример #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'])
Пример #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)
Пример #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)
Пример #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))
Пример #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)
Пример #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)
Пример #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))
Пример #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))
Пример #19
0
 def test_identity(self):
     ex = file_types.StaticLibrary(Path('static', Root.srcdir), None)
     self.assertIs(self.context['static_library'](ex), ex)
Пример #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)
Пример #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)
Пример #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)
Пример #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)))
Пример #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))
Пример #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))
Пример #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)
Пример #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)
Пример #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'])
Пример #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'])
Пример #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++']))