[gnome-builder] plugins/flatpak: implement IdeSdkProvider
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder] plugins/flatpak: implement IdeSdkProvider
- Date: Tue, 23 Aug 2022 01:06:03 +0000 (UTC)
commit 46d5f2f44021cde713c3e5b4323143c08c986592
Author: Christian Hergert <chergert redhat com>
Date: Mon Aug 22 18:00:16 2022 -0700
plugins/flatpak: implement IdeSdkProvider
This implements the SDK provider addin so that we can install runtimes
using the new tweaks addin in sdkui which will land next.
src/plugins/flatpak/flatpak-plugin.c | 14 +-
src/plugins/flatpak/gbp-flatpak-sdk-provider.c | 291 +++++++++++++++++++++++++
src/plugins/flatpak/gbp-flatpak-sdk-provider.h | 31 +++
src/plugins/flatpak/gbp-flatpak-sdk.c | 127 +++++++++++
src/plugins/flatpak/gbp-flatpak-sdk.h | 34 +++
src/plugins/flatpak/meson.build | 2 +
6 files changed, 494 insertions(+), 5 deletions(-)
---
diff --git a/src/plugins/flatpak/flatpak-plugin.c b/src/plugins/flatpak/flatpak-plugin.c
index ae76ebee5..e94e56e14 100644
--- a/src/plugins/flatpak/flatpak-plugin.c
+++ b/src/plugins/flatpak/flatpak-plugin.c
@@ -35,6 +35,7 @@
#include "gbp-flatpak-pipeline-addin.h"
#include "gbp-flatpak-run-command-provider.h"
#include "gbp-flatpak-runtime-provider.h"
+#include "gbp-flatpak-sdk-provider.h"
#include "gbp-flatpak-workbench-addin.h"
_IDE_EXTERN void
@@ -45,21 +46,24 @@ _gbp_flatpak_register_types (PeasObjectModule *module)
peas_object_module_register_extension_type (module,
IDE_TYPE_BUILD_SYSTEM_DISCOVERY,
GBP_TYPE_FLATPAK_BUILD_SYSTEM_DISCOVERY);
- peas_object_module_register_extension_type (module,
- IDE_TYPE_RUN_COMMAND_PROVIDER,
- GBP_TYPE_FLATPAK_RUN_COMMAND_PROVIDER);
peas_object_module_register_extension_type (module,
IDE_TYPE_CONFIG_PROVIDER,
GBP_TYPE_FLATPAK_CONFIG_PROVIDER);
peas_object_module_register_extension_type (module,
IDE_TYPE_DEPENDENCY_UPDATER,
GBP_TYPE_FLATPAK_DEPENDENCY_UPDATER);
+ peas_object_module_register_extension_type (module,
+ IDE_TYPE_PIPELINE_ADDIN,
+ GBP_TYPE_FLATPAK_PIPELINE_ADDIN);
+ peas_object_module_register_extension_type (module,
+ IDE_TYPE_RUN_COMMAND_PROVIDER,
+ GBP_TYPE_FLATPAK_RUN_COMMAND_PROVIDER);
peas_object_module_register_extension_type (module,
IDE_TYPE_RUNTIME_PROVIDER,
GBP_TYPE_FLATPAK_RUNTIME_PROVIDER);
peas_object_module_register_extension_type (module,
- IDE_TYPE_PIPELINE_ADDIN,
- GBP_TYPE_FLATPAK_PIPELINE_ADDIN);
+ IDE_TYPE_SDK_PROVIDER,
+ GBP_TYPE_FLATPAK_SDK_PROVIDER);
peas_object_module_register_extension_type (module,
IDE_TYPE_WORKBENCH_ADDIN,
GBP_TYPE_FLATPAK_WORKBENCH_ADDIN);
diff --git a/src/plugins/flatpak/gbp-flatpak-sdk-provider.c b/src/plugins/flatpak/gbp-flatpak-sdk-provider.c
new file mode 100644
index 000000000..ee20b3542
--- /dev/null
+++ b/src/plugins/flatpak/gbp-flatpak-sdk-provider.c
@@ -0,0 +1,291 @@
+/* gbp-flatpak-sdk-provider.c
+ *
+ * Copyright 2022 Christian Hergert <chergert redhat com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * 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/>.
+ *
+ * SPDX-License-Identifier: GPL-3.0-or-later
+ */
+
+#define G_LOG_DOMAIN "gbp-flatpak-sdk-provider"
+
+#include "config.h"
+
+#include <libide-gui.h>
+#include <libide-threading.h>
+
+#include "gbp-flatpak-client.h"
+#include "gbp-flatpak-sdk.h"
+#include "gbp-flatpak-sdk-provider.h"
+
+#include "ipc-flatpak-service.h"
+#include "ipc-flatpak-transfer-impl.h"
+
+struct _GbpFlatpakSdkProvider
+{
+ IdeSdkProvider parent_instance;
+};
+
+G_DEFINE_FINAL_TYPE (GbpFlatpakSdkProvider, gbp_flatpak_sdk_provider, IDE_TYPE_SDK_PROVIDER)
+
+static void
+gbp_flatpak_sdk_provider_runtime_added_cb (GbpFlatpakSdkProvider *self,
+ GVariant *runtime_variant,
+ IpcFlatpakService *service)
+{
+ g_autoptr(GbpFlatpakSdk) sdk = NULL;
+
+ IDE_ENTRY;
+
+ g_assert (GBP_IS_FLATPAK_SDK_PROVIDER (self));
+ g_assert (runtime_variant != NULL);
+ g_assert (IPC_IS_FLATPAK_SERVICE (service));
+
+ if ((sdk = gbp_flatpak_sdk_new_from_variant (runtime_variant)))
+ ide_sdk_provider_sdk_added (IDE_SDK_PROVIDER (self), IDE_SDK (sdk));
+
+ IDE_EXIT;
+}
+
+static void
+gbp_flatpak_sdk_provider_list_runtimes_cb (GObject *object,
+ GAsyncResult *result,
+ gpointer user_data)
+{
+ IpcFlatpakService *service = (IpcFlatpakService *)object;
+ g_autoptr(GbpFlatpakSdkProvider) self = user_data;
+ g_autoptr(GVariant) runtimes = NULL;
+ g_autoptr(GError) error = NULL;
+ guint n_children;
+
+ IDE_ENTRY;
+
+ g_assert (IDE_IS_MAIN_THREAD ());
+ g_assert (GBP_IS_FLATPAK_SDK_PROVIDER (self));
+ g_assert (G_IS_ASYNC_RESULT (result));
+ g_assert (IPC_IS_FLATPAK_SERVICE (service));
+
+ if (!ipc_flatpak_service_call_list_runtimes_finish (service, &runtimes, result, &error))
+ {
+ g_warning ("Failed to list flatpak runtimes: %s", error->message);
+ IDE_EXIT;
+ }
+
+ n_children = g_variant_n_children (runtimes);
+
+ for (guint i = 0; i < n_children; i++)
+ {
+ g_autoptr(GVariant) runtime = g_variant_get_child_value (runtimes, i);
+ gbp_flatpak_sdk_provider_runtime_added_cb (self, runtime, service);
+ }
+
+ IDE_EXIT;
+}
+
+static void
+gbp_flatpak_sdk_provider_get_service_cb (GObject *object,
+ GAsyncResult *result,
+ gpointer user_data)
+{
+ GbpFlatpakClient *client = (GbpFlatpakClient *)object;
+ g_autoptr(GbpFlatpakSdkProvider) self = user_data;
+ g_autoptr(IpcFlatpakService) service = NULL;
+ g_autoptr(GError) error = NULL;
+
+ IDE_ENTRY;
+
+ g_assert (IDE_IS_MAIN_THREAD ());
+ g_assert (GBP_IS_FLATPAK_CLIENT (client));
+ g_assert (G_IS_ASYNC_RESULT (result));
+ g_assert (GBP_IS_FLATPAK_SDK_PROVIDER (self));
+
+ if (!(service = gbp_flatpak_client_get_service_finish (client, result, &error)))
+ {
+ g_warning ("Failed to access gnome-builder-flatpak, cannot integrate SDK management.");
+ IDE_EXIT;
+ }
+
+ g_assert (IPC_IS_FLATPAK_SERVICE (service));
+
+ g_signal_connect_object (service,
+ "runtime-added",
+ G_CALLBACK (gbp_flatpak_sdk_provider_runtime_added_cb),
+ self,
+ G_CONNECT_SWAPPED);
+
+ ipc_flatpak_service_call_list_runtimes (service,
+ NULL,
+ gbp_flatpak_sdk_provider_list_runtimes_cb,
+ g_object_ref (self));
+
+ IDE_EXIT;
+}
+
+static void
+gbp_flatpak_sdk_provider_update_cb (GObject *object,
+ GAsyncResult *result,
+ gpointer user_data)
+{
+ IpcFlatpakService *service = (IpcFlatpakService *)object;
+ g_autoptr(IdeTask) task = user_data;
+ g_autoptr(GError) error = NULL;
+
+ IDE_ENTRY;
+
+ g_assert (IDE_IS_MAIN_THREAD ());
+ g_assert (IPC_IS_FLATPAK_SERVICE (service));
+ g_assert (G_IS_ASYNC_RESULT (result));
+ g_assert (IDE_IS_TASK (task));
+
+ if (!ipc_flatpak_service_call_install_finish (service, result, &error))
+ ide_task_return_error (task, g_steal_pointer (&error));
+ else
+ ide_task_return_boolean (task, TRUE);
+
+ IDE_EXIT;
+}
+
+static void
+gbp_flatpak_sdk_provider_update_async (IdeSdkProvider *provider,
+ IdeSdk *sdk,
+ IdeNotification *notif,
+ GCancellable *cancellable,
+ GAsyncReadyCallback callback,
+ gpointer user_data)
+{
+ GbpFlatpakSdkProvider *self = (GbpFlatpakSdkProvider *)provider;
+ g_autoptr(IpcFlatpakService) service = NULL;
+ g_autoptr(IpcFlatpakTransfer) transfer = NULL;
+ g_autoptr(IdeTask) task = NULL;
+ g_autoptr(GError) error = NULL;
+ g_autofree char *guid = NULL;
+ g_autofree char *transfer_path = NULL;
+ GbpFlatpakClient *client;
+ const char * refs[2] = { NULL };
+ GtkWindow *window;
+
+ IDE_ENTRY;
+
+ g_assert (GBP_IS_FLATPAK_SDK_PROVIDER (self));
+ g_assert (GBP_IS_FLATPAK_SDK (sdk));
+ g_assert (IDE_IS_NOTIFICATION (notif));
+ g_assert (!cancellable || G_IS_CANCELLABLE (cancellable));
+
+ client = gbp_flatpak_client_get_default ();
+ window = gtk_application_get_active_window (GTK_APPLICATION (IDE_APPLICATION_DEFAULT));
+
+ task = ide_task_new (self, cancellable, callback, user_data);
+ ide_task_set_source_tag (task, gbp_flatpak_sdk_provider_update_async);
+
+ if (!(service = gbp_flatpak_client_get_service (client, cancellable, &error)))
+ {
+ ide_task_return_error (task, g_steal_pointer (&error));
+ IDE_EXIT;
+ }
+
+ refs[0] = gbp_flatpak_sdk_get_id (GBP_FLATPAK_SDK (sdk));
+
+ guid = g_dbus_generate_guid ();
+ transfer_path = g_strdup_printf ("/org/gnome/Builder/Flatpak/Transfer/%s", guid);
+ transfer = ipc_flatpak_transfer_impl_new_simple (window);
+ if (cancellable != NULL)
+ g_signal_connect_object (cancellable,
+ "cancelled",
+ G_CALLBACK (ipc_flatpak_transfer_emit_cancel),
+ transfer,
+ G_CONNECT_SWAPPED);
+ g_dbus_interface_skeleton_export (G_DBUS_INTERFACE_SKELETON (transfer),
+ g_dbus_proxy_get_connection (G_DBUS_PROXY (service)),
+ transfer_path,
+ &error);
+
+ if (error != NULL)
+ {
+ ide_task_return_error (task, g_steal_pointer (&error));
+ IDE_EXIT;
+ }
+
+ g_object_bind_property (transfer, "fraction", notif, "progress", G_BINDING_SYNC_CREATE);
+ g_object_bind_property (transfer, "message", notif, "body", G_BINDING_DEFAULT);
+ ide_task_set_task_data (task, g_object_ref (transfer), g_object_unref);
+
+ ipc_flatpak_service_call_install (service,
+ refs,
+ FALSE,
+ transfer_path,
+ "",
+ cancellable,
+ gbp_flatpak_sdk_provider_update_cb,
+ g_steal_pointer (&task));
+
+ IDE_EXIT;
+}
+
+static gboolean
+gbp_flatpak_sdk_provider_update_finish (IdeSdkProvider *provider,
+ GAsyncResult *result,
+ GError **error)
+{
+ GError *local_error = NULL;
+ gboolean ret;
+
+ IDE_ENTRY;
+
+ g_assert (IDE_IS_SDK_PROVIDER (provider));
+ g_assert (IDE_IS_TASK (result));
+
+ if (!(ret = ide_task_propagate_boolean (IDE_TASK (result), &local_error)))
+ {
+ g_warning ("Failed to update SDK: %s", local_error->message);
+ g_propagate_error (error, local_error);
+ }
+
+ IDE_RETURN (ret);
+}
+
+static void
+gbp_flatpak_sdk_provider_constructed (GObject *object)
+{
+ GbpFlatpakSdkProvider *self = (GbpFlatpakSdkProvider *)object;
+ GbpFlatpakClient *client;
+
+ IDE_ENTRY;
+
+ G_OBJECT_CLASS (gbp_flatpak_sdk_provider_parent_class)->constructed (object);
+
+ client = gbp_flatpak_client_get_default ();
+ gbp_flatpak_client_get_service_async (client,
+ NULL,
+ gbp_flatpak_sdk_provider_get_service_cb,
+ g_object_ref (self));
+
+ IDE_EXIT;
+}
+
+static void
+gbp_flatpak_sdk_provider_class_init (GbpFlatpakSdkProviderClass *klass)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+ IdeSdkProviderClass *sdk_provider_class = IDE_SDK_PROVIDER_CLASS (klass);
+
+ object_class->constructed = gbp_flatpak_sdk_provider_constructed;
+
+ sdk_provider_class->update_async = gbp_flatpak_sdk_provider_update_async;
+ sdk_provider_class->update_finish = gbp_flatpak_sdk_provider_update_finish;
+}
+
+static void
+gbp_flatpak_sdk_provider_init (GbpFlatpakSdkProvider *self)
+{
+}
diff --git a/src/plugins/flatpak/gbp-flatpak-sdk-provider.h b/src/plugins/flatpak/gbp-flatpak-sdk-provider.h
new file mode 100644
index 000000000..ff9628b6d
--- /dev/null
+++ b/src/plugins/flatpak/gbp-flatpak-sdk-provider.h
@@ -0,0 +1,31 @@
+/* gbp-flatpak-sdk-provider.h
+ *
+ * Copyright 2022 Christian Hergert <chergert redhat com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * 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/>.
+ *
+ * SPDX-License-Identifier: GPL-3.0-or-later
+ */
+
+#pragma once
+
+#include <libide-foundry.h>
+
+G_BEGIN_DECLS
+
+#define GBP_TYPE_FLATPAK_SDK_PROVIDER (gbp_flatpak_sdk_provider_get_type())
+
+G_DECLARE_FINAL_TYPE (GbpFlatpakSdkProvider, gbp_flatpak_sdk_provider, GBP, FLATPAK_SDK_PROVIDER,
IdeSdkProvider)
+
+G_END_DECLS
diff --git a/src/plugins/flatpak/gbp-flatpak-sdk.c b/src/plugins/flatpak/gbp-flatpak-sdk.c
new file mode 100644
index 000000000..5e5c84508
--- /dev/null
+++ b/src/plugins/flatpak/gbp-flatpak-sdk.c
@@ -0,0 +1,127 @@
+/* gbp-flatpak-sdk.c
+ *
+ * Copyright 2022 Christian Hergert <chergert redhat com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * 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/>.
+ *
+ * SPDX-License-Identifier: GPL-3.0-or-later
+ */
+
+#define G_LOG_DOMAIN "gbp-flatpak-sdk"
+
+#include "config.h"
+
+#include "gbp-flatpak-sdk.h"
+
+struct _GbpFlatpakSdk
+{
+ IdeSdk parent_instance;
+ char *id;
+ char *name;
+ char *arch;
+ char *branch;
+ char *sdk_name;
+ char *sdk_branch;
+ char *deploy_dir;
+ char *metadata;
+ guint is_sdk_extension : 1;
+};
+
+G_DEFINE_FINAL_TYPE (GbpFlatpakSdk, gbp_flatpak_sdk, IDE_TYPE_SDK)
+
+static void
+gbp_flatpak_sdk_dispose (GObject *object)
+{
+ GbpFlatpakSdk *self = (GbpFlatpakSdk *)object;
+
+ g_clear_pointer (&self->id, g_free);
+ g_clear_pointer (&self->name, g_free);
+ g_clear_pointer (&self->arch, g_free);
+ g_clear_pointer (&self->branch, g_free);
+ g_clear_pointer (&self->sdk_name, g_free);
+ g_clear_pointer (&self->sdk_branch, g_free);
+ g_clear_pointer (&self->deploy_dir, g_free);
+ g_clear_pointer (&self->metadata, g_free);
+
+ G_OBJECT_CLASS (gbp_flatpak_sdk_parent_class)->dispose (object);
+}
+
+static void
+gbp_flatpak_sdk_class_init (GbpFlatpakSdkClass *klass)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+ object_class->dispose = gbp_flatpak_sdk_dispose;
+}
+
+static void
+gbp_flatpak_sdk_init (GbpFlatpakSdk *self)
+{
+}
+
+GbpFlatpakSdk *
+gbp_flatpak_sdk_new_from_variant (GVariant *variant)
+{
+ GbpFlatpakSdk *ret;
+ g_autofree char *name = NULL;
+ g_autofree char *arch = NULL;
+ g_autofree char *branch = NULL;
+ g_autofree char *sdk_name = NULL;
+ g_autofree char *sdk_branch = NULL;
+ g_autofree char *deploy_dir = NULL;
+ g_autofree char *metadata = NULL;
+ g_autofree char *title = NULL;
+ gboolean is_sdk_extension = FALSE;
+
+ g_return_val_if_fail (variant != NULL, NULL);
+ g_return_val_if_fail (g_variant_is_of_type (variant, G_VARIANT_TYPE ("(sssssssb)")), NULL);
+
+ g_variant_get (variant,
+ "(sssssssb)",
+ &name,
+ &arch,
+ &branch,
+ &sdk_name,
+ &sdk_branch,
+ &deploy_dir,
+ &metadata,
+ &is_sdk_extension);
+
+ title = g_strdup_printf ("%s/%s/%s", name, arch, branch);
+
+ ret = g_object_new (GBP_TYPE_FLATPAK_SDK,
+ "title", title,
+ "can-update", TRUE,
+ NULL);
+
+ ret->id = g_strdup_printf ("runtime/%s/%s/%s", name, arch, branch);
+ ret->name = g_steal_pointer (&name);
+ ret->arch = g_steal_pointer (&arch);
+ ret->branch = g_steal_pointer (&branch);
+ ret->sdk_name = g_steal_pointer (&sdk_name);
+ ret->sdk_branch = g_steal_pointer (&sdk_branch);
+ ret->deploy_dir = g_steal_pointer (&deploy_dir);
+ ret->metadata = g_steal_pointer (&metadata);
+ ret->is_sdk_extension = !!is_sdk_extension;
+
+ return ret;
+}
+
+const char *
+gbp_flatpak_sdk_get_id (GbpFlatpakSdk *self)
+{
+ g_return_val_if_fail (GBP_IS_FLATPAK_SDK (self), NULL);
+
+ return self->id;
+}
diff --git a/src/plugins/flatpak/gbp-flatpak-sdk.h b/src/plugins/flatpak/gbp-flatpak-sdk.h
new file mode 100644
index 000000000..5550095c9
--- /dev/null
+++ b/src/plugins/flatpak/gbp-flatpak-sdk.h
@@ -0,0 +1,34 @@
+/* gbp-flatpak-sdk.h
+ *
+ * Copyright 2022 Christian Hergert <chergert redhat com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * 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/>.
+ *
+ * SPDX-License-Identifier: GPL-3.0-or-later
+ */
+
+#pragma once
+
+#include <libide-foundry.h>
+
+G_BEGIN_DECLS
+
+#define GBP_TYPE_FLATPAK_SDK (gbp_flatpak_sdk_get_type())
+
+G_DECLARE_FINAL_TYPE (GbpFlatpakSdk, gbp_flatpak_sdk, GBP, FLATPAK_SDK, IdeSdk)
+
+GbpFlatpakSdk *gbp_flatpak_sdk_new_from_variant (GVariant *variant);
+const char *gbp_flatpak_sdk_get_id (GbpFlatpakSdk *self);
+
+G_END_DECLS
diff --git a/src/plugins/flatpak/meson.build b/src/plugins/flatpak/meson.build
index 88705eeec..436d7ade4 100644
--- a/src/plugins/flatpak/meson.build
+++ b/src/plugins/flatpak/meson.build
@@ -27,6 +27,8 @@ plugins_sources += files([
'gbp-flatpak-run-command-provider.c',
'gbp-flatpak-runtime-provider.c',
'gbp-flatpak-runtime.c',
+ 'gbp-flatpak-sdk.c',
+ 'gbp-flatpak-sdk-provider.c',
'gbp-flatpak-sdk-stage.c',
'gbp-flatpak-sources.c',
'gbp-flatpak-util.c',
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]