Ejemplo n.º 1
0
    def test_requires(self):
        pkg = PkgConfigInfo(self.context,
                            name='package',
                            version='1.0',
                            requires=[
                                'req', ('vreq', '>=1.0'),
                                ('vreq2', SpecifierSet('>=1.1'))
                            ],
                            requires_private=['preq'],
                            conflicts=['creq'])
        data = pkg.finalize()

        out = StringIO()
        PkgConfigWriter(self.context)._write(out, data, installed=True)
        self.assertIn('\nRequires: req, vreq >= 1.0, vreq2 >= 1.1\n',
                      out.getvalue())
        self.assertIn('\nRequires.private: preq\n', out.getvalue())
        self.assertIn('\nConflicts: creq\n', out.getvalue())

        with self.assertRaises(TypeError):
            pkg = PkgConfigInfo(self.context, requires=[1])
        with self.assertRaises(TypeError):
            pkg = PkgConfigInfo(self.context,
                                requires=[
                                    Package('foo', format='elf'),
                                ])
Ejemplo n.º 2
0
    def test_compile_options(self):
        compiler = AttrDict(flavor='gcc')
        with mock.patch('bfg9000.shell.execute', mock_execute):
            pkg = PkgConfigPackage('foo', 'elf', SpecifierSet(''),
                                   PackageKind.shared, self.tool)

            self.assertEqual(pkg.compile_options(compiler),
                             opts.option_list(['-I/usr/include']))
Ejemplo n.º 3
0
 def test_lang(self):
     with mock.patch('bfg9000.shell.execute', mock_execute), \
          mock.patch('bfg9000.shell.which', mock_which):  # noqa
         pkg = self.builtin_dict['package']('name', lang='c++')
         self.assertEqual(pkg.name, 'name')
         self.assertEqual(pkg.version, Version('1.2.3'))
         self.assertEqual(pkg.specifier, SpecifierSet())
         self.assertEqual(pkg.static, False)
Ejemplo n.º 4
0
 def test_kind(self):
     with mock.patch('bfg9000.shell.execute', mock_execute), \
          mock.patch('bfg9000.shell.which', mock_which):  # noqa
         pkg = packages.package(self.env, 'name', kind='static')
         self.assertEqual(pkg.name, 'name')
         self.assertEqual(pkg.version, Version('1.2.3'))
         self.assertEqual(pkg.specifier, SpecifierSet())
         self.assertEqual(pkg.static, True)
Ejemplo n.º 5
0
    def test_link_options_coff(self):
        linker = AttrDict(flavor='gcc', builder=AttrDict(object_format='coff'))
        with mock.patch('bfg9000.shell.execute', mock_execute):
            pkg = PkgConfigPackage('foo', 'elf', SpecifierSet(''),
                                   PackageKind.shared, self.tool)

            self.assertEqual(
                pkg.link_options(linker),
                opts.option_list('-L/usr/lib', opts.lib_literal('-lfoo')))
Ejemplo n.º 6
0
 def test_version(self):
     with mock.patch('bfg9000.shell.execute', mock_execute), \
          mock.patch('bfg9000.shell.which', mock_which), \
          mock.patch('logging.log'):  # noqa
         pkg = self.context['package']('name', version='>1.0')
         self.assertEqual(pkg.name, 'name')
         self.assertEqual(pkg.version, Version('1.2.3'))
         self.assertEqual(pkg.specifier, SpecifierSet('>1.0'))
         self.assertEqual(pkg.static, False)
Ejemplo n.º 7
0
 def test_create(self):
     specifier = SpecifierSet('')
     with mock.patch('bfg9000.shell.execute', mock_execute):
         pkg = PkgConfigPackage('foo', 'elf', specifier, PackageKind.shared,
                                self.tool)
         self.assertEqual(pkg.name, 'foo')
         self.assertEqual(pkg.format, 'elf')
         self.assertEqual(pkg.version, Version('1.0'))
         self.assertEqual(pkg.specifier, specifier)
         self.assertEqual(pkg.static, False)
Ejemplo n.º 8
0
 def test_submodules_and_version(self):
     with mock.patch('bfg9000.shell.execute', self.mock_execute), \
          mock.patch('bfg9000.shell.which', mock_which), \
          mock.patch('logging.log'):
         pkg = self.context['package']('name', 'submodule', '>1.0')
         self.assertEqual(pkg.name, 'name[submodule]')
         self.assertEqual(pkg.version, Version('1.2.3'))
         self.assertEqual(pkg.specifier, SpecifierSet('>1.0'))
         self.assertEqual(pkg.static, False)
         self.assertEqual(pkg.system, True)
Ejemplo n.º 9
0
 def test_kind(self):
     with mock.patch('bfg9000.shell.execute', self.mock_execute), \
          mock.patch('bfg9000.shell.which', mock_which), \
          mock.patch('logging.log'):
         pkg = self.context['package']('name', kind='static')
         self.assertEqual(pkg.name, 'name')
         self.assertEqual(pkg.version, Version('1.2.3'))
         self.assertEqual(pkg.specifier, SpecifierSet())
         self.assertEqual(pkg.static, True)
         self.assertEqual(pkg.system, True)
Ejemplo n.º 10
0
class TestWholeArchive(IntegrationTest):
    def __init__(self, *args, **kwargs):
        super().__init__('whole_archive', *args, **kwargs)

    @skip_if(cxx.flavor == 'msvc' and cxx.version
             and cxx.version in SpecifierSet('<19'),
             'requires cc builder or msvc 2015 update 2',
             hide=True)
    def test_build(self):
        self.build()
        self.assertOutput([executable('program')], 'hello, library!\n')
Ejemplo n.º 11
0
 def test_resolve_path_auto_link(self):
     usage = {'type': 'path', 'generated': True, 'auto_link': True,
              'pcnames': ['foo'], 'pkg_config_path': '/path/to/pkgconfig'}
     with mock.patch('bfg9000.shell.execute', mock_execute_pkgconf), \
          mock.patch('bfg9000.tools.msvc.exists', return_value=True), \
          mock.patch('bfg9000.tools.mopack.get_usage',
                     return_value=usage), \
          mock.patch('bfg9000.log.info'):
         pkg = self.packages.resolve('foo', None, SpecifierSet(),
                                     PackageKind.any)
         self.check_package(pkg)
Ejemplo n.º 12
0
    def test_link_options_elf_uninst(self):
        linker = AttrDict(flavor='gcc', builder=AttrDict(object_format='elf'))
        with mock.patch('bfg9000.shell.execute', mock_execute_uninst):
            pkg = PkgConfigPackage('foo', 'elf', SpecifierSet(''),
                                   PackageKind.shared, self.tool)

            self.assertEqual(
                pkg.link_options(linker),
                opts.option_list(
                    '-L/path/to/build/foo', opts.lib_literal('-lfoo'),
                    opts.rpath_dir(Path('/path/to/build/foo'), 'uninstalled'),
                    opts.rpath_dir(Path('/usr/lib'), 'installed')))
Ejemplo n.º 13
0
    def test_symlink(self):
        self.configure(extra_args=['--mode=symlink'])
        self.build(executable('simple'))

        path, exe = self.split_path(executable('simple'))
        os.chdir(path)

        self.assertOutput([exe], 'Hello from a file!\n')
        supports_symlink = (env.backend != 'msbuild' or
                            (env.backend_version
                             and env.backend_version in SpecifierSet('>=15')))
        if (env.host_platform.family == 'windows' and sys.version[0] == 2
                and supports_symlink):
            self.assertTrue(os.path.islink(pjoin('dir', 'data.txt')))
Ejemplo n.º 14
0
    def test_link_options_macho_requires(self):
        linker = AttrDict(flavor='gcc',
                          builder=AttrDict(object_format='mach-o'))
        with mock.patch('bfg9000.shell.execute', mock_execute_requires):
            pkg = PkgConfigPackage('foo', 'elf', SpecifierSet(''),
                                   PackageKind.shared, self.tool)

            self.assertEqual(
                pkg.link_options(linker),
                opts.option_list(
                    '-L/path/to/build/foo',
                    opts.lib_literal('-lfoo'),
                    opts.install_name_change('/path/to/build/foo/libfoo.dylib',
                                             '/usr/lib/libfoo.dylib'),
                    opts.install_name_change('/path/to/build/bar/libbar.dylib',
                                             '/usr/lib/libbar.dylib'),
                    opts.install_name_change('/path/to/build/baz/libbaz.dylib',
                                             '/usr/lib/libbaz.dylib'),
                ))
Ejemplo n.º 15
0
    def test_requires_pkg_config_package(self):
        pkg_config = self.get_pkg_config()
        with mock.patch('bfg9000.shell.execute', mock_execute):
            req = PkgConfigPackage(pkg_config, 'req', format='elf')
            vreq = PkgConfigPackage(pkg_config,
                                    'vreq',
                                    format='elf',
                                    specifier=SpecifierSet('>=1.0'))
            preq = PkgConfigPackage(pkg_config, 'preq', format='elf')
            creq = PkgConfigPackage(pkg_config, 'creq', format='elf')

        pkg = PkgConfigInfo(self.context,
                            name='package',
                            version='1.0',
                            requires=[req, vreq],
                            requires_private=[preq],
                            conflicts=[creq])
        data = pkg.finalize()

        out = StringIO()
        PkgConfigWriter(self.context)._write(out, data, installed=True)
        self.assertIn('\nRequires: req, vreq >= 1.0\n', out.getvalue())
        self.assertIn('\nRequires.private: preq\n', out.getvalue())
        self.assertIn('\nConflicts: creq\n', out.getvalue())
Ejemplo n.º 16
0
 def test_boost_version_cant_parse(self):
     data = 'foobar\n'
     with mock.patch(mock_open_name, mock_open(read_data=data)):
         hdr = HeaderDirectory(abspath('path'))
         with self.assertRaises(PackageVersionError):
             packages._boost_version(hdr, SpecifierSet(''))
Ejemplo n.º 17
0
 def test_boost_version_too_old(self):
     data = '#define BOOST_LIB_VERSION "1_23_4"\n'
     with mock.patch(mock_open_name, mock_open(read_data=data)):
         hdr = HeaderDirectory(abspath('path'))
         with self.assertRaises(PackageVersionError):
             packages._boost_version(hdr, SpecifierSet('>=1.30'))
Ejemplo n.º 18
0
 def test_boost_version(self):
     data = '#define BOOST_LIB_VERSION "1_23_4"\n'
     with mock.patch(mock_open_name, mock_open(read_data=data)):
         hdr = HeaderDirectory(abspath('path'))
         self.assertEqual(packages._boost_version(hdr, SpecifierSet('')),
                          Version('1.23.4'))