From b4c5c9956d94812c4eecdcea82eac925537e66e3 Mon Sep 17 00:00:00 2001 From: Soumyadeep Ghosh Date: Sat, 14 Dec 2024 21:57:09 +0530 Subject: [PATCH] cmake: use the cmake snap by default - allow using the cmake snap or deb - add an option to specify the source for cmake --- craft_parts/plugins/cmake_plugin.py | 15 +++++++++++++-- tests/unit/plugins/test_cmake_plugin.py | 16 ++++++++++------ 2 files changed, 23 insertions(+), 8 deletions(-) diff --git a/craft_parts/plugins/cmake_plugin.py b/craft_parts/plugins/cmake_plugin.py index 0ff290b65..baee4b925 100644 --- a/craft_parts/plugins/cmake_plugin.py +++ b/craft_parts/plugins/cmake_plugin.py @@ -31,6 +31,7 @@ class CMakePluginProperties(PluginProperties, frozen=True): cmake_parameters: list[str] = [] cmake_generator: str = "Unix Makefiles" + cmake_source: str = "snap" # part properties required by the plugin source: str # pyright: ignore[reportGeneralTypeIssues] @@ -65,6 +66,11 @@ class CMakePlugin(Plugin): (string; default: "Unix Makefiles") Determine what native build system is to be used. Can be either `Ninja` or `Unix Makefiles` (default). + + - cmake-source + (string; default: "deb") + Determine the source type. + Can be either `deb` (default) or `snap`. """ properties_class = CMakePluginProperties @@ -72,15 +78,20 @@ class CMakePlugin(Plugin): @override def get_build_snaps(self) -> set[str]: """Return a set of required snaps to install in the build environment.""" + options = cast(CMakePluginProperties, self._options) + if options.cmake_source == "snap": + return {"cmake"} return set() @override def get_build_packages(self) -> set[str]: """Return a set of required packages to install in the build environment.""" - build_packages = {"gcc", "cmake"} - options = cast(CMakePluginProperties, self._options) + if options.cmake_source == "deb": + build_packages = {"gcc", "cmake"} + build_packages = {"gcc"} + if options.cmake_generator == "Ninja": build_packages.add("ninja-build") diff --git a/tests/unit/plugins/test_cmake_plugin.py b/tests/unit/plugins/test_cmake_plugin.py index 1a834f879..e507b7ca1 100644 --- a/tests/unit/plugins/test_cmake_plugin.py +++ b/tests/unit/plugins/test_cmake_plugin.py @@ -47,29 +47,33 @@ class TestPluginCMakePlugin: def test_get_build_snaps(self, setup_method_fixture, new_dir): plugin = setup_method_fixture(new_dir) - assert plugin.get_build_snaps() == set() + assert plugin.get_build_snaps() == {"cmake"} def test_get_build_packages_default(self, setup_method_fixture, new_dir): plugin = setup_method_fixture(new_dir) - assert plugin.get_build_packages() == { - "gcc", - "cmake", - } + assert plugin.get_build_packages() == {"gcc"} + assert plugin.get_build_snaps() == {"cmake"} def test_get_build_packages_ninja(self, setup_method_fixture, new_dir): plugin = setup_method_fixture(new_dir, properties={"cmake-generator": "Ninja"}) assert plugin.get_build_packages() == { "gcc", - "cmake", "ninja-build", } + assert plugin.get_build_snaps() == {"cmake"} def test_get_build_packages_unix_makefiles(self, setup_method_fixture, new_dir): plugin = setup_method_fixture( new_dir, properties={"cmake-generator": "Unix Makefiles"} ) + assert plugin.get_build_packages() == {"gcc"} + assert plugin.get_build_snaps() == {"cmake"} + + def test_get_build_packages_deb(self, setup_method_fixture, new_dir): + plugin = setup_method_fixture(new_dir, properties={"cmake-source": "deb"}) + assert plugin.get_build_packages() == { "gcc", "cmake",