Esempio n. 1
0
    def test_auto_generate_source(self):
        result = self.context['object_file'](file='main.qrc')
        intermediate = result.creator.file
        self.assertSameFile(result, self.output_file('main'))
        self.assertSameFile(intermediate, file_types.SourceFile(
            Path('main.cpp'), lang='c++'
        ))
        self.assertSameFile(intermediate.creator.file, file_types.SourceFile(
            Path('main.qrc', Root.srcdir), lang='qrc'
        ))

        src = self.context['auto_file']('main.hpp', lang='qtmoc')
        result = self.context['object_file'](file=src)
        intermediate = result.creator.file
        self.assertSameFile(result, self.output_file('moc_main'))
        self.assertSameFile(intermediate, file_types.SourceFile(
            Path('moc_main.cpp', Root.builddir), lang='c++'
        ))
        self.assertSameFile(intermediate.creator.file, file_types.HeaderFile(
            Path('main.hpp', Root.srcdir), lang='qtmoc'
        ))

        result = self.context['object_file'](file='main.qrc', directory='dir')
        intermediate = result.creator.file
        self.assertSameFile(result, self.output_file('dir/main'))
        self.assertSameFile(intermediate, file_types.SourceFile(
            Path('dir/main.cpp'), lang='c++'
        ))
        self.assertSameFile(intermediate.creator.file, file_types.SourceFile(
            Path('main.qrc', Root.srcdir), lang='qrc'
        ))
Esempio n. 2
0
    def make_file_list(self, return_src=False, prefix=''):
        files = [file_types.SourceFile(Path(i, Root.builddir), 'c++')
                 for i in [prefix + 'src1.cpp', prefix + 'src2.cpp']]
        src_files = [file_types.SourceFile(Path(i, Root.srcdir), 'qrc')
                     for i in [prefix + 'src1', prefix + 'src2']]

        file_list = self.context['generated_sources'](src_files)

        if return_src:
            return file_list, files, src_files
        return file_list, files
Esempio n. 3
0
 def test_submodule(self):
     with self.context.push_path(Path('dir/build.bfg', Root.srcdir)):
         result = self.context['build_step']('lex.yy.c',
                                             cmd=['lex', 'foo.lex'])
         expected = file_types.SourceFile(Path('lex.yy.c', Root.builddir),
                                          'c')
         self.assertSameFile(result, expected)
Esempio n. 4
0
    def test_input(self):
        foolex = self.context['source_file']('foo.lex')
        build_step = self.context['build_step']
        expected = file_types.SourceFile(Path('lex.yy.c', Root.builddir), 'c')

        result = build_step('lex.yy.c',
                            cmd=['lex', build_step.input],
                            files=foolex)
        self.assertSameFile(result, expected)
        self.assertCommand(result.creator, [['lex', foolex]], [foolex],
                           phony=False)

        result = build_step('lex.yy.c',
                            cmd=['lex', build_step.input[0]],
                            files=foolex)
        self.assertSameFile(result, expected)
        self.assertCommand(result.creator, [['lex', foolex]], [foolex],
                           phony=False)

        result = build_step('lex.yy.c',
                            cmd=['lex', build_step.input[0:]],
                            files=foolex)
        self.assertSameFile(result, expected)
        self.assertCommand(result.creator, [['lex', foolex]], [foolex],
                           phony=False)

        with self.assertRaises(IndexError):
            build_step('foo', cmd=[build_step.input[1]], files=foolex)
Esempio n. 5
0
    def test_input_line(self):
        foopy = self.context['source_file']('foo.py')
        build_step = self.context['build_step']
        expected = file_types.SourceFile(Path('foo.c', Root.builddir), 'c')

        result = build_step('foo.c', cmd=build_step.input, files=foopy)
        self.assertSameFile(result, expected)
        self.assertCommand(result.creator, [self.env.tool('python')(foopy)],
                           [foopy],
                           phony=False)

        result = build_step('foo.c', cmd=build_step.input[0], files=foopy)
        self.assertSameFile(result, expected)
        self.assertCommand(result.creator, [self.env.tool('python')(foopy)],
                           [foopy],
                           phony=False)

        result = build_step('foo.c', cmd=build_step.input[0:], files=foopy)
        self.assertSameFile(result, expected)
        self.assertCommand(result.creator, [self.env.tool('python')(foopy)],
                           [foopy],
                           phony=False)

        with self.assertRaises(IndexError):
            build_step('foo.c', cmd=build_step.input[1], files=foopy)
        with self.assertRaises(ValueError):
            build_step('foo.c', cmd=build_step.input, files=[foopy, foopy])
Esempio n. 6
0
    def test_output(self):
        build_step = self.context['build_step']
        expected = file_types.SourceFile(Path('foo-lex.c', Root.builddir), 'c')

        result = build_step('foo-lex.c',
                            cmd=['lex', 'foo.lex', '-o', build_step.output])
        self.assertSameFile(result, expected)
        self.assertCommand(result.creator,
                           [['lex', 'foo.lex', '-o', expected]],
                           phony=False)

        result = build_step('foo-lex.c',
                            cmd=['lex', 'foo.lex', '-o', build_step.output[0]])
        self.assertSameFile(result, expected)
        self.assertCommand(result.creator,
                           [['lex', 'foo.lex', '-o', expected]],
                           phony=False)

        result = build_step(
            'foo-lex.c', cmd=['lex', 'foo.lex', '-o', build_step.output[0:]])
        self.assertSameFile(result, expected)
        self.assertCommand(result.creator,
                           [['lex', 'foo.lex', '-o', expected]],
                           phony=False)

        with self.assertRaises(IndexError):
            build_step('foo', cmd=[build_step.output[1]])
Esempio n. 7
0
 def test_always_outdated(self):
     result = self.context['build_step']('lex.yy.c',
                                         cmd=['lex', 'foo.lex'],
                                         always_outdated=True)
     expected = file_types.SourceFile(Path('lex.yy.c', Root.builddir), 'c')
     self.assertSameFile(result, expected)
     self.assertCommand(result.creator, [['lex', 'foo.lex']], phony=True)
Esempio n. 8
0
 def test_output_file(self):
     fmt = self.env.target_platform.object_format
     out = file_types.MsvcPrecompiledHeader(
         Path('hdr.pch'), Path('src.obj'), 'hdr.h', fmt, 'c++'
     )
     self.assertEqual(self.compiler.output_file('hdr.h', AttrDict(
         pch_source=file_types.SourceFile(Path('src.c'), 'c')
     )), [out, out.object_file])
Esempio n. 9
0
 def test_file_cmd(self):
     foolex = self.context['source_file']('foo.lex')
     result = self.context['build_step']('lex.yy.c', cmd=['lex', foolex])
     expected = file_types.SourceFile(Path('lex.yy.c', Root.builddir), 'c')
     self.assertSameFile(result, expected)
     self.assertCommand(result.creator, [['lex', foolex]],
                        extra_deps=[foolex],
                        phony=False)
Esempio n. 10
0
    def test_make_simple(self):
        linker = self.env.builder('c++').linker('shared_library')

        result = self.builtin_dict['shared_library']('shared', ['main.cpp'])
        self.assertEqual(result, self.output_file(linker, 'shared', None))

        src = file_types.SourceFile(Path('main.cpp', Root.srcdir))
        result = self.builtin_dict['shared_library']('shared', [src])
        self.assertEqual(result, self.output_file(linker, 'shared', None))
Esempio n. 11
0
 def test_multiple_outputs(self):
     result = self.context['build_step'](['hello.tab.h', 'hello.tab.c'],
                                         cmd=['bison', 'hello.y'])
     expected = [
         file_types.HeaderFile(Path('hello.tab.h', Root.builddir), 'c'),
         file_types.SourceFile(Path('hello.tab.c', Root.builddir), 'c')
     ]
     for i, j in zip(result, expected):
         self.assertSameFile(i, j)
         self.assertCommand(i.creator, [['bison', 'hello.y']], phony=False)
Esempio n. 12
0
    def test_make_simple(self):
        compiler = self.env.builder('c++').compiler

        result = self.builtin_dict['object_file'](file='main.cpp')
        self.assertEqual(result, self.output_file(compiler, 'main', None))

        result = self.builtin_dict['object_file']('object', 'main.cpp')
        self.assertEqual(result, self.output_file(compiler, 'object', None))

        src = file_types.SourceFile(Path('main.cpp', Root.srcdir))
        result = self.builtin_dict['object_file']('object', src)
        self.assertEqual(result, self.output_file(compiler, 'object', None))
Esempio n. 13
0
    def test_make_simple(self):
        class Context(object):
            langs = ['c++']

        linker = self.env.builder('c++').linker('static_library')

        result = self.builtin_dict['static_library']('static', ['main.cpp'])
        self.assertEqual(result, self.output_file(linker, 'static', Context()))

        src = file_types.SourceFile(Path('main.cpp', Root.srcdir))
        result = self.builtin_dict['static_library']('static', [src])
        self.assertEqual(result, self.output_file(linker, 'static', Context()))
Esempio n. 14
0
    def test_make_no_lang(self):
        compiler = self.env.builder('c++').compiler

        result = self.builtin_dict['object_file']('object', 'main.goofy',
                                                  lang='c++')
        self.assertEqual(result, self.output_file(compiler, 'object', None))

        self.assertRaises(ValueError, self.builtin_dict['object_file'],
                          'object', 'main.goofy')

        src = file_types.SourceFile(Path('main.goofy', Root.srcdir))
        self.assertRaises(ValueError, self.builtin_dict['object_file'],
                          'object', src)
Esempio n. 15
0
    def make_object_files(self, make_src=False):
        files = [file_types.ObjectFile(Path(i, Root.srcdir), None)
                 for i in ['obj1', 'obj2']]
        if make_src:
            src_files = [file_types.SourceFile(Path(i, Root.srcdir), None)
                         for i in ['src1', 'src2']]
            for f, s in zip(files, src_files):
                f.creator = MockCompile(s)

        obj_files = self.builtin_dict['object_files'](files)

        if make_src:
            return obj_files, files, src_files
        return obj_files, files
Esempio n. 16
0
    def make_file_list(self, make_src=False, prefix=''):
        files = [file_types.ObjectFile(Path(i, Root.srcdir), None)
                 for i in [prefix + 'obj1', prefix + 'obj2']]
        if make_src:
            src_files = [file_types.SourceFile(Path(i, Root.srcdir), None)
                         for i in [prefix + 'src1', prefix + 'src2']]
            for f, s in zip(files, src_files):
                f.creator = MockCompile(s)

        file_list = self.context['object_files'](files)

        if make_src:
            return file_list, files, src_files
        return file_list, files
Esempio n. 17
0
    def test_make_simple_dual(self):
        class Context(object):
            langs = ['c++']

        src = file_types.SourceFile(Path('main.cpp', Root.srcdir))
        shared_linker = self.env.builder('c++').linker('shared_library')
        static_linker = self.env.builder('c++').linker('static_library')
        with mock.patch('warnings.warn', lambda s: None):
            result = self.builtin_dict['library']('library', [src],
                                                  kind='dual')

        if shared_linker.builder.can_dual_link:
            self.assertEqual(
                result,
                file_types.DualUseLibrary(
                    self.output_file(shared_linker, 'library', None),
                    self.output_file(static_linker, 'library', Context())))
        else:
            self.assertEqual(result,
                             self.output_file(shared_linker, 'library', None))
Esempio n. 18
0
    def test_make_soversion(self):
        class Context(object):
            version = '1'
            soversion = '1'

        src = file_types.SourceFile(Path('main.cpp', Root.srcdir))
        linker = self.env.builder('c++').linker('shared_library')
        result = self.builtin_dict['shared_library']('shared', [src],
                                                     version='1',
                                                     soversion='1')
        self.assertEqual(result, self.output_file(linker, 'shared', Context()))

        self.assertRaises(ValueError,
                          self.builtin_dict['shared_library'],
                          'shared', [src],
                          version='1')
        self.assertRaises(ValueError,
                          self.builtin_dict['shared_library'],
                          'shared', [src],
                          soversion='1')
Esempio n. 19
0
    def test_make_directory(self):
        with mock.patch('bfg9000.builtins.file_types.make_immediate_file',
                        return_value=self.MockFile()):
            pch = self.builtin_dict['precompiled_header']

            result = pch(file='main.hpp', directory='dir')
            self.assertSameFile(result,
                                self.output_file('dir/main.hpp', self.context))

            src = self.builtin_dict['header_file']('main.hpp')
            result = pch(file=src, directory='dir')
            self.assertSameFile(result,
                                self.output_file('dir/main.hpp', self.context))

            result = pch(file='main.hpp', directory='dir/')
            self.assertSameFile(result,
                                self.output_file('dir/main.hpp', self.context))

            result = pch(file='main.hpp', directory=Path('dir'))
            self.assertSameFile(result,
                                self.output_file('dir/main.hpp', self.context))

            result = pch(file='dir1/main.hpp', directory='dir2')
            context = {
                'pch_source':
                file_types.SourceFile(Path('dir1/main.cpp', Root.srcdir),
                                      'c++')
            }
            self.assertSameFile(
                result, self.output_file('dir2/dir1/main.hpp', context))

            result = pch('object', 'main.hpp', directory='dir')
            self.assertSameFile(result,
                                self.output_file('object', self.context))

            self.assertRaises(ValueError,
                              pch,
                              file='main.hpp',
                              directory=Path('dir', Root.srcdir))
Esempio n. 20
0
class TestPrecompiledHeader(CompileTest):
    class MockFile(object):
        def write(self, data):
            pass

    mode = 'pch_compiler'
    context = {
        'pch_source': file_types.SourceFile(Path('main.cpp', Root.srcdir),
                                            'c++')
    }

    def test_identity(self):
        ex = file_types.PrecompiledHeader(Path('header', Root.srcdir), None)
        self.assertIs(self.builtin_dict['precompiled_header'](ex), ex)

    def test_src_file(self):
        expected = file_types.PrecompiledHeader(Path('header', Root.srcdir),
                                                'c')
        self.assertSameFile(self.builtin_dict['precompiled_header']('header'),
                            expected)
        self.assertEqual(list(self.build.sources()), [self.bfgfile, expected])

        self.builtin_dict['project'](lang='c++')
        expected.lang = 'c++'
        self.assertSameFile(self.builtin_dict['precompiled_header']('header'),
                            expected)

    def test_no_dist(self):
        expected = file_types.PrecompiledHeader(Path('header', Root.srcdir),
                                                'c')
        self.assertSameFile(
            self.builtin_dict['precompiled_header']('header', dist=False),
            expected)
        self.assertEqual(list(self.build.sources()), [self.bfgfile])

    def test_make_simple(self):
        with mock.patch('bfg9000.builtins.file_types.make_immediate_file',
                        return_value=self.MockFile()):
            pch = self.builtin_dict['precompiled_header']

            result = pch(file='main.hpp')
            self.assertSameFile(result,
                                self.output_file('main.hpp', self.context))

            result = pch('object', 'main.hpp')
            self.assertSameFile(result,
                                self.output_file('object', self.context))

            src = self.builtin_dict['header_file']('main.hpp')
            result = pch('object', src)
            self.assertSameFile(result,
                                self.output_file('object', self.context))

    def test_make_no_lang(self):
        with mock.patch('bfg9000.builtins.file_types.make_immediate_file',
                        return_value=self.MockFile()):
            pch = self.builtin_dict['precompiled_header']

            result = pch('object', 'main.goofy', lang='c++')
            self.assertSameFile(result,
                                self.output_file('object', self.context))
            self.assertRaises(ValueError, pch, 'object', 'main.goofy')

            src = self.builtin_dict['header_file']('main.goofy')
            self.assertRaises(ValueError, pch, 'object', src)

    def test_make_override_lang(self):
        with mock.patch('bfg9000.builtins.file_types.make_immediate_file',
                        return_value=self.MockFile()):
            pch = self.builtin_dict['precompiled_header']

            src = self.builtin_dict['header_file']('main.h', 'c')
            result = pch('object', src, lang='c++')
            self.assertSameFile(result,
                                self.output_file('object', self.context))
            self.assertEqual(result.creator.compiler.lang, 'c++')

    def test_make_directory(self):
        with mock.patch('bfg9000.builtins.file_types.make_immediate_file',
                        return_value=self.MockFile()):
            pch = self.builtin_dict['precompiled_header']

            result = pch(file='main.hpp', directory='dir')
            self.assertSameFile(result,
                                self.output_file('dir/main.hpp', self.context))

            src = self.builtin_dict['header_file']('main.hpp')
            result = pch(file=src, directory='dir')
            self.assertSameFile(result,
                                self.output_file('dir/main.hpp', self.context))

            result = pch(file='main.hpp', directory='dir/')
            self.assertSameFile(result,
                                self.output_file('dir/main.hpp', self.context))

            result = pch(file='main.hpp', directory=Path('dir'))
            self.assertSameFile(result,
                                self.output_file('dir/main.hpp', self.context))

            result = pch(file='dir1/main.hpp', directory='dir2')
            context = {
                'pch_source':
                file_types.SourceFile(Path('dir1/main.cpp', Root.srcdir),
                                      'c++')
            }
            self.assertSameFile(
                result, self.output_file('dir2/dir1/main.hpp', context))

            result = pch('object', 'main.hpp', directory='dir')
            self.assertSameFile(result,
                                self.output_file('object', self.context))

            self.assertRaises(ValueError,
                              pch,
                              file='main.hpp',
                              directory=Path('dir', Root.srcdir))

    def test_make_no_name_or_file(self):
        self.assertRaises(TypeError, self.builtin_dict['precompiled_header'])

    def test_description(self):
        result = self.builtin_dict['precompiled_header'](
            file='main.hpp', description='my description')
        self.assertEqual(result.creator.description, 'my description')
Esempio n. 21
0
 def test_single_output(self):
     result = self.context['build_step']('lex.yy.c', cmd=['lex', 'foo.lex'])
     expected = file_types.SourceFile(Path('lex.yy.c', Root.builddir), 'c')
     self.assertSameFile(result, expected)
     self.assertCommand(result.creator, [['lex', 'foo.lex']], phony=False)
Esempio n. 22
0
 def test_default_name(self):
     src = file_types.SourceFile(Path('file.java', Root.srcdir), 'java')
     self.assertEqual(self.compiler.default_name(src, None), 'file')
Esempio n. 23
0
 def output_file(self, name, pch_source='main.cpp', *args, **kwargs):
     pch_source_path = Path(name).parent().append(pch_source)
     step = {'pch_source': file_types.SourceFile(pch_source_path, 'c++')}
     return super().output_file(name, step, *args, **kwargs)
Esempio n. 24
0
 class Context(object):
     pch_source = file_types.SourceFile(Path('file.cpp', Root.srcdir))