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'))))
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])
def test_equality(self): shared_a = file_types.SharedLibrary(Path('shared_a'), 'elf') shared_b = file_types.SharedLibrary(Path('shared_b'), 'elf') static_a = file_types.SharedLibrary(Path('static_a'), 'elf') static_b = file_types.SharedLibrary(Path('static_b'), 'elf') Dual = file_types.DualUseLibrary self.assertTrue(Dual(shared_a, static_a) == Dual(shared_a, static_a)) self.assertFalse(Dual(shared_a, static_a) != Dual(shared_a, static_a)) self.assertFalse(Dual(shared_a, static_a) == Dual(shared_b, static_b)) self.assertTrue(Dual(shared_a, static_a) != Dual(shared_b, static_b))
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'])
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)
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)
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)
def test_no_dist(self): expected = file_types.SharedLibrary( Path('shared', Root.srcdir), self.env.target_platform.object_format, 'c') self.assertSameFile( self.context['shared_library']('shared', dist=False), expected) self.assertEqual(list(self.build.sources()), [self.bfgfile])
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'])
def test_src_file(self): expected = file_types.SharedLibrary( Path('shared', Root.srcdir), self.env.target_platform.object_format, 'c') self.assertSameFile(self.context['shared_library']('shared'), expected) self.assertEqual(list(self.build.sources()), [self.bfgfile, expected]) self.context['project'](lang='c++') expected.lang = 'c++' self.assertSameFile(self.context['shared_library']('shared'), expected)
def test_lib_order(self): fmt = self.env.target_platform.object_format lib = opts.lib( file_types.SharedLibrary(Path('libfoo', Root.srcdir), fmt)) pkg_libdir = opts.lib_dir( file_types.Directory(Path('/usr/lib', Root.absolute))) pkg = CommonPackage('pkg', fmt, None, opts.option_list(pkg_libdir)) result = self.context['shared_library']('shared', ['main.cpp'], libs='libfoo', packages=pkg) self.assertEqual(result.creator.options, opts.option_list(lib, pkg_libdir))
def test_shared_library(self): lib = file_types.SharedLibrary(Path('libfoo.dylib'), 'native') self.assertEqual(common.darwin_install_name(lib, self.env), self.env.builddir.append('libfoo.dylib').string())
def test_src_file_explicit_shared(self): result = self.builtin_dict['library']('library', kind='shared') self.assertEqual( result, file_types.SharedLibrary(Path('library', Root.srcdir), None))
def test_identity(self): lib = file_types.SharedLibrary(Path('shared', Root.srcdir), None) result = self.builtin_dict['shared_library'](lib) self.assertEqual(result, lib)
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)
def test_identity(self): ex = file_types.SharedLibrary(Path('shared', Root.srcdir), None) self.assertIs(self.context['shared_library'](ex), ex)
def test_src_file(self): expected = file_types.SharedLibrary( Path('shared', Root.srcdir), self.env.target_platform.object_format, 'c') self.assertSameFile(self.builtin_dict['shared_library']('shared'), expected)
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'])
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)
def test_src_file(self): result = self.builtin_dict['shared_library']('shared') self.assertEqual( result, file_types.SharedLibrary(Path('shared', Root.srcdir), None))
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)