[gnome-builder] flatpak: use dependency updater interface
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder] flatpak: use dependency updater interface
- Date: Sun, 17 Dec 2017 01:58:06 +0000 (UTC)
commit 38e09f2da2766e07dccff3661ef7d01c7f102bfe
Author: Christian Hergert <chergert redhat com>
Date: Sat Dec 16 17:56:21 2017 -0800
flatpak: use dependency updater interface
Instead of the one-off for updating dependencies in flatpak, we
can now use the abstracted interface.
.../flatpak/gbp-flatpak-dependency-updater.c | 150 ++++++++++++++++++++
.../flatpak/gbp-flatpak-dependency-updater.h | 29 ++++
src/plugins/flatpak/gbp-flatpak-plugin.c | 4 +
src/plugins/flatpak/gbp-flatpak-workbench-addin.c | 46 ------
src/plugins/flatpak/meson.build | 2 +
5 files changed, 185 insertions(+), 46 deletions(-)
---
diff --git a/src/plugins/flatpak/gbp-flatpak-dependency-updater.c
b/src/plugins/flatpak/gbp-flatpak-dependency-updater.c
new file mode 100644
index 0000000..6e40621
--- /dev/null
+++ b/src/plugins/flatpak/gbp-flatpak-dependency-updater.c
@@ -0,0 +1,150 @@
+/* gbp-flatpak-dependency-updater.c
+ *
+ * Copyright (C) 2017 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/>.
+ */
+
+#define G_LOG_DOMAIN "gbp-flatpak-dependency-updater"
+
+#include "gbp-flatpak-dependency-updater.h"
+#include "gbp-flatpak-download-stage.h"
+
+struct _GbpFlatpakDependencyUpdater
+{
+ IdeObject parent_instance;
+};
+
+static void
+find_download_stage_cb (gpointer data,
+ gpointer user_data)
+{
+ GbpFlatpakDownloadStage **stage = user_data;
+
+ g_assert (IDE_IS_BUILD_STAGE (data));
+ g_assert (stage != NULL);
+
+ if (GBP_IS_FLATPAK_DOWNLOAD_STAGE (data))
+ *stage = data;
+}
+
+static void
+gbp_flatpak_dependency_updater_update_cb (GObject *object,
+ GAsyncResult *result,
+ gpointer user_data)
+{
+ IdeBuildManager *manager = (IdeBuildManager *)object;
+ g_autoptr(GTask) task = user_data;
+ g_autoptr(GError) error = NULL;
+
+ g_assert (IDE_IS_BUILD_MANAGER (manager));
+ g_assert (G_IS_ASYNC_RESULT (result));
+ g_assert (G_IS_TASK (task));
+
+ if (!ide_build_manager_rebuild_finish (manager, result, &error))
+ g_task_return_error (task, g_steal_pointer (&error));
+ else
+ g_task_return_boolean (task, TRUE);
+}
+
+static void
+gbp_flatpak_dependency_updater_update_async (IdeDependencyUpdater *updater,
+ GCancellable *cancellable,
+ GAsyncReadyCallback callback,
+ gpointer user_data)
+{
+ GbpFlatpakDependencyUpdater *self = (GbpFlatpakDependencyUpdater *)updater;
+ GbpFlatpakDownloadStage *stage = NULL;
+ g_autoptr(GTask) task = NULL;
+ IdeBuildPipeline *pipeline;
+ IdeBuildManager *manager;
+ IdeContext *context;
+
+ g_assert (GBP_IS_FLATPAK_DEPENDENCY_UPDATER (self));
+ g_assert (!cancellable || G_IS_CANCELLABLE (cancellable));
+
+ task = g_task_new (self, cancellable, callback, user_data);
+ g_task_set_source_tag (task, gbp_flatpak_dependency_updater_update_async);
+ g_task_set_priority (task, G_PRIORITY_LOW);
+
+ context = ide_object_get_context (IDE_OBJECT (self));
+ g_assert (IDE_IS_CONTEXT (context));
+
+ manager = ide_context_get_build_manager (context);
+ g_assert (IDE_IS_BUILD_MANAGER (manager));
+
+ pipeline = ide_build_manager_get_pipeline (manager);
+ g_assert (!pipeline || IDE_IS_BUILD_PIPELINE (pipeline));
+
+ if (pipeline == NULL)
+ {
+ g_task_return_new_error (task,
+ G_IO_ERROR,
+ G_IO_ERROR_FAILED,
+ "Cannot update flatpak dependencies until build pipeline is initialized");
+ return;
+ }
+
+ /* Find the downloads stage and tell it to download updates one time */
+ ide_build_pipeline_foreach_stage (pipeline, find_download_stage_cb, &stage);
+ if (stage != NULL)
+ gbp_flatpak_download_stage_force_update (stage);
+
+ /* Ensure downloads and everything past it is invalidated */
+ ide_build_pipeline_invalidate_phase (pipeline, IDE_BUILD_PHASE_DOWNLOADS);
+
+ /* Start building all the way up to the project configure so that
+ * the user knows if the updates broke their configuration or anything.
+ */
+ ide_build_manager_rebuild_async (manager,
+ IDE_BUILD_PHASE_CONFIGURE,
+ NULL,
+ gbp_flatpak_dependency_updater_update_cb,
+ g_steal_pointer (&task));
+}
+
+static gboolean
+gbp_flatpak_dependency_updater_update_finish (IdeDependencyUpdater *updater,
+ GAsyncResult *result,
+ GError **error)
+{
+ g_assert (GBP_IS_FLATPAK_DEPENDENCY_UPDATER (updater));
+ g_assert (G_IS_TASK (result));
+ g_assert (g_task_is_valid (G_TASK (result), updater));
+
+ return g_task_propagate_boolean (G_TASK (result), error);
+}
+
+static void
+dependency_udpater_iface_init (IdeDependencyUpdaterInterface *iface)
+{
+ iface->update_async = gbp_flatpak_dependency_updater_update_async;
+ iface->update_finish = gbp_flatpak_dependency_updater_update_finish;
+}
+
+G_DEFINE_TYPE_WITH_CODE (GbpFlatpakDependencyUpdater,
+ gbp_flatpak_dependency_updater,
+ IDE_TYPE_OBJECT,
+ G_IMPLEMENT_INTERFACE (IDE_TYPE_DEPENDENCY_UPDATER,
+ dependency_udpater_iface_init))
+
+static void
+gbp_flatpak_dependency_updater_class_init (GbpFlatpakDependencyUpdaterClass *klass)
+{
+}
+
+static void
+gbp_flatpak_dependency_updater_init (GbpFlatpakDependencyUpdater *self)
+{
+}
diff --git a/src/plugins/flatpak/gbp-flatpak-dependency-updater.h
b/src/plugins/flatpak/gbp-flatpak-dependency-updater.h
new file mode 100644
index 0000000..1b03ef5
--- /dev/null
+++ b/src/plugins/flatpak/gbp-flatpak-dependency-updater.h
@@ -0,0 +1,29 @@
+/* gbp-flatpak-dependency-updater.h
+ *
+ * Copyright © 2017 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/>.
+ */
+
+#pragma once
+
+#include <ide.h>
+
+G_BEGIN_DECLS
+
+#define GBP_TYPE_FLATPAK_DEPENDENCY_UPDATER (gbp_flatpak_dependency_updater_get_type())
+
+G_DECLARE_FINAL_TYPE (GbpFlatpakDependencyUpdater, gbp_flatpak_dependency_updater, GBP,
FLATPAK_DEPENDENCY_UPDATER, IdeObject)
+
+G_END_DECLS
diff --git a/src/plugins/flatpak/gbp-flatpak-plugin.c b/src/plugins/flatpak/gbp-flatpak-plugin.c
index 06219fd..af61881 100644
--- a/src/plugins/flatpak/gbp-flatpak-plugin.c
+++ b/src/plugins/flatpak/gbp-flatpak-plugin.c
@@ -23,6 +23,7 @@
#include "gbp-flatpak-build-system-discovery.h"
#include "gbp-flatpak-build-target-provider.h"
#include "gbp-flatpak-configuration-provider.h"
+#include "gbp-flatpak-dependency-updater.h"
#include "gbp-flatpak-genesis-addin.h"
#include "gbp-flatpak-pipeline-addin.h"
#include "gbp-flatpak-preferences-addin.h"
@@ -44,6 +45,9 @@ gbp_flatpak_register_types (PeasObjectModule *module)
IDE_TYPE_CONFIGURATION_PROVIDER,
GBP_TYPE_FLATPAK_CONFIGURATION_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_RUNTIME_PROVIDER,
GBP_TYPE_FLATPAK_RUNTIME_PROVIDER);
peas_object_module_register_extension_type (module,
diff --git a/src/plugins/flatpak/gbp-flatpak-workbench-addin.c
b/src/plugins/flatpak/gbp-flatpak-workbench-addin.c
index 8002cc4..42a04c9 100644
--- a/src/plugins/flatpak/gbp-flatpak-workbench-addin.c
+++ b/src/plugins/flatpak/gbp-flatpak-workbench-addin.c
@@ -116,51 +116,6 @@ workbench_addin_iface_init (IdeWorkbenchAddinInterface *iface)
}
static void
-find_download_stage_cb (gpointer data,
- gpointer user_data)
-{
- GbpFlatpakDownloadStage **stage = user_data;
-
- g_assert (IDE_IS_BUILD_STAGE (data));
- g_assert (stage != NULL);
-
- if (GBP_IS_FLATPAK_DOWNLOAD_STAGE (data))
- *stage = data;
-}
-
-static void
-gbp_flatpak_workbench_addin_update_dependencies (GSimpleAction *action,
- GVariant *param,
- gpointer user_data)
-{
- GbpFlatpakWorkbenchAddin *self = user_data;
- GbpFlatpakDownloadStage *stage = NULL;
- IdeBuildPipeline *pipeline;
- IdeBuildManager *manager;
-
- g_assert (G_IS_SIMPLE_ACTION (action));
- g_assert (GBP_IS_FLATPAK_WORKBENCH_ADDIN (self));
-
- manager = ide_context_get_build_manager (ide_workbench_get_context (self->workbench));
- pipeline = ide_build_manager_get_pipeline (manager);
-
- /* Find the downloads stage and tell it to download updates one time */
- ide_build_pipeline_foreach_stage (pipeline, find_download_stage_cb, &stage);
- if (stage != NULL)
- gbp_flatpak_download_stage_force_update (stage);
-
- /* Ensure downloads and everything past it is invalidated */
- ide_build_pipeline_invalidate_phase (pipeline, IDE_BUILD_PHASE_DOWNLOADS);
-
- /* Start building all the way up to the project configure so that
- * the user knows if the updates broke their configuration or anything.
- */
- ide_build_manager_rebuild_async (manager,
- IDE_BUILD_PHASE_CONFIGURE,
- NULL, NULL, NULL);
-}
-
-static void
gbp_flatpak_workbench_addin_install_cb (GObject *object,
GAsyncResult *result,
gpointer user_data)
@@ -261,7 +216,6 @@ static void
gbp_flatpak_workbench_addin_init (GbpFlatpakWorkbenchAddin *self)
{
static const GActionEntry actions[] = {
- { "update-dependencies", gbp_flatpak_workbench_addin_update_dependencies },
{ "install-flatpak-builder", gbp_flatpak_workbench_addin_install_flatpak_builder },
};
diff --git a/src/plugins/flatpak/meson.build b/src/plugins/flatpak/meson.build
index a811b05..c8a6f4d 100644
--- a/src/plugins/flatpak/meson.build
+++ b/src/plugins/flatpak/meson.build
@@ -21,6 +21,8 @@ flatpak_sources = [
'gbp-flatpak-configuration.h',
'gbp-flatpak-configuration-provider.c',
'gbp-flatpak-configuration-provider.h',
+ 'gbp-flatpak-dependency-updater.c',
+ 'gbp-flatpak-dependency-updater.h',
'gbp-flatpak-download-stage.c',
'gbp-flatpak-download-stage.h',
'gbp-flatpak-genesis-addin.c',
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]