From d9c8781a1433bd0f335c23fa0303fa212015d517 Mon Sep 17 00:00:00 2001 From: Callahan Date: Fri, 5 Jul 2024 22:24:52 -0500 Subject: [PATCH] fix(remotebuild): require core20 snaps to use the legacy remote builder (#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 --- docs/explanation/remote-build.rst | 8 +++++--- snapcraft/application.py | 16 +++++++++++----- tests/unit/test_application.py | 15 ++++++++------- 3 files changed, 24 insertions(+), 15 deletions(-) diff --git a/docs/explanation/remote-build.rst b/docs/explanation/remote-build.rst index 837668e5c7..360db6d4d9 100644 --- a/docs/explanation/remote-build.rst +++ b/docs/explanation/remote-build.rst @@ -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. @@ -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 --------------------------- @@ -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 diff --git a/snapcraft/application.py b/snapcraft/application.py index d5bc2754ed..f7e4e72999 100644 --- a/snapcraft/application.py +++ b/snapcraft/application.py @@ -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) diff --git a/tests/unit/test_application.py b/tests/unit/test_application.py index 0162aac494..3a640c6a5a 100644 --- a/tests/unit/test_application.py +++ b/tests/unit/test_application.py @@ -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"})