Example #1
0
    def test_make_simple_dual(self):
        linker = self.env.builder('c++').linker('static_library')
        static_extra = {'forward_opts': opts.ForwardOptions(
            compile_options=linker.forwarded_compile_options(
                AttrDict(name='liblibrary')
            )
        )}

        src = self.context['source_file']('main.cpp')
        with mock.patch('warnings.warn', lambda s: None):
            result = self.context['library']('library', [src], kind='dual')

        if self.env.builder('c++').can_dual_link:
            self.assertSameFile(result, file_types.DualUseLibrary(
                self.output_file('library', mode='shared_library'),
                self.output_file('library', mode='static_library',
                                 extra=static_extra)
            ), exclude={'post_install'})
            for i in result.all:
                self.assertSameFile(i.creator.files[0],
                                    self.object_file('liblibrary.int/main'))
        else:
            self.assertSameFile(result, self.output_file(
                'library', mode='shared_library'
            ))
            self.assertSameFile(result.creator.files[0],
                                self.object_file('liblibrary.int/main'))
Example #2
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)
Example #3
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'])
Example #4
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)
Example #5
0
    def test_make_simple_dual(self):
        linker = self.env.builder('c++').linker('static_library')
        static_extra = {
            'forward_opts': {
                'compile_options':
                linker.forwarded_compile_options(AttrDict(name='liblibrary')),
                'link_options':
                option_list(),
                'libs': [],
                'packages': [],
            }
        }

        src = self.builtin_dict['source_file']('main.cpp')
        with mock.patch('warnings.warn', lambda s: None):
            result = self.builtin_dict['library']('library', [src],
                                                  kind='dual')

        if self.env.builder('c++').can_dual_link:
            self.assertSameFile(result,
                                file_types.DualUseLibrary(
                                    self.output_file('library',
                                                     mode='shared_library'),
                                    self.output_file('library',
                                                     mode='static_library',
                                                     extra=static_extra)),
                                exclude={'post_install'})
        else:
            self.assertSameFile(
                result, self.output_file('library', mode='shared_library'))
Example #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)
Example #7
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'])
Example #8
0
    def test_make_simple_dual(self):
        class Context(object):
            langs = ['c++']

        src = file_types.SourceFile(Path('main.cpp', Root.srcdir))
        shared_linker = self.env.builder('c++').linker('shared_library')
        static_linker = self.env.builder('c++').linker('static_library')
        with mock.patch('warnings.warn', lambda s: None):
            result = self.builtin_dict['library']('library', [src],
                                                  kind='dual')

        if shared_linker.builder.can_dual_link:
            self.assertEqual(
                result,
                file_types.DualUseLibrary(
                    self.output_file(shared_linker, 'library', None),
                    self.output_file(static_linker, 'library', Context())))
        else:
            self.assertEqual(result,
                             self.output_file(shared_linker, 'library', None))
Example #9
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)
Example #10
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)