[gnome-builder/wip/chergert/flatpak-repo] flatpak: add stage to install SDK runtimes



commit 1bebf0fb8d488ab82fddbb33b3d4c0fb3f464697
Author: Christian Hergert <chergert redhat com>
Date:   Tue Aug 24 21:42:14 2021 -0700

    flatpak: add stage to install SDK runtimes

 src/plugins/flatpak/gbp-flatpak-sdk-stage.c | 199 ++++++++++++++++++++++++++++
 src/plugins/flatpak/gbp-flatpak-sdk-stage.h |  33 +++++
 src/plugins/flatpak/meson.build             |   1 +
 3 files changed, 233 insertions(+)
---
diff --git a/src/plugins/flatpak/gbp-flatpak-sdk-stage.c b/src/plugins/flatpak/gbp-flatpak-sdk-stage.c
new file mode 100644
index 000000000..395001c72
--- /dev/null
+++ b/src/plugins/flatpak/gbp-flatpak-sdk-stage.c
@@ -0,0 +1,199 @@
+/* gbp-flatpak-sdk-stage.c
+ *
+ * Copyright 2021 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-stage"
+
+#include "config.h"
+
+#include <glib/gi18n.h>
+
+#include "gbp-flatpak-client.h"
+#include "gbp-flatpak-sdk-stage.h"
+#include "ipc-flatpak-service.h"
+#include "ipc-flatpak-transfer-impl.h"
+
+struct _GbpFlatpakSdkStage
+{
+  IdePipelineStage parent_instance;
+  char **sdks;
+};
+
+G_DEFINE_TYPE (GbpFlatpakSdkStage, gbp_flatpak_sdk_stage, IDE_TYPE_PIPELINE_STAGE)
+
+static void
+gbp_flatpak_sdk_stage_install_cb (GObject      *object,
+                                  GAsyncResult *result,
+                                  gpointer      user_data)
+{
+  IpcFlatpakService *service = (IpcFlatpakService *)object;
+  g_autoptr(IdeTask) task = user_data;
+  g_autoptr(GError) error = NULL;
+  GbpFlatpakSdkStage *self;
+
+  IDE_ENTRY;
+
+  g_assert (IPC_IS_FLATPAK_SERVICE (service));
+  g_assert (G_IS_ASYNC_RESULT (result));
+  g_assert (IDE_IS_TASK (task));
+
+  self = ide_task_get_source_object (task);
+
+  if (!ipc_flatpak_service_call_install_finish (service, result, &error))
+    ide_object_warning (IDE_OBJECT (self), _("Failed to update SDKs: %s"), error->message);
+
+  ide_pipeline_stage_set_active (IDE_PIPELINE_STAGE (self), FALSE);
+  ide_pipeline_stage_set_completed (IDE_PIPELINE_STAGE (self), TRUE);
+
+  ide_task_return_boolean (task, TRUE);
+
+  IDE_EXIT;
+}
+
+static void
+gbp_flatpak_sdk_stage_build_async (IdePipelineStage    *stage,
+                                   IdePipeline         *pipeline,
+                                   GCancellable        *cancellable,
+                                   GAsyncReadyCallback  callback,
+                                   gpointer             user_data)
+{
+  GbpFlatpakSdkStage *self = (GbpFlatpakSdkStage *)stage;
+  g_autofree char *guid = NULL;
+  g_autofree char *transfer_path = NULL;
+  g_autoptr(IdeTask) task = NULL;
+  g_autoptr(IpcFlatpakTransfer) transfer = NULL;
+  g_autoptr(GError) error = NULL;
+  IpcFlatpakService *service;
+  GbpFlatpakClient *client;
+  IdeContext *context;
+
+  IDE_ENTRY;
+
+  g_assert (GBP_IS_FLATPAK_SDK_STAGE (self));
+  g_assert (!cancellable || G_IS_CANCELLABLE (cancellable));
+  g_assert (IDE_IS_PIPELINE (pipeline));
+
+  task = ide_task_new (self, cancellable, callback, user_data);
+  ide_task_set_source_tag (task, gbp_flatpak_sdk_stage_build_async);
+
+  context = ide_object_get_context (IDE_OBJECT (pipeline));
+  client = gbp_flatpak_client_from_context (context);
+
+  if (!(service = gbp_flatpak_client_get_service (client, cancellable, &error)))
+    {
+      ide_task_return_error (task, g_steal_pointer (&error));
+      IDE_EXIT;
+    }
+
+  guid = g_dbus_generate_guid ();
+  transfer_path = g_strdup_printf ("/org/gnome/Builder/Flatpak/Transfer/%s", guid);
+
+  transfer = ipc_flatpak_transfer_impl_new (context);
+  g_signal_connect_object (ide_task_get_cancellable (task),
+                           "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;
+    }
+
+  ide_task_set_task_data (task, g_object_ref (transfer), g_object_unref);
+
+  ide_pipeline_stage_set_active (stage, TRUE);
+
+  ipc_flatpak_service_call_install (service,
+                                    (const char * const *)self->sdks,
+                                    transfer_path,
+                                    "",
+                                    ide_task_get_cancellable (task),
+                                    gbp_flatpak_sdk_stage_install_cb,
+                                    g_object_ref (task));
+
+  IDE_EXIT;
+}
+
+static gboolean
+gbp_flatpak_sdk_stage_build_finish (IdePipelineStage  *stage,
+                                    GAsyncResult      *result,
+                                    GError           **error)
+{
+  gboolean ret;
+
+  IDE_ENTRY;
+
+  g_assert (GBP_IS_FLATPAK_SDK_STAGE (stage));
+  g_assert (IDE_IS_TASK (result));
+
+  ret = ide_task_propagate_boolean (IDE_TASK (result), error);
+
+  IDE_RETURN (ret);
+}
+
+static void
+gbp_flatpak_sdk_stage_finalize (GObject *object)
+{
+  GbpFlatpakSdkStage *self = (GbpFlatpakSdkStage *)object;
+
+  g_clear_pointer (&self->sdks, g_strfreev);
+
+  G_OBJECT_CLASS (gbp_flatpak_sdk_stage_parent_class)->finalize (object);
+}
+
+static void
+gbp_flatpak_sdk_stage_class_init (GbpFlatpakSdkStageClass *klass)
+{
+  GObjectClass *object_class = G_OBJECT_CLASS (klass);
+  IdePipelineStageClass *stage_class = IDE_PIPELINE_STAGE_CLASS (klass);
+
+  stage_class->build_async = gbp_flatpak_sdk_stage_build_async;
+  stage_class->build_finish = gbp_flatpak_sdk_stage_build_finish;
+
+  object_class->finalize = gbp_flatpak_sdk_stage_finalize;
+}
+
+static void
+gbp_flatpak_sdk_stage_init (GbpFlatpakSdkStage *self)
+{
+}
+
+GbpFlatpakSdkStage *
+gbp_flatpak_sdk_stage_new (const char * const *sdks)
+{
+  GbpFlatpakSdkStage *self;
+  g_autofree char *name = NULL;
+
+  g_return_val_if_fail (sdks != NULL, NULL);
+  g_return_val_if_fail (sdks[0] != NULL, NULL);
+
+  self = g_object_new (GBP_TYPE_FLATPAK_SDK_STAGE,
+                       "name", _("Updating SDK Runtime"),
+                       "transient", TRUE,
+                       NULL);
+  self->sdks = g_strdupv ((char **)sdks);
+
+  return self;
+}
diff --git a/src/plugins/flatpak/gbp-flatpak-sdk-stage.h b/src/plugins/flatpak/gbp-flatpak-sdk-stage.h
new file mode 100644
index 000000000..1322b60f4
--- /dev/null
+++ b/src/plugins/flatpak/gbp-flatpak-sdk-stage.h
@@ -0,0 +1,33 @@
+/* gbp-flatpak-sdk-stage.h
+ *
+ * Copyright 2021 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_STAGE (gbp_flatpak_sdk_stage_get_type())
+
+G_DECLARE_FINAL_TYPE (GbpFlatpakSdkStage, gbp_flatpak_sdk_stage, GBP, FLATPAK_SDK_STAGE, IdePipelineStage)
+
+GbpFlatpakSdkStage *gbp_flatpak_sdk_stage_new (const char * const *sdks);
+
+G_END_DECLS
diff --git a/src/plugins/flatpak/meson.build b/src/plugins/flatpak/meson.build
index 4be33614d..7c819702f 100644
--- a/src/plugins/flatpak/meson.build
+++ b/src/plugins/flatpak/meson.build
@@ -29,6 +29,7 @@ plugins_sources += files([
   'gbp-flatpak-runner.c',
   'gbp-flatpak-runtime-provider.c',
   'gbp-flatpak-runtime.c',
+  'gbp-flatpak-sdk-stage.c',
   'gbp-flatpak-sources.c',
   'gbp-flatpak-subprocess-launcher.c',
   'gbp-flatpak-util.c',


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]