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(SharedLibrary(lib, 'native')))), [lib]) self.assertEqual( self.linker.lib_flags(opts.option_list( opts.lib(SharedLibrary(lib, 'native'))), mode='pkg-config'), ['-lfoo']) self.assertEqual( self.linker.lib_flags( opts.option_list( opts.lib(WholeArchive(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(WholeArchive(StaticLibrary(lib, 'native'))))) with self.assertRaises(TypeError): self.linker.lib_flags( opts.option_list(opts.lib(Framework('cocoa'))))
def test_framework_suffix(self): env = make_env('macos') self.assertEqual( packages.framework(env, 'name', 'suffix'), CommonPackage('name,suffix', env.target_platform.object_format, link_options=opts.option_list( opts.lib(Framework('name', 'suffix')))))
def test_framework_suffix(self): env = make_env('macos') context = self._make_context(env) self.assertEqual( context['framework']('name', 'suffix'), CommonPackage('name,suffix', env.target_platform.object_format, link_options=opts.option_list( opts.lib(Framework('name', 'suffix')))))
def test_mixed(self): self.assertEqual( to_frameworks(['lib', { 'type': 'framework', 'name': 'fw' }]), ['lib', Framework('fw')])
def test_framework(self): self.assertEqual(to_frameworks([{ 'type': 'framework', 'name': 'fw' }]), [Framework('fw')])
def test_lib_flags_lib(self): lib = self.Path('/path/to/lib/libfoo.a') # Shared library self.assertEqual( self.linker.lib_flags( opts.option_list(opts.lib(SharedLibrary(lib, 'native')))), ['-lfoo']) self.assertEqual( self.linker.lib_flags(opts.option_list( opts.lib(SharedLibrary(lib, 'native'))), mode='pkg-config'), ['-lfoo']) # Shared library with creator x = SharedLibrary(lib, 'native') x.creator = 'test' self.assertEqual(self.linker.lib_flags(opts.option_list(opts.lib(x))), [lib]) self.assertEqual( self.linker.lib_flags(opts.option_list(opts.lib(x)), mode='pkg-config'), ['-lfoo']) # Static library self.assertEqual( self.linker.lib_flags( opts.option_list(opts.lib(StaticLibrary(lib, 'native')))), [lib]) self.assertEqual( self.linker.lib_flags(opts.option_list( opts.lib(StaticLibrary(lib, 'native'))), mode='pkg-config'), ['-lfoo']) # Whole archive flags = self.linker.lib_flags( opts.option_list( opts.lib(WholeArchive(StaticLibrary(lib, 'native'))))) if self.env.target_platform.genus == '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(Library(lib, 'native')))), ['-lfoo']) mingw_lib = self.Path('/path/to/lib/foo.lib') self.assertEqual( self.linker.lib_flags( opts.option_list(opts.lib(Library(mingw_lib, 'native')))), [mingw_lib]) with self.assertRaises(ValueError): self.linker.lib_flags(opts.option_list( opts.lib(Library(mingw_lib, 'native'))), mode='pkg-config') # Framework fw = opts.lib(Framework('cocoa')) if self.env.target_platform.genus == '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 = self.Path('/path/to/lib') lib = self.Path('/path/to/lib/libfoo.a') srclibdir = self.Path('.', Root.srcdir) srclib = self.Path('libfoo.a', Root.srcdir) if self.shared: output = SharedLibrary(self.Path('out'), 'native') if self.env.target_platform.genus == 'darwin': soname = [ '-install_name', self.Path('out').string(self.env.base_dirs) ] else: soname = ['-Wl,-soname,out'] else: output = Executable(self.Path('exe'), 'native') soname = [] if self.env.target_platform.genus == 'linux': rpath = ['-Wl,-rpath,' + libdir] srcdir_rpath = ['-Wl,-rpath,' + srclibdir] else: rpath = srcdir_rpath = [] # Lib dir self.assertEqual( self.linker.flags(opts.option_list(opts.lib_dir( Directory(libdir)))), ['-L' + libdir]) # Shared library self.assertEqual( self.linker.flags( opts.option_list(opts.lib(SharedLibrary(lib, 'native')))), ['-L' + libdir] + rpath) self.assertEqual( self.linker.flags( opts.option_list(opts.lib(SharedLibrary(lib, 'native'))), output), ['-L' + libdir] + rpath + soname) self.assertEqual( self.linker.flags( opts.option_list(opts.lib(SharedLibrary(srclib, 'native'))), output), ['-L' + srclibdir] + srcdir_rpath + soname) if self.env.target_platform.genus == 'linux': libdir2 = self.Path('foo') lib2 = self.Path('foo/libbar.a') with self.assertRaises(ValueError): self.linker.flags( opts.option_list(opts.lib(SharedLibrary(lib2, 'native')))) self.assertEqual( self.linker.flags( opts.option_list(opts.lib(SharedLibrary(lib2, 'native'))), output), ['-L' + libdir2, '-Wl,-rpath,$ORIGIN/foo'] + soname) # Static library self.assertEqual( self.linker.flags( opts.option_list(opts.lib(StaticLibrary(lib, 'native')))), []) self.assertEqual( self.linker.flags(opts.option_list( opts.lib(StaticLibrary(lib, 'native'))), mode='pkg-config'), ['-L' + libdir]) # Generic library self.assertEqual( self.linker.flags( opts.option_list(opts.lib(Library(lib, 'native')))), ['-L' + libdir]) mingw_lib = self.Path('/path/to/lib/foo.lib') self.assertEqual( self.linker.flags( opts.option_list(opts.lib(Library(mingw_lib, 'native')))), []) with self.assertRaises(ValueError): self.linker.flags(opts.option_list( opts.lib(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(Directory(libdir)), opts.lib(SharedLibrary(lib, 'native')))), ['-L' + libdir] + rpath) self.assertEqual( self.linker.flags( opts.option_list(opts.lib_dir(Directory(libdir)), opts.lib(SharedLibrary(lib, 'native'))), output), ['-L' + libdir] + rpath + soname)
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)