Exemplo n.º 1
0
    def test_extra_args(self):
        opts = ConanPackage.Options()
        opts(extra_args='--foo',
             config_file=self.config_file,
             _symbols=self.symbols)
        self.assertEqual(opts.extra_args, ShellArguments(['--foo']))

        opts(extra_args='--bar --baz',
             config_file=self.config_file,
             _symbols=self.symbols)
        self.assertEqual(opts.extra_args,
                         ShellArguments(['--foo', '--bar', '--baz']))

        opts(extra_args=['--goat', '--panda'],
             config_file=self.config_file,
             _symbols=self.symbols)
        self.assertEqual(
            opts.extra_args,
            ShellArguments(['--foo', '--bar', '--baz', '--goat', '--panda']))

        opts(extra_args='$variable',
             config_file=self.config_file,
             _symbols=self.symbols)
        self.assertEqual(
            opts.extra_args,
            ShellArguments(
                ['--foo', '--bar', '--baz', '--goat', '--panda', 'value']))
Exemplo n.º 2
0
    def test_deploy(self):
        builder = self.make_builder('foo',
                                    build_commands=['make'],
                                    deploy_commands=['make install'],
                                    usage='pkg_config')
        self.assertEqual(builder.name, 'foo')
        self.assertEqual(builder.build_commands, [
            ShellArguments(['make']),
        ])
        self.assertEqual(builder.deploy_commands, [
            ShellArguments(['make', 'install']),
        ])
        self.assertEqual(
            builder.usage,
            PkgConfigUsage('foo',
                           submodules=None,
                           _options=self.make_options(),
                           _path_bases=self.path_bases))

        self.check_build(builder)

        with mock_open_log() as mopen, \
             mock.patch('mopack.builders.custom.pushd'), \
             mock.patch('subprocess.run') as mcall:  # noqa
            builder.deploy(self.pkgdir, self.srcdir)
            mopen.assert_called_with(
                os.path.join(self.pkgdir, 'logs', 'deploy', 'foo.log'), 'a')
            mcall.assert_called_with(['make', 'install'],
                                     stdout=subprocess.PIPE,
                                     stderr=subprocess.STDOUT,
                                     universal_newlines=True,
                                     check=True)
Exemplo n.º 3
0
    def test_path_objects(self):
        opts = self.make_options()

        builder = self.make_builder('foo',
                                    build_commands=[
                                        'configure $srcdir/build',
                                        ['make', '-C', '$builddir'],
                                    ],
                                    usage='pkg_config')
        self.assertEqual(builder.name, 'foo')
        self.assertEqual(builder.build_commands, [
            ShellArguments(['configure', (Path('srcdir', ''), '/build')]),
            ShellArguments(['make', '-C', Path('builddir', '')]),
        ])
        self.assertEqual(builder.deploy_commands, [])
        self.assertEqual(
            builder.usage,
            PkgConfigUsage('foo',
                           submodules=None,
                           _options=opts,
                           _path_bases=self.path_bases))

        self.check_build(
            builder,
            build_commands=[
                ['configure', self.srcdir + '/build'],
                ['make', '-C',
                 os.path.join(self.pkgdir, 'build', 'foo')],
            ])
Exemplo n.º 4
0
    def test_cd(self):
        opts = self.make_options()

        builder = self.make_builder('foo',
                                    build_commands=[
                                        'configure $srcdir/build',
                                        'cd $builddir',
                                        'make',
                                    ],
                                    usage='pkg_config')
        self.assertEqual(builder.name, 'foo')
        self.assertEqual(builder.build_commands, [
            ShellArguments(['configure', (Path('srcdir', ''), '/build')]),
            ShellArguments(['cd', Path('builddir', '')]),
            ShellArguments(['make']),
        ])
        self.assertEqual(
            builder.usage,
            PkgConfigUsage('foo',
                           submodules=None,
                           _options=opts,
                           _path_bases=self.path_bases))

        with mock.patch('os.chdir') as mcd:
            builddir = os.path.join(self.pkgdir, 'build', 'foo')
            self.check_build(builder,
                             build_commands=[
                                 ['configure', self.srcdir + '/build'],
                                 ['make'],
                             ])
            mcd.assert_called_once_with(builddir)
Exemplo n.º 5
0
    def test_submodules(self):
        submodules_required = {'names': '*', 'required': True}
        submodules_optional = {'names': '*', 'required': False}

        usage = self.make_usage('foo', submodules=submodules_required)
        self.assertEqual(usage.path, Path('builddir', 'pkgconfig'))
        self.assertEqual(usage.pcfile, None)
        self.assertEqual(usage.extra_args, ShellArguments())
        self.assertEqual(
            usage.get_usage(['sub'], None, '/builddir'), {
                'type': 'pkg_config',
                'path': abspath('/builddir/pkgconfig'),
                'pcfiles': ['foo_sub'],
                'extra_args': [],
            })

        usage = self.make_usage('foo',
                                pcfile='bar',
                                submodules=submodules_required)
        self.assertEqual(usage.path, Path('builddir', 'pkgconfig'))
        self.assertEqual(usage.pcfile, 'bar')
        self.assertEqual(usage.extra_args, ShellArguments())
        self.assertEqual(
            usage.get_usage(['sub'], None, '/builddir'), {
                'type': 'pkg_config',
                'path': abspath('/builddir/pkgconfig'),
                'pcfiles': ['bar', 'foo_sub'],
                'extra_args': [],
            })

        usage = self.make_usage('foo', submodules=submodules_optional)
        self.assertEqual(usage.path, Path('builddir', 'pkgconfig'))
        self.assertEqual(usage.pcfile, 'foo')
        self.assertEqual(usage.extra_args, ShellArguments())
        self.assertEqual(
            usage.get_usage(['sub'], None, '/builddir'), {
                'type': 'pkg_config',
                'path': abspath('/builddir/pkgconfig'),
                'pcfiles': ['foo', 'foo_sub'],
                'extra_args': [],
            })

        usage = self.make_usage('foo',
                                pcfile='bar',
                                submodules=submodules_optional)
        self.assertEqual(usage.path, Path('builddir', 'pkgconfig'))
        self.assertEqual(usage.pcfile, 'bar')
        self.assertEqual(usage.extra_args, ShellArguments())
        self.assertEqual(
            usage.get_usage(['sub'], None, '/builddir'), {
                'type': 'pkg_config',
                'path': abspath('/builddir/pkgconfig'),
                'pcfiles': ['bar', 'foo_sub'],
                'extra_args': [],
            })
Exemplo n.º 6
0
    def test_usage_full(self):
        builder = self.make_builder('foo',
                                    build_commands=['make'],
                                    usage={
                                        'type': 'pkg_config',
                                        'path': 'pkgconf'
                                    })
        self.assertEqual(builder.name, 'foo')
        self.assertEqual(builder.build_commands, [
            ShellArguments(['make']),
        ])
        self.assertEqual(
            builder.usage,
            PkgConfigUsage('foo',
                           path='pkgconf',
                           submodules=None,
                           _options=self.make_options(),
                           _path_bases=self.path_bases))

        self.check_build(builder,
                         usage={
                             'type': 'pkg_config',
                             'path': self.pkgconfdir('foo', 'pkgconf'),
                             'pcfiles': ['foo'],
                             'extra_args': [],
                         })
Exemplo n.º 7
0
    def test_basic(self):
        builder = self.make_builder('foo',
                                    build_commands=['configure', 'make'],
                                    usage='pkg_config')
        self.assertEqual(builder.name, 'foo')
        self.assertEqual(builder.build_commands, [
            ShellArguments(['configure']),
            ShellArguments(['make']),
        ])
        self.assertEqual(builder.deploy_commands, [])
        self.assertEqual(
            builder.usage,
            PkgConfigUsage('foo',
                           submodules=None,
                           _options=self.make_options(),
                           _path_bases=self.path_bases))

        self.check_build(builder)
Exemplo n.º 8
0
    def test_usage_str(self):
        builder = self.make_builder('foo', usage='pkg_config')
        self.assertEqual(builder.name, 'foo')
        self.assertEqual(builder.extra_args, ShellArguments())
        self.assertEqual(builder.usage, PkgConfigUsage(
            'foo', submodules=None, _options=self.make_options(),
            _path_bases=self.path_bases
        ))

        self.check_build(builder)
Exemplo n.º 9
0
    def test_extra_args(self):
        builder = self.make_builder('foo', extra_args='--extra args')
        self.assertEqual(builder.name, 'foo')
        self.assertEqual(builder.extra_args,
                         ShellArguments(['--extra', 'args']))
        self.assertEqual(builder.usage, PkgConfigUsage(
            'foo', submodules=None, _options=self.make_options(),
            _path_bases=self.path_bases
        ))

        self.check_build(builder, extra_args=['--extra', 'args'])
Exemplo n.º 10
0
    def test_deploy_paths(self):
        deploy_paths = {'prefix': '/usr/local', 'goofy': '/foo/bar'}
        builder = self.make_builder('foo', deploy_paths=deploy_paths)
        self.assertEqual(builder.name, 'foo')
        self.assertEqual(builder.extra_args, ShellArguments())
        self.assertEqual(builder.usage, PkgConfigUsage(
            'foo', submodules=None, _options=self.make_options(),
            _path_bases=self.path_bases
        ))

        self.check_build(builder, extra_args=['--prefix', '/usr/local'])
Exemplo n.º 11
0
 def check_usage(self,
                 usage,
                 *,
                 auto_link=False,
                 include_path=[],
                 library_path=[],
                 headers=[],
                 libraries=[{
                     'type': 'guess',
                     'name': 'foo'
                 }],
                 compile_flags=[],
                 link_flags=[]):
     self.assertEqual(usage.auto_link, auto_link)
     self.assertEqual(usage.include_path, include_path)
     self.assertEqual(usage.library_path, library_path)
     self.assertEqual(usage.headers, headers)
     self.assertEqual(usage.libraries, libraries)
     self.assertEqual(usage.compile_flags, ShellArguments(compile_flags))
     self.assertEqual(usage.link_flags, ShellArguments(link_flags))
Exemplo n.º 12
0
 def test_path_builddir(self):
     usage = self.make_usage('foo', path='$builddir/pkgconf')
     self.assertEqual(usage.path, Path('builddir', 'pkgconf'))
     self.assertEqual(usage.pcfile, 'foo')
     self.assertEqual(usage.extra_args, ShellArguments())
     self.assertEqual(
         usage.get_usage(None, '/srcdir', '/builddir'), {
             'type': 'pkg_config',
             'path': abspath('/builddir/pkgconf'),
             'pcfiles': ['foo'],
             'extra_args': [],
         })
Exemplo n.º 13
0
    def test_toolchain(self):
        builder = self.make_builder('foo', this_options={
            'toolchain': 'toolchain.bfg'
        })
        self.assertEqual(builder.name, 'foo')
        self.assertEqual(builder.extra_args, ShellArguments())
        self.assertEqual(builder.usage, PkgConfigUsage(
            'foo', submodules=None, _options=self.make_options(),
            _path_bases=self.path_bases
        ))

        self.check_build(builder, extra_args=[
            '--toolchain', os.path.join(self.config_dir, 'toolchain.bfg')
        ])
Exemplo n.º 14
0
    def test_extra_args(self):
        usage = self.make_usage('foo', path='pkgconf', extra_args='--static')
        self.assertEqual(usage.path, Path('builddir', 'pkgconf'))
        self.assertEqual(usage.pcfile, 'foo')
        self.assertEqual(usage.extra_args, ShellArguments(['--static']))
        self.assertEqual(
            usage.get_usage(None, None, '/builddir'), {
                'type': 'pkg_config',
                'path': abspath('/builddir/pkgconf'),
                'pcfiles': ['foo'],
                'extra_args': ['--static'],
            })

        usage = self.make_usage('foo', path='pkgconf', extra_args=['--static'])
        self.assertEqual(usage.path, Path('builddir', 'pkgconf'))
        self.assertEqual(usage.pcfile, 'foo')
        self.assertEqual(usage.extra_args, ShellArguments(['--static']))
        self.assertEqual(
            usage.get_usage(None, None, '/builddir'), {
                'type': 'pkg_config',
                'path': abspath('/builddir/pkgconf'),
                'pcfiles': ['foo'],
                'extra_args': ['--static'],
            })
Exemplo n.º 15
0
    def test_toolchain(self):
        builder = self.make_builder(
            'foo',
            usage={'type': 'pkg_config'},
            this_options={'toolchain': 'toolchain.cmake'})
        self.assertEqual(builder.name, 'foo')
        self.assertEqual(builder.extra_args, ShellArguments())
        self.assertEqual(
            builder.usage,
            PkgConfigUsage('foo',
                           submodules=None,
                           _options=self.make_options(),
                           _path_bases=self.path_bases))

        self.check_build(builder,
                         extra_args=[
                             '-DCMAKE_TOOLCHAIN_FILE=' +
                             os.path.join(self.config_dir, 'toolchain.cmake')
                         ])
Exemplo n.º 16
0
    def test_deploy_paths(self):
        deploy_paths = {'prefix': '/usr/local', 'goofy': '/foo/bar'}
        builder = self.make_builder('foo',
                                    usage='pkg_config',
                                    deploy_paths=deploy_paths)
        self.assertEqual(builder.name, 'foo')
        self.assertEqual(builder.extra_args, ShellArguments())
        self.assertEqual(
            builder.usage,
            PkgConfigUsage('foo',
                           submodules=None,
                           _options=self.make_options(),
                           _path_bases=self.path_bases))

        self.check_build(builder,
                         extra_args=[
                             '-DCMAKE_INSTALL_PREFIX:PATH=' +
                             os.path.abspath('/usr/local')
                         ])
Exemplo n.º 17
0
    def test_basic(self):
        builder = self.make_builder('foo')
        self.assertEqual(builder.name, 'foo')
        self.assertEqual(builder.extra_args, ShellArguments())
        self.assertEqual(builder.usage, PkgConfigUsage(
            'foo', submodules=None, _options=self.make_options(),
            _path_bases=self.path_bases
        ))

        self.check_build(builder)

        with mock_open_log() as mopen, \
             mock.patch('mopack.builders.bfg9000.pushd'), \
             mock.patch('subprocess.run') as mcall:  # noqa
            builder.deploy(self.pkgdir, self.srcdir)
            mopen.assert_called_with(os.path.join(
                self.pkgdir, 'logs', 'deploy', 'foo.log'
            ), 'a')
            mcall.assert_called_with(
                ['ninja', 'install'], stdout=subprocess.PIPE,
                stderr=subprocess.STDOUT, universal_newlines=True,
                check=True
            )
Exemplo n.º 18
0
 def assertShellArgs(self, value, expected, **kwargs):
     self.assertEqual(
         shell_args(**kwargs)('field', value), ShellArguments(expected))
Exemplo n.º 19
0
 def test_default(self):
     opts = ConanPackage.Options()
     self.assertEqual(opts.build, [])
     self.assertEqual(opts.extra_args, ShellArguments())
Exemplo n.º 20
0
    def test_submodule_map(self):
        submodules_required = {'names': '*', 'required': True}

        usage = self.make_usage('foo',
                                submodule_map='$submodule',
                                submodules=submodules_required)
        self.assertEqual(usage.path, Path('builddir', 'pkgconfig'))
        self.assertEqual(usage.pcfile, None)
        self.assertEqual(usage.extra_args, ShellArguments())
        self.assertEqual(
            usage.get_usage(['sub'], None, '/builddir'), {
                'type': 'pkg_config',
                'path': abspath('/builddir/pkgconfig'),
                'pcfiles': ['sub'],
                'extra_args': [],
            })

        usage = self.make_usage('foo',
                                submodule_map={'*': {
                                    'pcfile': '$submodule'
                                }},
                                submodules=submodules_required)
        self.assertEqual(usage.path, Path('builddir', 'pkgconfig'))
        self.assertEqual(usage.pcfile, None)
        self.assertEqual(usage.extra_args, ShellArguments())
        self.assertEqual(
            usage.get_usage(['sub'], None, '/builddir'), {
                'type': 'pkg_config',
                'path': abspath('/builddir/pkgconfig'),
                'pcfiles': ['sub'],
                'extra_args': [],
            })

        usage = self.make_usage('foo',
                                submodule_map={
                                    'sub': {
                                        'pcfile': 'foopc'
                                    },
                                    'sub2': {
                                        'pcfile': '${{ submodule }}pc'
                                    },
                                    '*': {
                                        'pcfile': 'star${{ submodule }}pc'
                                    },
                                },
                                submodules=submodules_required)
        self.assertEqual(usage.path, Path('builddir', 'pkgconfig'))
        self.assertEqual(usage.pcfile, None)
        self.assertEqual(usage.extra_args, ShellArguments())
        self.assertEqual(
            usage.get_usage(['sub'], None, '/builddir'), {
                'type': 'pkg_config',
                'path': abspath('/builddir/pkgconfig'),
                'pcfiles': ['foopc'],
                'extra_args': [],
            })
        self.assertEqual(
            usage.get_usage(['sub2'], None, '/builddir'), {
                'type': 'pkg_config',
                'path': abspath('/builddir/pkgconfig'),
                'pcfiles': ['sub2pc'],
                'extra_args': [],
            })
        self.assertEqual(
            usage.get_usage(['subfoo'], None, '/builddir'), {
                'type': 'pkg_config',
                'path': abspath('/builddir/pkgconfig'),
                'pcfiles': ['starsubfoopc'],
                'extra_args': [],
            })

        submodules = {'names': '*', 'required': False}
        usage = self.make_usage('foo',
                                submodule_map={
                                    'sub': {
                                        'pcfile': 'subpc'
                                    },
                                    'sub2': {
                                        'pcfile': None
                                    },
                                },
                                submodules=submodules)
        self.assertEqual(usage.path, Path('builddir', 'pkgconfig'))
        self.assertEqual(usage.pcfile, 'foo')
        self.assertEqual(usage.extra_args, ShellArguments())
        self.assertEqual(
            usage.get_usage(['sub'], None, '/builddir'), {
                'type': 'pkg_config',
                'path': abspath('/builddir/pkgconfig'),
                'pcfiles': ['foo', 'subpc'],
                'extra_args': [],
            })
        self.assertEqual(
            usage.get_usage(['sub2'], None, '/builddir'), {
                'type': 'pkg_config',
                'path': abspath('/builddir/pkgconfig'),
                'pcfiles': ['foo'],
                'extra_args': [],
            })