[gnome-builder] flatpak: use downloads phase for downloads



commit d8b715327c6277bf066a26a22464eafa73fb6b3f
Author: Christian Hergert <chergert redhat com>
Date:   Tue Mar 7 16:42:43 2017 -0800

    flatpak: use downloads phase for downloads
    
    Previously, we were performing the downloads as part of the dependencies
    phase. Instead, it would be nice if we use the downloads phase for this
    so that we can easily replay it to "update dependencies".

 plugins/flatpak/gbp-flatpak-pipeline-addin.c |   88 ++++++++++++++++++++++++++
 1 files changed, 88 insertions(+), 0 deletions(-)
---
diff --git a/plugins/flatpak/gbp-flatpak-pipeline-addin.c b/plugins/flatpak/gbp-flatpak-pipeline-addin.c
index 6960caa..bfd6e47 100644
--- a/plugins/flatpak/gbp-flatpak-pipeline-addin.c
+++ b/plugins/flatpak/gbp-flatpak-pipeline-addin.c
@@ -18,6 +18,8 @@
 
 #define G_LOG_DOMAIN "gbp-flatpak-pipeline-addin"
 
+#include <glib/gi18n.h>
+
 #include "gbp-flatpak-pipeline-addin.h"
 #include "gbp-flatpak-runtime.h"
 #include "gbp-flatpak-transfer.h"
@@ -100,6 +102,31 @@ 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,
@@ -194,6 +221,66 @@ register_build_init_stage (GbpFlatpakPipelineAddin  *self,
 }
 
 static gboolean
+register_downloads_stage (GbpFlatpakPipelineAddin  *self,
+                          IdeBuildPipeline         *pipeline,
+                          IdeContext               *context,
+                          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");
+  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,
+                        "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);
+
+  return TRUE;
+}
+
+static gboolean
 register_dependencies_stage (GbpFlatpakPipelineAddin  *self,
                              IdeBuildPipeline         *pipeline,
                              IdeContext               *context,
@@ -378,6 +465,7 @@ gbp_flatpak_pipeline_addin_load (IdeBuildPipelineAddin *addin,
 
   if (!register_mkdirs_stage (self, pipeline, context, &error) ||
       !register_build_init_stage (self, pipeline, context, &error) ||
+      !register_downloads_stage (self, pipeline, context, &error) ||
       !register_dependencies_stage (self, pipeline, context, &error) ||
       !register_build_finish_stage (self, pipeline, context, &error))
     g_warning ("%s", error->message);


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