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

cmake: use the cmake snap by default #938

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
15 changes: 13 additions & 2 deletions craft_parts/plugins/cmake_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -65,22 +66,32 @@ 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

@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")

Expand Down
16 changes: 10 additions & 6 deletions tests/unit/plugins/test_cmake_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down