Skip to content

Commit

Permalink
fix(remotebuild): require core20 snaps to use the legacy remote build…
Browse files Browse the repository at this point in the history
…er (#4895)

Requires core20 snaps to use the legacy remote builder because the new
remote builder cannot parse core20 `snapcraft.yaml` files (#4885).

Signed-off-by: Callahan Kovacs <[email protected]>
  • Loading branch information
mr-cal authored Jul 6, 2024
1 parent 124c932 commit d9c8781
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 15 deletions.
8 changes: 5 additions & 3 deletions docs/explanation/remote-build.rst
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,9 @@ remote-builder.
Current
^^^^^^^

The current remote builder is available for ``core20``, ``core22``, ``core24``,
and newer snaps.
The current remote builder is available for ``core22``, ``core24``,
and newer snaps. It is not available for ``core20`` snaps because it cannot
parse ``core20``'s ``snapcraft.yaml`` schema (`[10]`_).

It does not modify the project or project metadata.

Expand Down Expand Up @@ -70,7 +71,7 @@ If the environment variable is unset, the remote builder will be determined
by the base:

* ``core22``, ``core24``, and newer snaps will use the current remote builder
* ``core20`` snaps will use the legacy remote builder by default.
* ``core20`` snaps will use the legacy remote builder

Platforms and architectures
---------------------------
Expand Down Expand Up @@ -172,3 +173,4 @@ Launchpad is not able to parse this notation (`[9]`_).
.. _`[7]`: https://bugs.launchpad.net/snapcraft/+bug/1992557
.. _`[8]`: https://bugs.launchpad.net/snapcraft/+bug/2007789
.. _`[9]`: https://bugs.launchpad.net/snapcraft/+bug/2042167
.. _`[10]`: https://github.com/canonical/snapcraft/issues/4885
16 changes: 11 additions & 5 deletions snapcraft/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,12 +274,18 @@ def _get_dispatcher(self) -> craft_cli.Dispatcher:
"'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"
):

# core20 must use the legacy remote builder because the Project model
# cannot parse core20 snapcraft.yaml schemas (#4885)
if "core20" in (base, build_base):
if build_strategy == "disable-fallback":
raise RuntimeError(
"'SNAPCRAFT_REMOTE_BUILD_STRATEGY=disable-fallback' cannot "
"be used for core20 snaps. Unset the environment variable "
"or use 'force-fallback'."
)
raise errors.ClassicFallback()

# Use craft-application unless explicitly forced to use legacy snapcraft
if (
"core22" in (base, build_base)
Expand Down
15 changes: 8 additions & 7 deletions tests/unit/test_application.py
Original file line number Diff line number Diff line change
Expand Up @@ -440,18 +440,19 @@ def test_run_envvar(

@pytest.mark.parametrize("base", const.LEGACY_BASES)
@pytest.mark.usefixtures("mock_confirm", "mock_remote_build_argv")
def test_run_envvar_disable_fallback_core20(
snapcraft_yaml, base, mock_remote_build_run, mock_run_legacy, monkeypatch
):
"""core20 base run new remote-build if envvar is `disable-fallback`."""
def test_run_envvar_disable_fallback_core20(snapcraft_yaml, base, monkeypatch):
"""core20 bases cannot use the new remote-build."""
monkeypatch.setenv("SNAPCRAFT_REMOTE_BUILD_STRATEGY", "disable-fallback")
snapcraft_yaml_dict = {"base": base}
snapcraft_yaml(**snapcraft_yaml_dict)

application.main()
with pytest.raises(RuntimeError) as raised:
application.main()

mock_remote_build_run.assert_called_once()
mock_run_legacy.assert_not_called()
assert str(raised.value) == (
"'SNAPCRAFT_REMOTE_BUILD_STRATEGY=disable-fallback' cannot be used for core20 "
"snaps. Unset the environment variable or use 'force-fallback'."
)


@pytest.mark.parametrize("base", const.LEGACY_BASES | {"core22"})
Expand Down

0 comments on commit d9c8781

Please sign in to comment.