[gnome-builder] libide/foundry: add ease-of-use run command helper



commit 4528b8a107670bc3f6240493216b24759faef1a3
Author: Christian Hergert <chergert redhat com>
Date:   Thu Sep 15 16:06:45 2022 -0700

    libide/foundry: add ease-of-use run command helper
    
    This makes porting older code to use run commands a bit more symmetric with
    the legacy code.

 src/libide/foundry/ide-pipeline.c | 34 ++++++++++++++++++++++++++++++++++
 src/libide/foundry/ide-pipeline.h |  5 +++++
 2 files changed, 39 insertions(+)
---
diff --git a/src/libide/foundry/ide-pipeline.c b/src/libide/foundry/ide-pipeline.c
index 6368e2d78..0ca2e29fd 100644
--- a/src/libide/foundry/ide-pipeline.c
+++ b/src/libide/foundry/ide-pipeline.c
@@ -2627,6 +2627,40 @@ ide_pipeline_attach_launcher (IdePipeline           *self,
   return ide_pipeline_attach (self, phase, priority, stage);
 }
 
+/**
+ * ide_pipeline_attach_command:
+ * @self: an #IdePipeline
+ * @phase: An #IdePipelinePhase
+ * @priority: an optional priority for sorting within the phase
+ * @run_command: An #IdeRunCommand
+ *
+ * This creates a new stage that will spawn a process using @run_command and
+ * log the output of stdin/stdout.
+ *
+ * It is a programmer error to modify @run_command after passing it to this
+ * function.
+ *
+ * Returns: A stage_id that may be passed to ide_pipeline_remove().
+ */
+guint
+ide_pipeline_attach_command (IdePipeline      *self,
+                             IdePipelinePhase  phase,
+                             gint              priority,
+                             IdeRunCommand    *run_command)
+{
+  g_autoptr(IdePipelineStage) stage = NULL;
+
+  g_return_val_if_fail (IDE_IS_PIPELINE (self), 0);
+  g_return_val_if_fail ((phase & IDE_PIPELINE_PHASE_MASK) != IDE_PIPELINE_PHASE_NONE, 0);
+  g_return_val_if_fail ((phase & IDE_PIPELINE_PHASE_WHENCE_MASK) == 0 ||
+                        (phase & IDE_PIPELINE_PHASE_WHENCE_MASK) == IDE_PIPELINE_PHASE_BEFORE ||
+                        (phase & IDE_PIPELINE_PHASE_WHENCE_MASK) == IDE_PIPELINE_PHASE_AFTER, 0);
+
+  stage = ide_pipeline_stage_command_new (run_command, NULL);
+
+  return ide_pipeline_attach (self, phase, priority, stage);
+}
+
 /**
  * ide_pipeline_request_phase:
  * @self: An #IdePipeline
diff --git a/src/libide/foundry/ide-pipeline.h b/src/libide/foundry/ide-pipeline.h
index 05a3ead93..79abb8883 100644
--- a/src/libide/foundry/ide-pipeline.h
+++ b/src/libide/foundry/ide-pipeline.h
@@ -122,6 +122,11 @@ guint                  ide_pipeline_attach_launcher          (IdePipeline
                                                               gint                    priority,
                                                               IdeSubprocessLauncher  *launcher);
 IDE_AVAILABLE_IN_ALL
+guint                  ide_pipeline_attach_command           (IdePipeline            *self,
+                                                              IdePipelinePhase        phase,
+                                                              gint                    priority,
+                                                              IdeRunCommand          *run_command);
+IDE_AVAILABLE_IN_ALL
 void                   ide_pipeline_detach                   (IdePipeline            *self,
                                                               guint                   stage_id);
 IDE_AVAILABLE_IN_ALL


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