示例#1
0
def run(command_name: str, parsed_args: "argparse.Namespace") -> None:
    """Run the parts lifecycle.

    :raises SnapcraftError: if the step name is invalid, or the project
        yaml file cannot be loaded.
    :raises LegacyFallback: if the project's base is not core22.
    """
    emit.debug(f"command: {command_name}, arguments: {parsed_args}")

    snap_project = get_snap_project()
    yaml_data = process_yaml(snap_project.project_file)
    start_time = datetime.now()
    build_plan = get_build_plan(yaml_data, parsed_args)

    if parsed_args.provider:
        raise errors.SnapcraftError("Option --provider is not supported.")

    # Register our own plugins and callbacks
    plugins.register()
    callbacks.register_prologue(_set_global_environment)
    callbacks.register_pre_step(_set_step_environment)

    build_count = utils.get_parallel_build_count()

    for build_on, build_for in build_plan:
        emit.verbose(f"Running on {build_on} for {build_for}")
        yaml_data_for_arch = apply_yaml(yaml_data, build_on, build_for)
        parse_info = _extract_parse_info(yaml_data_for_arch)
        _expand_environment(
            yaml_data_for_arch,
            parallel_build_count=build_count,
            target_arch=build_for,
        )
        project = Project.unmarshal(yaml_data_for_arch)

        try:
            _run_command(
                command_name,
                project=project,
                parse_info=parse_info,
                parallel_build_count=build_count,
                assets_dir=snap_project.assets_dir,
                start_time=start_time,
                parsed_args=parsed_args,
            )
        except PermissionError as err:
            raise errors.FilePermissionError(err.filename, reason=err.strerror)
示例#2
0
def test_get_parallel_build_count_limited(mocker, max_count, count):
    mocker.patch("os.sched_getaffinity", return_value=[1] * 13)
    mocker.patch.dict(os.environ, {"SNAPCRAFT_MAX_PARALLEL_BUILD_COUNT": max_count})
    assert utils.get_parallel_build_count() == count
示例#3
0
def test_get_parallel_build_count_disable(mocker):
    mocker.patch("os.sched_getaffinity", side_effect=AttributeError)
    mocker.patch("multiprocessing.cpu_count", side_effect=NotImplementedError)
    assert utils.get_parallel_build_count() == 1
示例#4
0
def test_get_parallel_build_count_no_affinity(mocker):
    mocker.patch("os.sched_getaffinity", side_effect=AttributeError)
    mocker.patch("multiprocessing.cpu_count", return_value=17)
    assert utils.get_parallel_build_count() == 17
示例#5
0
def test_get_parallel_build_count(mocker):
    mocker.patch("os.sched_getaffinity", return_value=[1] * 13)
    assert utils.get_parallel_build_count() == 13