Beispiel #1
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)
Beispiel #2
0
 def test_inner(self):
     fn = abs_or_inner_path('cfgdir')
     self.assertEqual(fn('field', 'path'), Path('cfgdir', 'path'))
     self.assertEqual(fn('field', 'path/..'), Path('cfgdir', '.'))
     self.assertEqual(fn('field', 'foo/../bar'), Path('cfgdir', 'bar'))
     self.assertEqual(fn('field', Path('cfgdir', 'path')),
                      Path('cfgdir', 'path'))
Beispiel #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')],
            ])
Beispiel #4
0
    def test_boost(self):
        submodules = {'names': '*', 'required': False}
        final_usage = {
            'type': 'pkg_config',
            'path': abspath('/builddir/pkgconfig'),
            'pcfiles': ['boost'],
            'extra_args': [],
        }

        usage = self.make_usage('boost', submodules=submodules)
        self.assertEqual(usage.path, Path('builddir', 'pkgconfig'))
        self.assertEqual(usage.pcfile, 'boost')
        self.assertEqual(usage.get_usage(None, None, '/builddir'), final_usage)
        self.assertEqual(usage.get_usage(['thread'], None, '/builddir'),
                         final_usage)

        usage = self.make_usage('boost',
                                submodule_map='boost_$submodule',
                                submodules=submodules)
        self.assertEqual(usage.path, Path('builddir', 'pkgconfig'))
        self.assertEqual(usage.pcfile, 'boost')
        self.assertEqual(usage.get_usage(None, None, '/builddir'), final_usage)
        self.assertEqual(
            usage.get_usage(['thread'], None, '/builddir'), {
                'type': 'pkg_config',
                'path': abspath('/builddir/pkgconfig'),
                'pcfiles': ['boost', 'boost_thread'],
                'extra_args': [],
            })
Beispiel #5
0
    def test_usage(self):
        pkg = self.make_package('foo',
                                path=self.srcpath,
                                build='bfg9000',
                                usage='pkg_config')
        self.assertEqual(pkg.path, Path('absolute', self.srcpath))
        self.assertEqual(
            pkg.builder,
            self.make_builder(Bfg9000Builder, 'foo', usage='pkg_config'))

        pkg.fetch(self.pkgdir, self.config)
        self.check_resolve(pkg)

        usage = {'type': 'pkg_config', 'path': 'pkgconf'}
        pkg = self.make_package('foo',
                                path=self.srcpath,
                                build='bfg9000',
                                usage=usage)
        self.assertEqual(pkg.path, Path('absolute', self.srcpath))
        self.assertEqual(pkg.builder,
                         self.make_builder(Bfg9000Builder, 'foo', usage=usage))

        pkg.fetch(self.pkgdir, self.config)
        self.check_resolve(pkg,
                           usage={
                               'type': 'pkg_config',
                               'path': self.pkgconfdir('foo', 'pkgconf'),
                               'pcfiles': ['foo'],
                               'extra_args': [],
                           })
Beispiel #6
0
 def test_relative(self):
     fn = any_path('cfgdir')
     self.assertEqual(fn('field', 'path'), Path('cfgdir', 'path'))
     self.assertEqual(fn('field', '../path'),
                      Path('cfgdir', os.path.join('..', 'path')))
     self.assertEqual(fn('field', 'foo/../bar'), Path('cfgdir', 'bar'))
     self.assertEqual(fn('field', Path('cfgdir', 'path')),
                      Path('cfgdir', 'path'))
Beispiel #7
0
 def test_absolute(self):
     for i in ('cfgdir', None):
         fn = any_path('cfgdir')
         self.assertEqual(fn('field', '/path'),
                          Path('absolute', os.sep + 'path'))
         self.assertEqual(fn('field', '/path'),
                          Path('absolute', os.sep + 'path'))
         self.assertEqual(fn('field', Path('absolute', '/path')),
                          Path('absolute', '/path'))
Beispiel #8
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': [],
            })
Beispiel #9
0
 def test_absolute_nt(self):
     fn = abs_or_inner_path('cfgdir')
     with mock.patch('os.path', ntpath):
         for i in ('cfgdir', None):
             fn = abs_or_inner_path('cfgdir')
             self.assertEqual(fn('field', '/path'),
                              Path('absolute', '\\path'))
             self.assertEqual(fn('field', 'C:\\path'),
                              Path('absolute', 'C:\\path'))
             with self.assertFieldError(('field', )):
                 fn('field', 'C:')
             with self.assertFieldError(('field', )):
                 fn('field', 'C:path')
Beispiel #10
0
    def test_patch(self):
        patch = os.path.join(test_data_dir, 'hello-bfg.patch')
        pkg = self.make_package('foo',
                                path=self.srcpath,
                                patch=patch,
                                build='bfg9000')
        self.assertEqual(pkg.patch, Path('absolute', patch))

        srcdir = os.path.join(self.pkgdir, 'src', 'foo')
        with mock.patch('mopack.sources.sdist.urlopen', self.mock_urlopen), \
             mock.patch('mopack.sources.sdist.pushd'), \
             mock.patch('tarfile.TarFile.extractall') as mtar, \
             mock.patch('os.path.isdir', return_value=True), \
             mock.patch('os.path.exists', return_value=False), \
             mock.patch('builtins.open', mock_open_after_first()) as mopen, \
             mock.patch('os.makedirs'), \
             mock.patch('subprocess.run') as mrun:  # noqa
            pkg.fetch(self.pkgdir, self.config)
            mtar.assert_called_once_with(srcdir, None)
            mrun.assert_called_once_with(['patch', '-p1'],
                                         stdout=subprocess.PIPE,
                                         stderr=subprocess.STDOUT,
                                         stdin=mopen(),
                                         universal_newlines=True,
                                         check=True)
        self.check_resolve(pkg)
Beispiel #11
0
 def test_make_string(self):
     usage = make_usage('pkg',
                        'pkg_config',
                        submodules=None,
                        _options=self.make_options(),
                        _path_bases=self.path_bases)
     self.assertIsInstance(usage, PkgConfigUsage)
     self.assertEqual(usage.path, Path('builddir', 'pkgconfig'))
Beispiel #12
0
    def test_placeholder_list(self):
        srcdir = Path('srcdir', '')
        srcdir_ph = placeholder(srcdir)

        self.assertShellArgs([srcdir_ph], [srcdir])
        self.assertShellArgs(['foo', srcdir_ph, 'bar'], ['foo', srcdir, 'bar'])
        self.assertShellArgs([srcdir_ph + '/foo'], [(srcdir, '/foo')])
        self.assertShellArgs([srcdir_ph + '/ foo'], [(srcdir, '/ foo')])
Beispiel #13
0
    def test_resolve(self):
        pkg = self.make_package('foo', path=self.srcpath, build='bfg9000')
        self.assertEqual(pkg.path, Path('absolute', self.srcpath))
        self.assertEqual(pkg.builder, self.make_builder(Bfg9000Builder, 'foo'))
        self.assertEqual(pkg.needs_dependencies, True)
        self.assertEqual(pkg.should_deploy, True)

        pkg.fetch(self.pkgdir, self.config)
        self.check_resolve(pkg)
Beispiel #14
0
    def test_placeholder_string(self):
        srcdir = Path('srcdir', '')
        srcdir_ph = placeholder(srcdir)

        self.assertShellArgs(srcdir_ph, [srcdir])
        self.assertShellArgs(srcdir_ph + ' foo', [srcdir, 'foo'])
        self.assertShellArgs('foo ' + srcdir_ph + ' bar',
                             ['foo', srcdir, 'bar'])
        self.assertShellArgs(srcdir_ph + '/foo', [(srcdir, '/foo')])
        self.assertShellArgs('"' + srcdir_ph + '/ foo"', [(srcdir, '/ foo')])
Beispiel #15
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': [],
         })
Beispiel #16
0
    def test_build(self):
        build = {'type': 'bfg9000', 'extra_args': '--extra'}
        pkg = self.make_package('foo',
                                path=self.srcpath,
                                build=build,
                                usage='pkg_config')
        self.assertEqual(pkg.path, Path('absolute', self.srcpath))
        self.assertEqual(
            pkg.builder,
            self.make_builder(Bfg9000Builder, 'foo', extra_args='--extra'))

        self.check_fetch(pkg)
        self.check_resolve(pkg)
Beispiel #17
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'],
            })
Beispiel #18
0
    def test_zip_path(self):
        srcpath = os.path.join(test_data_dir, 'hello-bfg.zip')
        pkg = self.make_package('foo', build='bfg9000', path=srcpath)
        self.assertEqual(pkg.url, None)
        self.assertEqual(pkg.path, Path('absolute', srcpath))
        self.assertEqual(pkg.builder, self.make_builder(Bfg9000Builder, 'foo'))
        self.assertEqual(pkg.needs_dependencies, True)
        self.assertEqual(pkg.should_deploy, True)

        srcdir = os.path.join(self.pkgdir, 'src', 'foo')
        with mock.patch('mopack.sources.sdist.urlopen', self.mock_urlopen), \
             mock.patch('zipfile.ZipFile.extractall') as mtar, \
             mock.patch('os.path.isdir', return_value=True), \
             mock.patch('os.path.exists', return_value=False):  # noqa
            pkg.fetch(self.pkgdir, self.config)
            mtar.assert_called_once_with(srcdir, None)
        self.check_resolve(pkg)
Beispiel #19
0
    def test_make_no_deploy(self):
        pkg = make_package('foo', {
            'source': 'directory', 'path': '/path', 'build': 'bfg9000',
            'deploy': False, 'config_file': '/path/to/mopack.yml'
        }, _options=self.make_options())
        self.assertIsInstance(pkg, DirectoryPackage)
        self.assertEqual(pkg.name, 'foo')
        self.assertEqual(pkg.submodules, None)
        self.assertEqual(pkg.should_deploy, False)
        self.assertEqual(pkg.config_file, '/path/to/mopack.yml')
        self.assertEqual(pkg.path, Path('absolute', '/path'))
        self.assertEqual(pkg.builder.type, 'bfg9000')

        self.assertEqual(pkg.get_usage(self.pkgdir, None), {
            'type': 'pkg_config', 'path': self.pkgconfdir('foo'),
            'pcfiles': ['foo'], 'extra_args': [],
        })
        with self.assertRaises(ValueError):
            pkg.get_usage(self.pkgdir, ['sub'])
Beispiel #20
0
 def test_other_base(self):
     self.assertEqual(
         any_path('cfgdir')('field', Path('srcdir', 'path')),
         Path('srcdir', 'path'))
Beispiel #21
0
import os
from unittest import TestCase

from mopack.path import Path
from mopack.placeholder import placeholder
from mopack.shell import *

srcdir = Path('srcdir', '')
srcdir_ph = placeholder(srcdir)


class TestSplitWindows(TestCase):
    def assertSplitEqual(self, value, expected, **kwargs):
        self.assertEqual(split_windows_str(value, **kwargs), expected)
        self.assertEqual(split_windows(value, **kwargs),
                         ShellArguments(expected))

    def test_single(self):
        self.assertSplitEqual('foo', ['foo'])
        self.assertSplitEqual(' foo', ['foo'])
        self.assertSplitEqual('foo ', ['foo'])
        self.assertSplitEqual(' foo ', ['foo'])

    def test_multiple(self):
        self.assertSplitEqual('foo bar baz', ['foo', 'bar', 'baz'])

    def test_backslash(self):
        self.assertSplitEqual(r'C:\path\to\file', [r'C:\path\to\file'])

    def test_quote(self):
        self.assertSplitEqual('foo "bar baz"', ['foo', 'bar baz'])
Beispiel #22
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': [],
            })
Beispiel #23
0
def buildpathobj(p):
    return Path('builddir', p)
Beispiel #24
0
def srcpathobj(p):
    return Path('srcdir', p)
Beispiel #25
0
def abspathobj(p):
    return Path('absolute', p)
Beispiel #26
0
 def test_absolute_posix(self):
     with mock.patch('os.path', posixpath):
         for i in ('cfgdir', None):
             self.assertEqual(
                 abs_or_inner_path(i)('field', '/path'),
                 Path('absolute', '/path'))