Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(remote)!: use craft-application remote build for core22 #4724

Merged
merged 6 commits into from
Apr 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 48 additions & 1 deletion snapcraft/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import os
import pathlib
import sys
from typing import Any
from typing import Any, Optional

import craft_application.commands as craft_app_commands
import craft_cli
Expand Down Expand Up @@ -62,6 +62,25 @@
}


def _get_esm_error_for_base(base: str) -> None:
syu-w marked this conversation as resolved.
Show resolved Hide resolved
"""Raise an error appropriate for the base under ESM."""
channel: Optional[str] = None
match base:
case "core":
channel = "4.x"
version = "4"
case "core18":
channel = "7.x"
version = "7"
case _:
return

raise RuntimeError(
f"ERROR: base {base!r} was last supported on Snapcraft {version} available "
f"on the {channel!r} channel."
)


class Snapcraft(Application):
"""Snapcraft application definition."""

Expand Down Expand Up @@ -163,11 +182,39 @@ def _get_dispatcher(self) -> craft_cli.Dispatcher:
yaml_data = util.safe_yaml_load(file)
base = yaml_data.get("base")
build_base = yaml_data.get("build-base")
_get_esm_error_for_base(base)
if "core24" in (base, build_base) or build_base == "devel":
# We know for sure that we're handling a core24 project
self._known_core24 = True
elif any(arg in ("version", "--version", "-V") for arg in sys.argv):
pass
elif "remote-build" in sys.argv and any(
syu-w marked this conversation as resolved.
Show resolved Hide resolved
b in ("core20", "core22") for b in (base, build_base)
):
build_strategy = os.environ.get("SNAPCRAFT_REMOTE_BUILD_STRATEGY", None)
if build_strategy not in (
"force-fallback",
"disable-fallback",
"",
None,
):
raise errors.SnapcraftError(
f"Unknown value {build_strategy!r} in environment variable "
"'SNAPCRAFT_REMOTE_BUILD_STRATEGY'. "
"Valid values are 'disable-fallback' and 'force-fallback'."
)
# Use legacy snapcraft unless explicitly forced to use craft-application
if (
"core20" in (base, build_base)
and build_strategy != "disable-fallback"
):
raise errors.ClassicFallback()
# Use craft-application unless explicitly forced to use legacy snapcraft
if (
"core22" in (base, build_base)
and build_strategy == "force-fallback"
):
raise errors.ClassicFallback()
else:
raise errors.ClassicFallback()
return super()._get_dispatcher()
Expand Down
3 changes: 1 addition & 2 deletions snapcraft/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@

import craft_cli
import craft_store
from craft_application.errors import RemoteBuildError
from craft_cli import ArgumentParsingError, EmitterMode, ProvideHelpException, emit
from craft_providers import ProviderError

from snapcraft import errors, store, utils
from snapcraft.parts import plugins
from snapcraft.remote import RemoteBuildError

from . import commands
from .legacy_cli import run_legacy
Expand All @@ -44,7 +44,6 @@
commands.core22.StageCommand,
commands.core22.PrimeCommand,
commands.core22.PackCommand,
commands.core22.RemoteBuildCommand,
commands.core22.SnapCommand, # hidden (legacy compatibility)
commands.core22.PluginsCommand,
commands.core22.ListPluginsCommand,
Expand Down
2 changes: 0 additions & 2 deletions snapcraft/commands/core22/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
TryCommand,
)
from .lint import LintCommand
from .remote import RemoteBuildCommand

__all__ = [
"BuildCommand",
Expand All @@ -49,7 +48,6 @@
"PluginsCommand",
"PrimeCommand",
"PullCommand",
"RemoteBuildCommand",
"SnapCommand",
"StageCommand",
"TryCommand",
Expand Down
Loading
Loading