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

Sgmoore/update neon ext core22 #4023

Merged
merged 59 commits into from
Feb 23, 2023
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
59 commits
Select commit Hold shift + click to select a range
eb33e30
Add kde-neon extension support for core22.
ScarlettGatelyMoore Jan 20, 2023
0934eb5
Rename extension filename, convert tuples to dataclass, use match to …
ScarlettGatelyMoore Jan 25, 2023
93ab5d2
Update import and Class name in registry.
ScarlettGatelyMoore Jan 25, 2023
f62b68d
Update platform plug to match test. Update tests with new class name,…
ScarlettGatelyMoore Jan 25, 2023
3d8cb4d
Merge branch 'snapcore:main' into sgmoore/update_neon_ext_core22
ScarlettGatelyMoore Jan 25, 2023
96a1396
Fix lint tests.
ScarlettGatelyMoore Jan 25, 2023
f4681a8
Merge branch 'main' into sgmoore/update_neon_ext_core22
ScarlettGatelyMoore Jan 25, 2023
437bbbe
Fix black test.
ScarlettGatelyMoore Jan 25, 2023
2739903
Fix syntax found by black test.
ScarlettGatelyMoore Jan 25, 2023
014b184
Fix syntax found by black.
ScarlettGatelyMoore Jan 25, 2023
aabd50f
Fix kde-neon ext test formatting.
ScarlettGatelyMoore Jan 26, 2023
0764381
Also rename the test with underscore kde_neon
ScarlettGatelyMoore Jan 26, 2023
bdbef5c
Fix expectation yaml for kde-neon-extension and make-parameters in kd…
ScarlettGatelyMoore Jan 26, 2023
918bde1
Formatting! kde-neon test.
ScarlettGatelyMoore Jan 26, 2023
db1e9c3
More formatting fixes for kde_neon ext and test.
ScarlettGatelyMoore Jan 26, 2023
ea4fa1b
kde-neon extension test formatting
ScarlettGatelyMoore Jan 26, 2023
e86c36e
Remove f-strings, fix build-environment test.
ScarlettGatelyMoore Jan 26, 2023
9fa24f1
Fix formatting kde-neon test.
ScarlettGatelyMoore Jan 26, 2023
3a64f3a
Remove f-strings kde-neon ext, sort import block found by ruff.
ScarlettGatelyMoore Jan 26, 2023
794db89
Merge branch 'snapcore:main' into sgmoore/update_neon_ext_core22
ScarlettGatelyMoore Jan 27, 2023
f17f73e
Fix from tox -m fix kde-neon-extention test.
ScarlettGatelyMoore Jan 27, 2023
5526eac
Fix pylint line-to-long errors.
ScarlettGatelyMoore Jan 27, 2023
17156af
Fix formatting with black test, kde-neon test.
ScarlettGatelyMoore Jan 28, 2023
29dfe65
Fix docstring test for kde-neon extension.
ScarlettGatelyMoore Jan 28, 2023
1242aaf
Remove the extra blank line after docstring, kde-neon ext.
ScarlettGatelyMoore Jan 28, 2023
fb6964d
Merge branch 'main' into sgmoore/update_neon_ext_core22
ScarlettGatelyMoore Jan 30, 2023
dc7dad5
Merge branch 'snapcore:main' into sgmoore/update_neon_ext_core22
ScarlettGatelyMoore Feb 2, 2023
74fb596
kde-neon-extension: Fix unit test with missing option commpression: lzo.
ScarlettGatelyMoore Feb 2, 2023
0f2ba5f
kde-neon-extension: further attempt to fix my tests.
ScarlettGatelyMoore Feb 3, 2023
481e25f
kde-neon-extension: At some point I will get used to python formatting.
ScarlettGatelyMoore Feb 3, 2023
17a632b
kde-neon-extension: Fix Extension has invalid part names by add /sdk.
ScarlettGatelyMoore Feb 3, 2023
6feb7a7
kde-neon-extension: fix formatting again.. :( kde-neon test.
ScarlettGatelyMoore Feb 3, 2023
1e8fca4
kde-neon-extension: spread-test still using core20 snap, update conne…
ScarlettGatelyMoore Feb 3, 2023
2e9276c
kde-neon-extension: kde-neon test formatting again.
ScarlettGatelyMoore Feb 3, 2023
9a5b458
kde-neon-extension: try -all for the content snap connect.
ScarlettGatelyMoore Feb 3, 2023
b6a7e1a
kde-neon-extension: fix spread test with correct values for core20, a…
ScarlettGatelyMoore Feb 4, 2023
5667f00
kde-neon-extension: only run spread test on core20 until global is se…
ScarlettGatelyMoore Feb 4, 2023
e7ca659
kde-neon-extension: spread test, remove the -all from connect.
ScarlettGatelyMoore Feb 4, 2023
2abae68
kde-neon-extension: fix list_registry command test.. I hope.
ScarlettGatelyMoore Feb 4, 2023
633add3
kde-neon-extension: ebuild-environment assert again, either I fail li…
ScarlettGatelyMoore Feb 4, 2023
4b82e43
Merge branch 'main' into sgmoore/update_neon_ext_core22
ScarlettGatelyMoore Feb 10, 2023
47000a1
kde-neon-extension: fix various tox tests.
ScarlettGatelyMoore Feb 12, 2023
7ff11d0
kde-neon-extension: fix black linter.
ScarlettGatelyMoore Feb 12, 2023
d7f46f7
kde-neon-extension: fix pylint line to long.
ScarlettGatelyMoore Feb 12, 2023
d6ebe33
kde-neon-extension: fix spread test, remove the connect as we use pla…
ScarlettGatelyMoore Feb 12, 2023
0d84452
kde-neon-extension: remove cruft.. :(
ScarlettGatelyMoore Feb 12, 2023
221a717
kde-neon-extension: fix spacce for black linter.
ScarlettGatelyMoore Feb 12, 2023
1b39022
kde-neon-extension: fix sdk_different_channel test.
ScarlettGatelyMoore Feb 12, 2023
1d7c167
kde-neon-extension: and... changing make-parameters back again to mak…
ScarlettGatelyMoore Feb 12, 2023
598d76b
kde-neon-extension: fix spaces and line breaks in build-environment.
ScarlettGatelyMoore Feb 12, 2023
146e628
Merge remote-tracking branch 'origin/main' into sgmoore/update_neon_e…
sergiusens Feb 16, 2023
edc9478
lint: black
sergiusens Feb 16, 2023
4cd1e0f
kde-neon-extension: fix tests with proper test environment.
ScarlettGatelyMoore Feb 16, 2023
9f04fe5
kde-neon-extension: fix indentation.
ScarlettGatelyMoore Feb 16, 2023
8bda529
kde-neon-extension: fix pythonpath.
ScarlettGatelyMoore Feb 16, 2023
366f15e
kde-neon-extension:use join for pythonpath.
ScarlettGatelyMoore Feb 16, 2023
dc7160f
update tests, remove uneeded exports
sergiusens Feb 16, 2023
349d2e9
Merge branch 'main' into sgmoore/update_neon_ext_core22
ScarlettGatelyMoore Feb 20, 2023
c9779d8
Merge branch 'main' into sgmoore/update_neon_ext_core22
sergiusens Feb 23, 2023
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
268 changes: 268 additions & 0 deletions snapcraft/extensions/kde_neon.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,268 @@
# -*- Mode:Python; indent-tabs-mode:nil; tab-width:4 -*-
#
# Copyright 2022 Canonical Ltd.
# 2023 Scarlett Moore <sgmoore@kde.org>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 3 as
# published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

"""Generic KDE NEON extension to support core22 and onwards."""
import dataclasses
import functools
import re
from typing import Any, Dict, List, Optional, Tuple

from overrides import overrides

from .extension import Extension, get_extensions_data_dir, prepend_to_env

_SDK_SNAP = {"core22": "kde-frameworks-5-102-qt-5-15-8-core22-sd"}

@dataclasses.dataclass
class ExtensionInfo:
""" Content/SDK build information"""

cmake_args: str

@dataclasses.dataclass
class KDESnaps:
"""A structure of KDE related snaps."""

sdk: str
content: str
builtin: bool = True


class KDENeon(Extension):
"""The KDE Neon extension.

This extension makes it easy to assemble KDE based applications
using the Neon stack.

It configures each application with the following plugs:

\b
- Common Icon Themes.
- Common Sound Themes.
- The Qt5 and KDE Frameworks runtime libraries and utilities.

For easier desktop integration, it also configures each application
entry with these additional plugs:

\b
- desktop (https://snapcraft.io/docs/desktop-interface)
- desktop-legacy (https://snapcraft.io/docs/desktop-legacy-interface)
- opengl (https://snapcraft.io/docs/opengl-interface)
- wayland (https://snapcraft.io/docs/wayland-interface)
- x11 (https://snapcraft.io/docs/x11-interface)
"""

@staticmethod
@overrides
def get_supported_bases() -> Tuple[str, ...]:
return ("core22",)

@staticmethod
@overrides
def get_supported_confinement() -> Tuple[str, ...]:
return "strict", "devmode"

@staticmethod
@overrides
def is_experimental(base: Optional[str]) -> bool:
return False

@overrides
def get_app_snippet(self) -> Dict[str, Any]:
return {
"command-chain": ["snap/command-chain/desktop-launch"],
"plugs": [
"desktop",
"desktop-legacy",
"opengl",
"wayland",
"x11"
],
}

@functools.cached_property
def kde_snaps(self) -> KDESnaps:
"""Return the KDE related snaps to use to construct the environment."""
base = self.yaml_data["base"]
sdk_snap = _SDK_SNAP[base]

build_snaps: List[str] = []
for part in self.yaml_data["parts"].values():
build_snaps.extend(part.get("build-snaps", []))

matcher = re.compile(r"kde-frameworks-\d+-qt-\d+" + base + r"sd.*")
sdk_snap_candidates = [s for s in build_snaps if matcher.match(s)]
if sdk_snap_candidates:
sdk_snap = sdk_snap_candidates[0].split("/")[0]
builtin = False
else:
builtin = True
# The same except the trailing -sdk
content = sdk_snap[:-3]

return KDESnaps(sdk=sdk_snap, content=content, builtin=builtin)

@functools.cached_property
def ext_info(self) -> ExtensionInfo:
"""Return the extension info cmake_args, provider, content, build_snaps"""
cmake_args=f"-DCMAKE_FIND_ROOT_PATH=/snap/" + self.kde_snaps.sdk + f"/current"

return ExtensionInfo(cmake_args=cmake_args)

@overrides
def get_root_snippet(self) -> Dict[str, Any]:
platform_snap = self.kde_snaps.content
content_snap = self.kde_snaps.content + f"-all"

return {
"assumes": ["snapd2.43"], # for 'snapctl is-connected'
"compression": "lzo",
"plugs": {
"desktop": {"mount-host-font-cache": False},
"icon-themes": {
"interface": "content",
"target": "$SNAP/data-dir/icons",
"default-provider": "gtk-common-themes",
},
"sound-themes": {
"interface": "content",
"target": "$SNAP/data-dir/sounds",
"default-provider": "gtk-common-themes",
},
platform_snap: {
"content": content_snap,
"interface": "content",
"default-provider": platform_snap,
"target": "$SNAP/kf5",
},
},
"environment": {"SNAP_DESKTOP_RUNTIME": "$SNAP/kf5"},
"hooks": {
"configure": {
"plugs": ["desktop"],
"command-chain": ["snap/command-chain/hooks-configure-desktop"],
}
},
"layout": {"/usr/share/X11": {"symlink": "$SNAP/kf5/usr/share/X11"}},
}
@overrides
def get_part_snippet(self) -> Dict[str, Any]:
sdk_snap = self.kde_snaps.sdk
cmake_args = self.ext_info.cmake_args

return {
"build-environment": [
{
"PATH": prepend_to_env(
"PATH", [f"/snap/{sdk_snap}/current/usr/bin"]
),
},
{
"XDG_DATA_DIRS": prepend_to_env(
"XDG_DATA_DIRS",
[
f"$SNAPCRAFT_STAGE/usr/share:/snap/{sdk_snap}/current/usr/share",
"/usr/share",
],
),
},
{
"LD_LIBRARY_PATH": prepend_to_env(
"LD_LIBRARY_PATH",
[
f"/snap/{sdk_snap}/current/lib/$CRAFT_ARCH_TRIPLET",
f"/snap/{sdk_snap}/current/usr/lib/$CRAFT_ARCH_TRIPLET",
f"/snap/{sdk_snap}/current/usr/lib",
f"/snap/{sdk_snap}/current/usr/lib/vala-current",
f"/snap/{sdk_snap}/current/usr/lib/$CRAFT_ARCH_TRIPLET/pulseaudio",
],
),
},
{
"PKG_CONFIG_PATH": prepend_to_env(
"PKG_CONFIG_PATH",
[
f"/snap/{sdk_snap}/current/usr/lib/$CRAFT_ARCH_TRIPLET/pkgconfig",
f"/snap/{sdk_snap}/current/usr/lib/pkgconfig",
f"/snap/{sdk_snap}/current/usr/share/pkgconfig",
],
),
},
{
"GETTEXTDATADIRS": prepend_to_env(
"GETTEXTDATADIRS",
[
f"/snap/{sdk_snap}/current/usr/share/gettext-current",
],
),
},
{
"ACLOCAL_PATH": prepend_to_env(
"ACLOCAL_PATH",
[
f"/snap/{sdk_snap}/current/usr/share/aclocal",
],
),
},
{
"PYTHONPATH": prepend_to_env(
"PYTHONPATH",
[
f"/snap/{sdk_snap}/current/usr/lib/python3.10",
f"/snap/{sdk_snap}/current/usr/lib/python3/dist-packages",
f"/snap/{sdk_snap}/current/usr/lib/$CRAFT_ARCH_TRIPLET"
"/gobject-introspection",
],
),
},
{
if cmake_args is not None:
"SNAPCRAFT_CMAKE_ARGS": prepend_to_env(
"SNAPCRAFT_CMAKE_ARGS",
[
f"{cmake_args}",
],
),
},
],
}

@overrides
def get_parts_snippet(self) -> Dict[str, Any]:
source = get_extensions_data_dir() / "desktop" / "command-chain"

if self.kde_snaps.builtin:
base = self.yaml_data["base"]
sdk_snap = _SDK_SNAP[base]
provider = self.kde_snaps.content + f"-all"
return {
"kde-neon-extension": {
"source": str(source),
"source-subdir": "kde-neon"
"plugin": "make",
"make-parameters": [f"PLATFORM_PLUG={provider}"],
"build-packages": ["g++"],
"build-snaps": [sdk_snap],
}
}

return {
"kde-neon-extension": {
"source": str(source),
"plugin": "make",
}
}
2 changes: 2 additions & 0 deletions snapcraft/extensions/registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

from .gnome import GNOME
from .ros2_humble import ROS2HumbleExtension
from .kde_neon import KDENeon

if TYPE_CHECKING:
from .extension import Extension
Expand All @@ -31,6 +32,7 @@
_EXTENSIONS: Dict[str, "ExtensionType"] = {
"gnome": GNOME,
"ros2-humble": ROS2HumbleExtension,
"kde-neon": KDENeon,
}


Expand Down
11 changes: 8 additions & 3 deletions tests/spread/extensions/kde-neon/task.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ summary: Build and run a basic kde snap using extensions
# available on a subset of all the architectures this testbed
# can run on.
systems:
- ubuntu-18.04
- ubuntu-18.04-64
- ubuntu-18.04-amd64
- ubuntu-20.04
- ubuntu-20.04-64
- ubuntu-20.04-amd64
- ubuntu-22.04
- ubunut-22.04-64
ScarlettGatelyMoore marked this conversation as resolved.
Show resolved Hide resolved
- ubuntu-22.04-amd64

environment:
SNAP_DIR: ../snaps/neon-hello
Expand Down Expand Up @@ -37,6 +37,7 @@ execute: |
cd "$SNAP_DIR"
output="$(snapcraft)"
snap install neon-hello_*.snap --dangerous
snap connect neon-hello:kde-frameworks-5-102-qt-5-15-8-core22 kde-frameworks-5-102-qt-5-15-8-core22

[ "$(neon-hello)" = "hello world" ]

Expand All @@ -47,6 +48,10 @@ execute: |
[ -f "$snap_user_data/.last_revision" ]
[ "$(cat "$snap_user_data/.last_revision")" = "SNAP_DESKTOP_LAST_REVISION=x1" ]

# Verify content snap was installed for dependency checks.
snap list kde-frameworks-5-102-qt-5-15-8-core22
snap list gtk-common-themes

# Verify all dependencies were found.
if echo "$output" | grep -q "part is missing libraries"; then
echo "failed to find content snaps' libraries"
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/commands/test_list_extensions.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def test_command(emitter, command):
gnome-3-28 core18
gnome-3-34 core18
gnome-3-38 core20
kde-neon core18, core20
kde-neon core18, core20, core22
ros1-noetic core20
ros2-foxy core20
ros2-humble core22"""
Expand All @@ -67,7 +67,7 @@ def test_command_extension_dups(emitter, command):
gnome-3-28 core18
gnome-3-34 core18
gnome-3-38 core20
kde-neon core18, core20
kde-neon core18, core20, core22
ros1-noetic core20
ros2-foxy core20
ros2-humble core22"""
Expand Down
Loading