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_properties(self): with mock.patch('bfg9000.shell.which', mock_which): cc = MsvcBuilder(self.env, known_langs['c++'], ['cl'], 'version') self.assertEqual(cc.flavor, 'msvc') self.assertEqual(cc.compiler.flavor, 'msvc') self.assertEqual(cc.pch_compiler.flavor, 'msvc') self.assertEqual(cc.linker('executable').flavor, 'msvc') self.assertEqual(cc.linker('shared_library').flavor, 'msvc') self.assertEqual(cc.linker('static_library').flavor, 'msvc') self.assertEqual(cc.family, 'native') self.assertEqual(cc.auto_link, True) self.assertEqual(cc.can_dual_link, False) self.assertEqual(cc.compiler.num_outputs, 'all') self.assertEqual(cc.pch_compiler.num_outputs, 2) self.assertEqual(cc.linker('executable').num_outputs, 'all') self.assertEqual(cc.linker('shared_library').num_outputs, 2) self.assertEqual(cc.compiler.deps_flavor, 'msvc') self.assertEqual(cc.pch_compiler.deps_flavor, 'msvc') self.assertEqual(cc.compiler.needs_libs, False) self.assertEqual(cc.pch_compiler.needs_libs, False) self.assertEqual(cc.compiler.accepts_pch, True) self.assertEqual(cc.pch_compiler.accepts_pch, False) self.assertRaises(KeyError, lambda: cc.linker('unknown'))
def test_clang(self): def mock_execute(args, **kwargs): if '--version' in args: return 'clang version 10.0.0' version = 'OVERVIEW: clang LLVM compiler' with mock.patch('bfg9000.shell.which', mock_which), \ mock.patch('bfg9000.shell.execute', mock_execute): cc = MsvcBuilder(self.env, known_langs['c++'], ['cl'], True, version) self.assertEqual(cc.brand, 'clang') self.assertEqual(cc.compiler.brand, 'clang') self.assertEqual(cc.pch_compiler.brand, 'clang') self.assertEqual(cc.linker('executable').brand, 'clang') self.assertEqual(cc.linker('shared_library').brand, 'clang') self.assertEqual(cc.version, Version('10.0.0')) self.assertEqual(cc.compiler.version, Version('10.0.0')) self.assertEqual(cc.pch_compiler.version, Version('10.0.0')) self.assertEqual(cc.linker('executable').version, Version('10.0.0')) self.assertEqual(cc.linker('shared_library').version, Version('10.0.0'))
def setUp(self): self.env = make_env() version = ('Microsoft (R) C/C++ Optimizing Compiler Version ' + '19.12.25831 for x86') with mock.patch('bfg9000.shell.which', mock_which): self.linker = MsvcBuilder(self.env, known_langs['c++'], ['cl'], version).linker('executable')
def setUp(self): with mock.patch('bfg9000.shell.which', mock_which), \ mock.patch('bfg9000.shell.execute', mock_execute): self.builder = MsvcBuilder(self.env, known_langs['c++'], ['cl'], True, 'version') self.packages = self.builder.packages self.compiler = self.builder.compiler self.linker = self.builder.linker('executable') self.env.tool('pkg_config')
def test_unknown_brand(self): version = 'unknown' with mock.patch('bfg9000.shell.which', mock_which): cc = MsvcBuilder(self.env, known_langs['c++'], ['c++'], version) self.assertEqual(cc.brand, 'unknown') self.assertEqual(cc.compiler.brand, 'unknown') self.assertEqual(cc.pch_compiler.brand, 'unknown') self.assertEqual(cc.linker('executable').brand, 'unknown') self.assertEqual(cc.linker('shared_library').brand, 'unknown') self.assertEqual(cc.version, None) self.assertEqual(cc.compiler.version, None) self.assertEqual(cc.pch_compiler.version, None) self.assertEqual(cc.linker('executable').version, None) self.assertEqual(cc.linker('shared_library').version, None)
def test_msvc(self): version = ('Microsoft (R) C/C++ Optimizing Compiler Version ' + '19.12.25831 for x86') with mock.patch('bfg9000.shell.which', mock_which): cc = MsvcBuilder(self.env, known_langs['c++'], ['cl'], version) self.assertEqual(cc.brand, 'msvc') self.assertEqual(cc.compiler.brand, 'msvc') self.assertEqual(cc.pch_compiler.brand, 'msvc') self.assertEqual(cc.linker('executable').brand, 'msvc') self.assertEqual(cc.linker('shared_library').brand, 'msvc') self.assertEqual(cc.version, Version('19.12.25831')) self.assertEqual(cc.compiler.version, Version('19.12.25831')) self.assertEqual(cc.pch_compiler.version, Version('19.12.25831')) self.assertEqual( cc.linker('executable').version, Version('19.12.25831')) self.assertEqual( cc.linker('shared_library').version, Version('19.12.25831'))
def setUp(self): with mock.patch('bfg9000.shell.which', mock_which): self.compiler = MsvcBuilder(self.env, known_langs['c++'], ['cl'], True, 'version').pch_compiler
def setUp(self): with mock.patch('bfg9000.shell.which', mock_which): self.linker = MsvcBuilder(self.env, known_langs['c++'], ['cl'], 'version').linker('static_library')
def _get_linker(self, lang): version = ('Microsoft (R) C/C++ Optimizing Compiler Version ' + '19.12.25831 for x86') with mock.patch('bfg9000.shell.which', mock_which): # noqa return MsvcBuilder(self.env, known_langs[lang], ['cl'], version).linker('shared_library')
def setUp(self): with mock.patch('bfg9000.shell.which', mock_which): self.packages = MsvcBuilder(self.env, known_langs['c++'], ['cl'], 'version').packages