def test_CommandFileBuilder_clean_should_remove_build_folder():
    builder = CommandFileBuilder(target_name='myfile', build_command='')
    builder.install_dir.mkdir(exist_ok=True)
    assert builder.install_dir.is_dir()

    builder.clean(force=True)

    assert not builder.install_dir.is_dir()
def test_CommandFileBuilder_build_should_return_path_to_file():
    with tempfile.NamedTemporaryFile() as tmpfile:
        tmpfilepath = Path(tmpfile.name)
        builder = CommandFileBuilder(install_dir=tmpfilepath.parent,
                                     target_name=tmpfilepath.name,
                                     build_command='')

        output_path = builder.build()
        assert output_path == str(builder.output_filepath)
def test_CommandFileBuilder_build_should_error_on_command_error():
    build_cmd = 'some-non-existant-build command'

    with tempfile.NamedTemporaryFile() as tmpfile:
        tmpfilepath = Path(tmpfile.name)
        builder = CommandFileBuilder(install_dir=tmpfilepath.parent,
                                     target_name=tmpfilepath.name,
                                     build_command=build_cmd)

        with pytest.raises(TestsBuildError):
            builder.build()
def test_CommandFileBuilder_build_runs_build_command():
    build_cmd = 'some-build command'

    with tempfile.NamedTemporaryFile() as tmpfile:
        tmpfilepath = Path(tmpfile.name)
        builder = CommandFileBuilder(install_dir=tmpfilepath.parent,
                                     target_name=tmpfilepath.name,
                                     build_command=build_cmd)

        with patch('subprocess.check_output') as check_output:
            builder.build()

            check_output.assert_called_once()
            assert build_cmd in check_output.call_args[0]
Ejemplo n.º 5
0
    def create_builder(target_name: str,
                       sources: List[str],
                       flags: List[str] = None,
                       env_file: Optional[Path] = None,
                       install_dir: Optional[Path] = None) -> FileBuilder:
        '''Return a builder to cross-compile a C application with a Yocto SDK'''
        if not target_name or not env_file or not sources:
            raise ValueError('Null target, environment or sources passed')

        if not install_dir:
            install_dir = YoctoCBuilder.DEFAULT_EXEC_INSTALL_DIR

        if not flags:
            flags_str = ''
        else:
            flags_str = ' '.join(flags)

        sources_str = ' '.join(sources)
        output_filepath = Path(install_dir).joinpath(target_name)
        command = f'. {env_file} && $CC {sources_str} {flags_str} -o {output_filepath}'
        return CommandFileBuilder(target_name=target_name,
                                  build_command=command,
                                  install_dir=install_dir)
def test_CommandFileBuilder_output_filepath_use_target_and_install_dir():
    output = 'myfile'
    install_dir = Path('mydir')
    builder = CommandFileBuilder(target_name=output, install_dir=install_dir,
                                 build_command='')
    assert builder.output_filepath.resolve() == install_dir.resolve() / output
def test_CommandFileBuilder_install_folder_should_defaults_to_local_build_folder():
    builder = CommandFileBuilder(target_name='abc', build_command='xyz')
    assert builder.output_filepath != Path.cwd()
    assert str(builder.output_filepath).startswith(str(Path.cwd()))
def test_CommandFileBuilder_install_folder_should_be_local():
    install = Path('mybuild')
    builder = CommandFileBuilder(target_name='abc', build_command='xyz',
                                 install_dir=install)
    assert str(builder.install_dir.resolve()).startswith(str(Path.cwd()))
def test_CommandFileBuilder_build_should_error_if_file_not_built():
    builder = CommandFileBuilder(target_name='any_name', build_command='')
    with pytest.raises(TestsBuildError):
        builder.build()