[gnome-builder] build-pipeline: add cancellation support



commit e3ed8d3d02a8f52d6436300ae9614fc8b78cef90
Author: Christian Hergert <chergert redhat com>
Date:   Sun Dec 17 21:12:00 2017 -0800

    build-pipeline: add cancellation support
    
    This allows cancelling tasks from the pipeline directly using
    internal API. The build manager now uses this to propagate its
    cancellable to the pipeline.
    
    This is important because some layers may run build attempts
    against the pipeline directly (working around the manager).

 src/libide/buildsystem/ide-build-manager.c  |    4 +++
 src/libide/buildsystem/ide-build-pipeline.c |   31 ++++++++++++++++++++++++++-
 src/libide/buildsystem/ide-build-private.h  |    1 +
 3 files changed, 35 insertions(+), 1 deletions(-)
---
diff --git a/src/libide/buildsystem/ide-build-manager.c b/src/libide/buildsystem/ide-build-manager.c
index d650b09..6654f8c 100644
--- a/src/libide/buildsystem/ide-build-manager.c
+++ b/src/libide/buildsystem/ide-build-manager.c
@@ -26,6 +26,7 @@
 #include "buffers/ide-buffer-manager.h"
 #include "buildsystem/ide-build-manager.h"
 #include "buildsystem/ide-build-pipeline.h"
+#include "buildsystem/ide-build-private.h"
 #include "buildsystem/ide-configuration-manager.h"
 #include "buildsystem/ide-configuration.h"
 #include "diagnostics/ide-diagnostic.h"
@@ -1053,6 +1054,9 @@ ide_build_manager_cancel (IdeBuildManager *self)
   if (!g_cancellable_is_cancelled (cancellable))
     g_cancellable_cancel (cancellable);
 
+  if (self->pipeline != NULL)
+    _ide_build_pipeline_cancel (self->pipeline);
+
   IDE_EXIT;
 }
 
diff --git a/src/libide/buildsystem/ide-build-pipeline.c b/src/libide/buildsystem/ide-build-pipeline.c
index ef6b0f6..dea822a 100644
--- a/src/libide/buildsystem/ide-build-pipeline.c
+++ b/src/libide/buildsystem/ide-build-pipeline.c
@@ -106,7 +106,14 @@ typedef struct
 
 struct _IdeBuildPipeline
 {
-  IdeObject         parent_instance;
+  IdeObject parent_instance;
+
+  /*
+   * A cancellable we can use to chain to all incoming requests so that
+   * all tasks may be cancelled at once when _ide_build_pipeline_cancel()
+   * is called.
+   */
+  GCancellable *cancellable;
 
   /*
    * These are our extensions to the BuildPipeline. Plugins insert
@@ -966,6 +973,7 @@ ide_build_pipeline_finalize (GObject *object)
   g_assert (self->task_queue.length == 0);
   g_queue_clear (&self->task_queue);
 
+  g_clear_object (&self->cancellable);
   g_clear_object (&self->log);
   g_clear_object (&self->configuration);
   g_clear_pointer (&self->pipeline, g_array_unref);
@@ -1227,6 +1235,8 @@ ide_build_pipeline_init (IdeBuildPipeline *self)
 {
   DZL_COUNTER_INC (Instances);
 
+  self->cancellable = g_cancellable_new ();
+
   self->position = -1;
   self->pty_slave = -1;
 
@@ -1538,6 +1548,8 @@ ide_build_pipeline_build_async (IdeBuildPipeline    *self,
   g_task_set_source_tag (task, ide_build_pipeline_build_async);
   g_task_set_priority (task, G_PRIORITY_LOW);
 
+  dzl_cancellable_chain (cancellable, self->cancellable);
+
   /*
    * If the requested phase has already been met (by a previous build
    * or by an active build who has already surpassed this build phase,
@@ -2729,8 +2741,11 @@ ide_build_pipeline_clean_async (IdeBuildPipeline    *self,
   g_assert (!cancellable || G_IS_CANCELLABLE (cancellable));
 
   task = g_task_new (self, cancellable, callback, user_data);
+  g_task_set_priority (task, G_PRIORITY_LOW);
   g_task_set_source_tag (task, ide_build_pipeline_clean_async);
 
+  dzl_cancellable_chain (cancellable, self->cancellable);
+
   td = task_data_new (task, TASK_CLEAN);
   td->phase = phase;
   g_task_set_task_data (task, td, task_data_free);
@@ -2964,6 +2979,8 @@ ide_build_pipeline_rebuild_async (IdeBuildPipeline    *self,
   g_task_set_priority (task, G_PRIORITY_LOW);
   g_task_set_source_tag (task, ide_build_pipeline_rebuild_async);
 
+  dzl_cancellable_chain (cancellable, self->cancellable);
+
   td = task_data_new (task, TASK_REBUILD);
   td->phase = phase;
   g_task_set_task_data (task, td, task_data_free);
@@ -3046,3 +3063,15 @@ _ide_build_pipeline_set_message (IdeBuildPipeline *self,
       g_object_notify_by_pspec (G_OBJECT (self), properties [PROP_MESSAGE]);
     }
 }
+
+void
+_ide_build_pipeline_cancel (IdeBuildPipeline *self)
+{
+  g_autoptr(GCancellable) cancellable = NULL;
+
+  g_return_if_fail (IDE_IS_BUILD_PIPELINE (self));
+
+  cancellable = g_steal_pointer (&self->cancellable);
+  self->cancellable = g_cancellable_new ();
+  g_cancellable_cancel (cancellable);
+}
diff --git a/src/libide/buildsystem/ide-build-private.h b/src/libide/buildsystem/ide-build-private.h
index f678b0d..b777463 100644
--- a/src/libide/buildsystem/ide-build-private.h
+++ b/src/libide/buildsystem/ide-build-private.h
@@ -24,6 +24,7 @@
 
 G_BEGIN_DECLS
 
+void    _ide_build_pipeline_cancel      (IdeBuildPipeline *self);
 VtePty *_ide_build_pipeline_get_pty     (IdeBuildPipeline *self);
 void    _ide_build_pipeline_set_message (IdeBuildPipeline *self,
                                          const gchar      *message);


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