diff --git a/snapcraft/application.py b/snapcraft/application.py index b65fea747d..2ce8942361 100644 --- a/snapcraft/application.py +++ b/snapcraft/application.py @@ -84,6 +84,19 @@ def _get_esm_error_for_base(base: str) -> None: ) +def _get_base_warning_for_base(base: str) -> None: + """Emit a warning to use Snapcraft 9.x for core22, core24, and core26 bases.""" + match base: + case "core22" | "core24" | "core26": + emit.warning( + f"Base {base!r} is supported in Snapcraft 9.x. " + "It is recommended to upgrade to Snapcraft 9.x via the 'latest/stable' channel " + "to benefit from the latest bug fixes and performance improvements." + ) + case _: + return + + class Snapcraft(Application): """Snapcraft application definition.""" @@ -174,6 +187,7 @@ def _pre_run(self, dispatcher: craft_cli.Dispatcher) -> None: ) _get_esm_error_for_base(effective_base) self._ensure_remote_build_supported(effective_base) + _get_base_warning_for_base(effective_base) super()._pre_run(dispatcher) diff --git a/tests/unit/test_application.py b/tests/unit/test_application.py index 742b4f9ace..e2e0ba3ab1 100644 --- a/tests/unit/test_application.py +++ b/tests/unit/test_application.py @@ -418,6 +418,18 @@ def test_esm_pass(mocker, snapcraft_yaml, base): mock_dispatch.assert_called_once() +@pytest.mark.parametrize("base", ["core22", "core24", "core26"]) +def test_get_base_warning_for_base_emits_message(emitter, base): + """Test that _get_base_warning_for_base emits the correct message for core22, core24, and core26.""" + application._get_base_warning_for_base(base) + + emitter.assert_warning( + f"Base {base!r} is supported in Snapcraft 9.x. " + "It is recommended to upgrade to Snapcraft 9.x via the 'latest/stable' channel " + "to benefit from the latest bug fixes and performance improvements." + ) + + def test_yaml_syntax_error(in_project_path, monkeypatch, capsys): """Provide a user friendly error on yaml syntax errors.""" (in_project_path / "snapcraft.yaml").write_text("bad:\nyaml")