[gnome-builder] flatpak: new download stage for flatpak pipeline



commit b0cf72c1105e3fe27a406144eb8418afb5578c8e
Author: Christian Hergert <chergert redhat com>
Date:   Tue Nov 14 23:34:39 2017 -0800

    flatpak: new download stage for flatpak pipeline
    
    By breaking the download stage into a subclass, we can more
    easily support the avoidance of downloading dependencies as
    well as allowing the user to force update the dependencies.
    
    The workbench addin has been changed to mark the download stage
    as needing to be updated for downloads.

 src/plugins/flatpak/gbp-flatpak-download-stage.c  |  129 +++++++++++++++++++++
 src/plugins/flatpak/gbp-flatpak-download-stage.h  |   35 ++++++
 src/plugins/flatpak/gbp-flatpak-pipeline-addin.c  |   69 +-----------
 src/plugins/flatpak/gbp-flatpak-workbench-addin.c |   32 +++++-
 src/plugins/flatpak/meson.build                   |    2 +
 5 files changed, 199 insertions(+), 68 deletions(-)
---
diff --git a/src/plugins/flatpak/gbp-flatpak-download-stage.c 
b/src/plugins/flatpak/gbp-flatpak-download-stage.c
new file mode 100644
index 0000000..b078608
--- /dev/null
+++ b/src/plugins/flatpak/gbp-flatpak-download-stage.c
@@ -0,0 +1,129 @@
+/* gbp-flatpak-download-stage.c
+ *
+ * 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/>.
+ */
+
+#define G_LOG_DOMAIN "gbp-flatpak-download-stage"
+
+#include <glib/gi18n.h>
+
+#include "gbp-flatpak-configuration.h"
+#include "gbp-flatpak-download-stage.h"
+#include "gbp-flatpak-util.h"
+
+struct _GbpFlatpakDownloadStage
+{
+  IdeBuildStageLauncher parent_instance;
+
+  guint invalid : 1;
+  guint force_update : 1;
+};
+
+G_DEFINE_TYPE (GbpFlatpakDownloadStage, gbp_flatpak_download_stage, IDE_TYPE_BUILD_STAGE_LAUNCHER)
+
+static void
+gbp_flatpak_download_stage_query (IdeBuildStage    *stage,
+                                  IdeBuildPipeline *pipeline,
+                                  GCancellable     *cancellable)
+{
+  GbpFlatpakDownloadStage *self = (GbpFlatpakDownloadStage *)stage;
+  IdeConfiguration *config;
+  GNetworkMonitor *monitor;
+  g_autofree gchar *staging_dir = NULL;
+  g_autofree gchar *manifest_path = NULL;
+  g_autofree gchar *stop_at_option = NULL;
+  const gchar *src_dir;
+  const gchar *primary_module;
+
+  g_assert (GBP_IS_FLATPAK_DOWNLOAD_STAGE (self));
+  g_assert (IDE_IS_BUILD_PIPELINE (pipeline));
+  g_assert (!cancellable || G_IS_CANCELLABLE (cancellable));
+
+  config = ide_build_pipeline_get_configuration (pipeline);
+  if (!GBP_IS_FLATPAK_CONFIGURATION (config))
+    {
+      ide_build_stage_set_completed (stage, TRUE);
+      return;
+    }
+
+  if (self->invalid)
+    {
+      g_autoptr(IdeSubprocessLauncher) launcher = NULL;
+
+      primary_module = gbp_flatpak_configuration_get_primary_module (GBP_FLATPAK_CONFIGURATION (config));
+      manifest_path = gbp_flatpak_configuration_get_manifest_path (GBP_FLATPAK_CONFIGURATION (config));
+      staging_dir = gbp_flatpak_get_staging_dir (config);
+      src_dir = ide_build_pipeline_get_srcdir (pipeline);
+
+      launcher = ide_subprocess_launcher_new (G_SUBPROCESS_FLAGS_STDOUT_PIPE |
+                                              G_SUBPROCESS_FLAGS_STDERR_PIPE);
+
+      ide_subprocess_launcher_set_run_on_host (launcher, TRUE);
+      ide_subprocess_launcher_set_clear_env (launcher, FALSE);
+      ide_subprocess_launcher_set_cwd (launcher, src_dir);
+
+      ide_subprocess_launcher_push_argv (launcher, "flatpak-builder");
+      ide_subprocess_launcher_push_argv (launcher, "--ccache");
+      ide_subprocess_launcher_push_argv (launcher, "--force-clean");
+      ide_subprocess_launcher_push_argv (launcher, "--download-only");
+      if (!self->force_update)
+        ide_subprocess_launcher_push_argv (launcher, "--disable-updates");
+      stop_at_option = g_strdup_printf ("--stop-at=%s", primary_module);
+      ide_subprocess_launcher_push_argv (launcher, stop_at_option);
+      ide_subprocess_launcher_push_argv (launcher, staging_dir);
+      ide_subprocess_launcher_push_argv (launcher, manifest_path);
+
+      ide_build_stage_launcher_set_launcher (IDE_BUILD_STAGE_LAUNCHER (self), launcher);
+      ide_build_stage_set_completed (stage, FALSE);
+
+      self->invalid = FALSE;
+      self->force_update = FALSE;
+    }
+
+  /* Ignore downloads if there is no connection */
+  monitor = g_network_monitor_get_default ();
+  if (!g_network_monitor_get_network_available (monitor))
+    {
+      ide_build_stage_log (stage,
+                           IDE_BUILD_LOG_STDOUT,
+                           _("Network is not available, skipping downloads"),
+                           -1);
+      ide_build_stage_set_completed (stage, TRUE);
+    }
+}
+
+static void
+gbp_flatpak_download_stage_class_init (GbpFlatpakDownloadStageClass *klass)
+{
+  IdeBuildStageClass *stage_class = IDE_BUILD_STAGE_CLASS (klass);
+
+  stage_class->query = gbp_flatpak_download_stage_query;
+}
+
+static void
+gbp_flatpak_download_stage_init (GbpFlatpakDownloadStage *self)
+{
+  self->invalid = TRUE;
+}
+
+void
+gbp_flatpak_download_stage_force_update (GbpFlatpakDownloadStage *self)
+{
+  g_return_if_fail (GBP_IS_FLATPAK_DOWNLOAD_STAGE (self));
+
+  self->force_update = TRUE;
+  self->invalid = TRUE;
+}
diff --git a/src/plugins/flatpak/gbp-flatpak-download-stage.h 
b/src/plugins/flatpak/gbp-flatpak-download-stage.h
new file mode 100644
index 0000000..e95f455
--- /dev/null
+++ b/src/plugins/flatpak/gbp-flatpak-download-stage.h
@@ -0,0 +1,35 @@
+/* gbp-flatpak-download-stage.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_DOWNLOAD_STAGE (gbp_flatpak_download_stage_get_type())
+
+G_DECLARE_FINAL_TYPE (GbpFlatpakDownloadStage,
+                      gbp_flatpak_download_stage,
+                      GBP,
+                      FLATPAK_DOWNLOAD_STAGE,
+                      IdeBuildStageLauncher)
+
+void gbp_flatpak_download_stage_force_update (GbpFlatpakDownloadStage *self);
+
+G_END_DECLS
diff --git a/src/plugins/flatpak/gbp-flatpak-pipeline-addin.c 
b/src/plugins/flatpak/gbp-flatpak-pipeline-addin.c
index 8ea35b9..9e65744 100644
--- a/src/plugins/flatpak/gbp-flatpak-pipeline-addin.c
+++ b/src/plugins/flatpak/gbp-flatpak-pipeline-addin.c
@@ -20,11 +20,12 @@
 
 #include <glib/gi18n.h>
 
+#include "gbp-flatpak-configuration.h"
+#include "gbp-flatpak-download-stage.h"
 #include "gbp-flatpak-pipeline-addin.h"
 #include "gbp-flatpak-runtime.h"
 #include "gbp-flatpak-transfer.h"
 #include "gbp-flatpak-util.h"
-#include "gbp-flatpak-configuration.h"
 
 G_DEFINE_QUARK (gb-flatpak-pipeline-error-quark, gb_flatpak_pipeline_error)
 
@@ -117,31 +118,6 @@ check_if_file_exists (IdeBuildStage    *stage,
   ide_build_stage_set_completed (stage, exists);
 }
 
-static void
-query_downloads_cb (GbpFlatpakPipelineAddin *self,
-                    IdeBuildPipeline        *pipeline,
-                    GCancellable            *cancellable,
-                    IdeBuildStage           *stage)
-{
-  GNetworkMonitor *monitor;
-
-  g_assert (GBP_IS_FLATPAK_PIPELINE_ADDIN (self));
-  g_assert (IDE_IS_BUILD_PIPELINE (pipeline));
-  g_assert (!cancellable || G_IS_CANCELLABLE (cancellable));
-  g_assert (IDE_IS_BUILD_STAGE (stage));
-
-  /* Ignore downloads if there is no connection */
-  monitor = g_network_monitor_get_default ();
-  if (!g_network_monitor_get_network_available (monitor))
-    {
-      ide_build_stage_log (stage,
-                           IDE_BUILD_LOG_STDOUT,
-                           _("Network is not available, skipping downloads"),
-                           -1);
-      ide_build_stage_set_completed (stage, TRUE);
-    }
-}
-
 static gboolean
 register_build_init_stage (GbpFlatpakPipelineAddin  *self,
                            IdeBuildPipeline         *pipeline,
@@ -249,54 +225,15 @@ register_downloads_stage (GbpFlatpakPipelineAddin  *self,
                           GError                  **error)
 {
   g_autoptr(IdeBuildStage) stage = NULL;
-  g_autoptr(IdeSubprocessLauncher) launcher = NULL;
-  g_autofree gchar *staging_dir = NULL;
-  g_autofree gchar *manifest_path = NULL;
-  g_autofree gchar *stop_at_option = NULL;
-  IdeConfiguration *config;
-  const gchar *src_dir;
-  const gchar *primary_module;
   guint stage_id;
 
   g_assert (GBP_IS_FLATPAK_PIPELINE_ADDIN (self));
   g_assert (IDE_IS_BUILD_PIPELINE (pipeline));
   g_assert (IDE_IS_CONTEXT (context));
 
-  config = ide_build_pipeline_get_configuration (pipeline);
-  if (!GBP_IS_FLATPAK_CONFIGURATION (config))
-    return TRUE;
-
-  primary_module = gbp_flatpak_configuration_get_primary_module (GBP_FLATPAK_CONFIGURATION (config));
-  manifest_path = gbp_flatpak_configuration_get_manifest_path (GBP_FLATPAK_CONFIGURATION (config));
-
-  staging_dir = gbp_flatpak_get_staging_dir (config);
-  src_dir = ide_build_pipeline_get_srcdir (pipeline);
-
-  launcher = create_subprocess_launcher ();
-
-  ide_subprocess_launcher_set_cwd (launcher, src_dir);
-
-  ide_subprocess_launcher_push_argv (launcher, "flatpak-builder");
-  ide_subprocess_launcher_push_argv (launcher, "--ccache");
-  ide_subprocess_launcher_push_argv (launcher, "--force-clean");
-  ide_subprocess_launcher_push_argv (launcher, "--download-only");
-  ide_subprocess_launcher_push_argv (launcher, "--disable-updates");
-  stop_at_option = g_strdup_printf ("--stop-at=%s", primary_module);
-  ide_subprocess_launcher_push_argv (launcher, stop_at_option);
-  ide_subprocess_launcher_push_argv (launcher, staging_dir);
-  ide_subprocess_launcher_push_argv (launcher, manifest_path);
-
-  stage = g_object_new (IDE_TYPE_BUILD_STAGE_LAUNCHER,
+  stage = g_object_new (GBP_TYPE_FLATPAK_DOWNLOAD_STAGE,
                         "context", context,
-                        "launcher", launcher,
                         NULL);
-
-  g_signal_connect_object (stage,
-                           "query",
-                           G_CALLBACK (query_downloads_cb),
-                           self,
-                           G_CONNECT_SWAPPED);
-
   stage_id = ide_build_pipeline_connect (pipeline, IDE_BUILD_PHASE_DOWNLOADS, 0, stage);
   ide_build_pipeline_addin_track (IDE_BUILD_PIPELINE_ADDIN (self), stage_id);
 
diff --git a/src/plugins/flatpak/gbp-flatpak-workbench-addin.c 
b/src/plugins/flatpak/gbp-flatpak-workbench-addin.c
index d39e537..131c5a7 100644
--- a/src/plugins/flatpak/gbp-flatpak-workbench-addin.c
+++ b/src/plugins/flatpak/gbp-flatpak-workbench-addin.c
@@ -21,6 +21,7 @@
 #include <glib/gi18n.h>
 
 #include "gbp-flatpak-application-addin.h"
+#include "gbp-flatpak-download-stage.h"
 #include "gbp-flatpak-workbench-addin.h"
 
 struct _GbpFlatpakWorkbenchAddin
@@ -115,21 +116,48 @@ 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;
-  IdeBuildManager *manager;
+  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);
-  ide_build_manager_execute_async (manager, IDE_BUILD_PHASE_DOWNLOADS, NULL, NULL, NULL);
+
+  /* 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
diff --git a/src/plugins/flatpak/meson.build b/src/plugins/flatpak/meson.build
index 5449c81..8c8ae7c 100644
--- a/src/plugins/flatpak/meson.build
+++ b/src/plugins/flatpak/meson.build
@@ -17,6 +17,8 @@ flatpak_sources = [
   'gbp-flatpak-configuration.h',
   'gbp-flatpak-configuration-provider.c',
   'gbp-flatpak-configuration-provider.h',
+  'gbp-flatpak-download-stage.c',
+  'gbp-flatpak-download-stage.h',
   'gbp-flatpak-genesis-addin.c',
   'gbp-flatpak-genesis-addin.h',
   'gbp-flatpak-pipeline-addin.c',


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