From a4c401f1f8aeb8dfc1e5ea31b57c2deebbe01441 Mon Sep 17 00:00:00 2001 From: Jarred Wilson Date: Fri, 15 Sep 2023 09:43:17 -0400 Subject: [PATCH] Convert qt extension to separate versioned extensions --- snapcraft/extensions/_utils.py | 2 +- snapcraft/extensions/extension.py | 3 ++- snapcraft/extensions/qt_framework.py | 23 +++++++++++------------ snapcraft/extensions/registry.py | 5 ++++- 4 files changed, 18 insertions(+), 15 deletions(-) diff --git a/snapcraft/extensions/_utils.py b/snapcraft/extensions/_utils.py index 3aa885be353..f9cbfca2063 100644 --- a/snapcraft/extensions/_utils.py +++ b/snapcraft/extensions/_utils.py @@ -59,7 +59,7 @@ def apply_extensions( for extension_name in sorted(declared_extensions.keys()): extension_class = get_extension_class(extension_name) extension = extension_class( - yaml_data=copy.deepcopy(yaml_data), arch=arch, target_arch=target_arch + name=extension_name, yaml_data=copy.deepcopy(yaml_data), arch=arch, target_arch=target_arch ) extension.validate(extension_name=extension_name) _apply_extension(yaml_data, declared_extensions[extension_name], extension) diff --git a/snapcraft/extensions/extension.py b/snapcraft/extensions/extension.py index 52cdfd902e1..6a2f5a54cb5 100644 --- a/snapcraft/extensions/extension.py +++ b/snapcraft/extensions/extension.py @@ -39,9 +39,10 @@ class Extension(abc.ABC): """ def __init__( - self, *, yaml_data: Dict[str, Any], arch: str, target_arch: str + self, *, name: str, yaml_data: Dict[str, Any], arch: str, target_arch: str ) -> None: """Create a new Extension.""" + self.name = name self.yaml_data = yaml_data self.arch = arch self.target_arch = target_arch diff --git a/snapcraft/extensions/qt_framework.py b/snapcraft/extensions/qt_framework.py index 99ffa4e9b80..d1e27df8056 100644 --- a/snapcraft/extensions/qt_framework.py +++ b/snapcraft/extensions/qt_framework.py @@ -25,6 +25,12 @@ _SDK_SNAP = {"core22": "qt-framework-sdk"} +_CONTENT_SNAP = { + "qt6-5": {"core22": "qt-framework-6-5-core22"}, + "qt6-4": {"core22": "qt-framework-6-4-core22"}, + "qt6-2": {"core22": "qt-framework-6-2-core22"}, + "qt5-15": {"core22": "qt-framework-5-15-core22"}, +} @dataclasses.dataclass class ExtensionInfo: @@ -86,7 +92,7 @@ def get_app_snippet(self) -> Dict[str, Any]: "command-chain": ["snap/command-chain/desktop-launch"], "plugs": ["desktop", "desktop-legacy", "opengl", "wayland", "x11"], "environment": { - "QT_PLUGIN_PATH": "$SNAP/qt-framework/opt/qt5-15/plugins:$SNAP/usr/lib/$SNAPCRAFT_ARCH_TRIPLET/qt5/plugins", + "QT_PLUGIN_PATH": "$SNAP/qt-framework/usr/plugins:$SNAP/usr/lib/plugins", }, } @@ -108,23 +114,16 @@ def qt_snaps(self) -> QTSnaps: break # The same except the trailing -sd - content = sdk_snap[:-4] + content = _CONTENT_SNAP[self.name][base] return QTSnaps(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.""" - prefix_root = f"/snap/{self.qt_snaps.sdk}/current/opt" - versions = ["qt6-5", "qt6-4", "qt6-2", "qt5-15"] - prefix_path = "-DCMAKE_PREFIX_PATH=" - - for version in versions: - prefix_path += f"{prefix_root}/{version}" - cmake_args = [ f"-DCMAKE_FIND_ROOT_PATH=/snap/{self.qt_snaps.sdk}/current", - prefix_path, + f"-DCMAKE_PREFIX_PATH=/snap/{self.qt_snaps.sdk}/current/usr" "-DZLIB_INCLUDE_DIR=/lib/x86_64-linux-gnu", ] @@ -203,7 +202,7 @@ def get_parts_snippet(self) -> Dict[str, Any]: if self.qt_snaps.builtin: return { - "qt-framework/sdk": { + f"{self.name}/sdk": { "source": str(source), "plugin": "make", "make-parameters": [f"PLATFORM_PLUG={self.qt_snaps.content}"], @@ -212,7 +211,7 @@ def get_parts_snippet(self) -> Dict[str, Any]: } return { - "qt-framework/sdk": { + f"{self.name}/sdk": { "source": str(source), "plugin": "make", "make-parameters": [f"PLATFORM_PLUG={self.qt_snaps.content}"], diff --git a/snapcraft/extensions/registry.py b/snapcraft/extensions/registry.py index 854eeac68b0..0a4690aa259 100644 --- a/snapcraft/extensions/registry.py +++ b/snapcraft/extensions/registry.py @@ -34,7 +34,10 @@ "gnome": GNOME, "ros2-humble": ROS2HumbleExtension, "kde-neon": KDENeon, - "qt-framework": QTFramework, + "qt6-5": None, + "qt6-4": None, + "qt6-2": None, + "qt5-15": QTFramework, }