예제 #1
0
def conduct_project_sanity_check(project: Project, **kwargs) -> None:
    """Sanity check the project itself before continuing.

    The checks done here are meant to be light, and not rely on the build environment.
    """
    # The snapcraft.yaml should be valid even without extensions applied
    # This here check is mostly for backwards compatibility with the
    # rest of the code base.
    if project.info is not None:
        project.info.validate_raw_snapcraft()

    if project._get_build_base() == "core":
        raise errors.UnsupportedBaseError(base="core")

    snap_dir_path = os.path.join(project._get_snapcraft_assets_dir())
    if os.path.isdir(snap_dir_path):
        # TODO: move this check to the ProjectInfo class.
        _check_snap_dir(snap_dir_path)

    if (
        project._get_build_base() in ["core20"]
        and kwargs.get("target_arch") is not None
        and not os.getenv("SNAPCRAFT_ENABLE_EXPERIMENTAL_TARGET_ARCH")
    ):
        raise SnapcraftEnvironmentError(
            "*EXPERIMENTAL* '--target-arch' configured, but not enabled. "
            "Enable with '--enable-experimental-target-arch' flag."
        )

    # Icon should refer to project file, verify it exists.
    icon = project.info.get_raw_snapcraft().get("icon")
    if icon and not os.path.exists(icon):
        raise SnapcraftEnvironmentError(f"Specified icon {icon!r} does not exist.")
예제 #2
0
def load_plugin(
    plugin_name: str,
    part_name: str,
    project: Project,
    properties,
    part_schema,
    definitions_schema,
) -> plugins.v1.PluginV1:
    local_plugins_dir = project._get_local_plugins_dir()
    if local_plugins_dir is not None:
        plugin_class = _get_local_plugin_class(
            plugin_name=plugin_name, local_plugins_dir=local_plugins_dir
        )
    if plugin_class is None:
        plugin_class = plugins.get_plugin_for_base(
            plugin_name, build_base=project._get_build_base()
        )

    if issubclass(plugin_class, plugins.v2.PluginV2):
        plugin_schema = plugin_class.get_schema()
        options = _make_options(
            part_name, part_schema, definitions_schema, properties, plugin_schema
        )
        plugin = plugin_class(part_name=part_name, options=options)
    else:
        plugin_schema = plugin_class.schema()
        _validate_pull_and_build_properties(
            plugin_name, plugin_class, part_schema, definitions_schema
        )
        options = _make_options(
            part_name, part_schema, definitions_schema, properties, plugin_schema
        )
        plugin = plugin_class(part_name, options, project)

        if project.is_cross_compiling:
            logger.debug(
                "Setting {!r} as the compilation target for {!r}".format(
                    project.deb_arch, plugin_name
                )
            )
            plugin.enable_cross_compilation()

    return plugin