[gnome-builder] foundry: add VtePty parameter when running unit tests



commit dee5b184f84ebaad31e042fba75d892e3a1d7db5
Author: Christian Hergert <chergert redhat com>
Date:   Wed Feb 20 16:36:18 2019 -0800

    foundry: add VtePty parameter when running unit tests
    
    This allows runners to wire up a PTY when running tests. We can use that
    later on to show unit test output in the bottom panel.

 src/libide/foundry/ide-runner.c             | 27 ++++++++++++
 src/libide/foundry/ide-runner.h             |  4 ++
 src/libide/foundry/ide-test-manager.c       |  1 +
 src/libide/foundry/ide-test-manager.h       |  1 +
 src/libide/foundry/ide-test-provider.c      |  8 +++-
 src/libide/foundry/ide-test-provider.h      |  6 ++-
 src/plugins/gradle/gradle_plugin.py         |  5 ++-
 src/plugins/maven/maven_plugin.py           |  5 ++-
 src/plugins/meson/gbp-meson-test-provider.c | 68 +++++++++++++++++++++--------
 9 files changed, 101 insertions(+), 24 deletions(-)
---
diff --git a/src/libide/foundry/ide-runner.c b/src/libide/foundry/ide-runner.c
index 25e68c826..c9b48c0e6 100644
--- a/src/libide/foundry/ide-runner.c
+++ b/src/libide/foundry/ide-runner.c
@@ -1204,6 +1204,33 @@ ide_runner_set_tty (IdeRunner *self,
   IDE_EXIT;
 }
 
+/**
+ * ide_runner_set_pty:
+ * @self: a #IdeRunner
+ * @pty: (nullable): a #VtePty or %NULL
+ *
+ * Sets the #VtePty to use for the runner.
+ *
+ * This is equivalent to calling ide_runner_set_tty() with the
+ * result of vte_pty_get_fd().
+ *
+ * Since: 3.32
+ */
+void
+ide_runner_set_pty (IdeRunner *self,
+                    VtePty    *pty)
+{
+  int fd = -1;
+
+  g_return_if_fail (IDE_IS_RUNNER (self));
+  g_return_if_fail (!pty || VTE_IS_PTY (pty));
+
+  if (pty != NULL)
+    fd = vte_pty_get_fd (pty);
+
+  ide_runner_set_tty (self, fd);
+}
+
 static gint
 sort_fd_mapping (gconstpointer a,
                  gconstpointer b)
diff --git a/src/libide/foundry/ide-runner.h b/src/libide/foundry/ide-runner.h
index ac8be8770..99698eaa8 100644
--- a/src/libide/foundry/ide-runner.h
+++ b/src/libide/foundry/ide-runner.h
@@ -26,6 +26,7 @@
 
 #include <libide-core.h>
 #include <libide-threading.h>
+#include <vte/vte.h>
 
 #include "ide-foundry-types.h"
 
@@ -129,6 +130,9 @@ IDE_AVAILABLE_IN_3_32
 void               ide_runner_set_run_on_host  (IdeRunner            *self,
                                                 gboolean              run_on_host);
 IDE_AVAILABLE_IN_3_32
+void               ide_runner_set_pty          (IdeRunner            *self,
+                                                VtePty               *pty);
+IDE_AVAILABLE_IN_3_32
 void               ide_runner_set_tty          (IdeRunner            *self,
                                                 int                   tty_fd);
 IDE_AVAILABLE_IN_3_32
diff --git a/src/libide/foundry/ide-test-manager.c b/src/libide/foundry/ide-test-manager.c
index 2b8fb31e6..06e38dc06 100644
--- a/src/libide/foundry/ide-test-manager.c
+++ b/src/libide/foundry/ide-test-manager.c
@@ -734,6 +734,7 @@ ide_test_manager_run_async (IdeTestManager      *self,
   ide_test_provider_run_async (provider,
                                test,
                                pipeline,
+                               NULL, /* PTY */
                                cancellable,
                                ide_test_manager_run_cb,
                                g_steal_pointer (&task));
diff --git a/src/libide/foundry/ide-test-manager.h b/src/libide/foundry/ide-test-manager.h
index 2bf74c820..842d82b3d 100644
--- a/src/libide/foundry/ide-test-manager.h
+++ b/src/libide/foundry/ide-test-manager.h
@@ -25,6 +25,7 @@
 #endif
 
 #include <libide-core.h>
+#include <vte/vte.h>
 
 #include "ide-foundry-types.h"
 
diff --git a/src/libide/foundry/ide-test-provider.c b/src/libide/foundry/ide-test-provider.c
index 2887dbaf3..c1e4f4e4f 100644
--- a/src/libide/foundry/ide-test-provider.c
+++ b/src/libide/foundry/ide-test-provider.c
@@ -49,7 +49,8 @@ static GParamSpec *properties [N_PROPS];
 static void
 ide_test_provider_real_run_async (IdeTestProvider     *self,
                                   IdeTest             *test,
-                                  IdePipeline    *pipeline,
+                                  IdePipeline         *pipeline,
+                                  VtePty              *pty,
                                   GCancellable        *cancellable,
                                   GAsyncReadyCallback  callback,
                                   gpointer             user_data)
@@ -266,7 +267,8 @@ ide_test_provider_clear (IdeTestProvider *self)
 void
 ide_test_provider_run_async (IdeTestProvider     *self,
                              IdeTest             *test,
-                             IdePipeline    *pipeline,
+                             IdePipeline         *pipeline,
+                             VtePty              *pty,
                              GCancellable        *cancellable,
                              GAsyncReadyCallback  callback,
                              gpointer             user_data)
@@ -274,11 +276,13 @@ ide_test_provider_run_async (IdeTestProvider     *self,
   g_return_if_fail (IDE_IS_TEST_PROVIDER (self));
   g_return_if_fail (IDE_IS_TEST (test));
   g_return_if_fail (IDE_IS_PIPELINE (pipeline));
+  g_return_if_fail (!pty || VTE_IS_PTY (pty));
   g_return_if_fail (!cancellable || G_IS_CANCELLABLE (cancellable));
 
   IDE_TEST_PROVIDER_GET_CLASS (self)->run_async (self,
                                                  test,
                                                  pipeline,
+                                                 pty,
                                                  cancellable,
                                                  callback,
                                                  user_data);
diff --git a/src/libide/foundry/ide-test-provider.h b/src/libide/foundry/ide-test-provider.h
index e31ef2410..54222bd72 100644
--- a/src/libide/foundry/ide-test-provider.h
+++ b/src/libide/foundry/ide-test-provider.h
@@ -41,7 +41,8 @@ struct _IdeTestProviderClass
 
   void     (*run_async)  (IdeTestProvider      *self,
                           IdeTest              *test,
-                          IdePipeline     *pipeline,
+                          IdePipeline          *pipeline,
+                          VtePty               *pty,
                           GCancellable         *cancellable,
                           GAsyncReadyCallback   callback,
                           gpointer              user_data);
@@ -70,7 +71,8 @@ void     ide_test_provider_remove      (IdeTestProvider      *self,
 IDE_AVAILABLE_IN_3_32
 void     ide_test_provider_run_async   (IdeTestProvider      *self,
                                         IdeTest              *test,
-                                        IdePipeline     *pipeline,
+                                        IdePipeline          *pipeline,
+                                        VtePty               *pty,
                                         GCancellable         *cancellable,
                                         GAsyncReadyCallback   callback,
                                         gpointer              user_data);
diff --git a/src/plugins/gradle/gradle_plugin.py b/src/plugins/gradle/gradle_plugin.py
index 73c2427af..61f48afea 100755
--- a/src/plugins/gradle/gradle_plugin.py
+++ b/src/plugins/gradle/gradle_plugin.py
@@ -153,7 +153,7 @@ class GradleBuildTargetProvider(Ide.Object, Ide.BuildTargetProvider):
 
 class GradleIdeTestProvider(Ide.TestProvider):
 
-    def do_run_async(self, test, pipeline, cancellable, callback, data):
+    def do_run_async(self, test, pipeline, pty, cancellable, callback, data):
         task = Ide.Task.new(self, cancellable, callback)
         task.set_priority(GLib.PRIORITY_LOW)
 
@@ -176,6 +176,9 @@ class GradleIdeTestProvider(Ide.TestProvider):
 
             runner.set_flags(Gio.SubprocessFlags.STDOUT_PIPE | Gio.SubprocessFlags.STDERR_PIPE)
 
+            if pty is not None:
+                runner.set_pty(pty)
+
             srcdir = pipeline.get_srcdir()
             runner.set_cwd(srcdir)
 
diff --git a/src/plugins/maven/maven_plugin.py b/src/plugins/maven/maven_plugin.py
index 651b7ee96..0030e73f1 100755
--- a/src/plugins/maven/maven_plugin.py
+++ b/src/plugins/maven/maven_plugin.py
@@ -156,7 +156,7 @@ class MavenBuildTargetProvider(Ide.Object, Ide.BuildTargetProvider):
 
 class MavenIdeTestProvider(Ide.TestProvider):
 
-    def do_run_async(self, test, pipeline, cancellable, callback, data):
+    def do_run_async(self, test, pipeline, pty, cancellable, callback, data):
         task = Ide.Task.new(self, cancellable, callback)
         task.set_priority(GLib.PRIORITY_LOW)
 
@@ -179,6 +179,9 @@ class MavenIdeTestProvider(Ide.TestProvider):
 
             runner.set_flags(Gio.SubprocessFlags.STDOUT_PIPE | Gio.SubprocessFlags.STDERR_PIPE)
 
+            if pty is not None:
+                runner.set_pty(pty)
+
             srcdir = pipeline.get_srcdir()
             runner.set_cwd(srcdir)
 
diff --git a/src/plugins/meson/gbp-meson-test-provider.c b/src/plugins/meson/gbp-meson-test-provider.c
index cf8614800..17066e32a 100644
--- a/src/plugins/meson/gbp-meson-test-provider.c
+++ b/src/plugins/meson/gbp-meson-test-provider.c
@@ -34,8 +34,22 @@ struct _GbpMesonTestProvider
   guint            reload_source;
 };
 
+typedef struct
+{
+  IdeTest *test;
+  VtePty  *pty;
+} Run;
+
 G_DEFINE_TYPE (GbpMesonTestProvider, gbp_meson_test_provider, IDE_TYPE_TEST_PROVIDER)
 
+static void
+run_free (Run *run)
+{
+  g_clear_object (&run->test);
+  g_clear_object (&run->pty);
+  g_slice_free (Run, run);
+}
+
 static void
 gbp_meson_test_provider_load_json (GbpMesonTestProvider *self,
                                    JsonNode             *root)
@@ -362,23 +376,26 @@ gbp_meson_test_provider_run_cb (GObject      *object,
   IdeRunner *runner = (IdeRunner *)object;
   g_autoptr(IdeTask) task = user_data;
   g_autoptr(GError) error = NULL;
-  IdeTest *test;
+  Run *run;
 
   g_assert (IDE_IS_RUNNER (runner));
   g_assert (G_IS_ASYNC_RESULT (result));
   g_assert (IDE_IS_TASK (task));
 
-  test = ide_task_get_task_data (task);
-  g_assert (IDE_IS_TEST (test));
+  run = ide_task_get_task_data (task);
+
+  g_assert (run != NULL);
+  g_assert (IDE_IS_TEST (run->test));
+  g_assert (!run->pty || VTE_IS_PTY (run->pty));
 
   if (!ide_runner_run_finish (runner, result, &error))
     {
-      ide_test_set_status (test, IDE_TEST_STATUS_FAILED);
+      ide_test_set_status (run->test, IDE_TEST_STATUS_FAILED);
       ide_task_return_error (task, g_steal_pointer (&error));
       return;
     }
 
-  ide_test_set_status (test, IDE_TEST_STATUS_SUCCESS);
+  ide_test_set_status (run->test, IDE_TEST_STATUS_SUCCESS);
   ide_object_destroy (IDE_OBJECT (runner));
 
   ide_task_return_boolean (task, TRUE);
@@ -398,8 +415,8 @@ gbp_meson_test_provider_run_build_cb (GObject      *object,
   const gchar * const *environ_;
   const gchar *builddir;
   IdeRuntime *runtime;
-  IdeTest *test;
   GFile *workdir;
+  Run *run;
 
   IDE_ENTRY;
 
@@ -407,6 +424,12 @@ gbp_meson_test_provider_run_build_cb (GObject      *object,
   g_assert (G_IS_ASYNC_RESULT (result));
   g_assert (IDE_IS_TASK (task));
 
+  run = ide_task_get_task_data (task);
+
+  g_assert (run != NULL);
+  g_assert (IDE_IS_TEST (run->test));
+  g_assert (!run->pty || VTE_IS_PTY (run->pty));
+
   if (!ide_pipeline_build_finish (pipeline, result, &error))
     {
       ide_task_return_error (task, g_steal_pointer (&error));
@@ -426,22 +449,24 @@ gbp_meson_test_provider_run_build_cb (GObject      *object,
       IDE_EXIT;
     }
 
-  test = ide_task_get_task_data (task);
   cancellable = ide_task_get_cancellable (task);
 
-  g_assert (IDE_IS_TEST (test));
+  g_assert (IDE_IS_TEST (run->test));
   g_assert (!cancellable || G_IS_CANCELLABLE (cancellable));
 
   ide_runner_set_flags (runner,
                         (G_SUBPROCESS_FLAGS_STDOUT_PIPE |
                          G_SUBPROCESS_FLAGS_STDERR_PIPE));
 
+  if (run->pty)
+    ide_runner_set_pty (runner, run->pty);
+
   /* Default to running from builddir */
   builddir = ide_pipeline_get_builddir (pipeline);
   ide_runner_set_cwd (runner, builddir);
 
   /* And override of the test requires it */
-  workdir = gbp_meson_test_get_workdir (GBP_MESON_TEST (test));
+  workdir = gbp_meson_test_get_workdir (GBP_MESON_TEST (run->test));
   if (workdir != NULL)
     {
       g_autofree gchar *path = g_file_get_path (workdir);
@@ -449,11 +474,11 @@ gbp_meson_test_provider_run_build_cb (GObject      *object,
     }
 
   /* Set our command as specified by meson */
-  command = gbp_meson_test_get_command (GBP_MESON_TEST (test));
+  command = gbp_meson_test_get_command (GBP_MESON_TEST (run->test));
   ide_runner_push_args (runner, command);
 
   /* Make sure the environment is respected */
-  if ((environ_ = gbp_meson_test_get_environ (GBP_MESON_TEST (test))))
+  if ((environ_ = gbp_meson_test_get_environ (GBP_MESON_TEST (run->test))))
     {
       IdeEnvironment *dest = ide_runner_get_environment (runner);
 
@@ -467,7 +492,7 @@ gbp_meson_test_provider_run_build_cb (GObject      *object,
         }
     }
 
-  ide_test_set_status (test, IDE_TEST_STATUS_RUNNING);
+  ide_test_set_status (run->test, IDE_TEST_STATUS_RUNNING);
 
   ide_runner_run_async (runner,
                         cancellable,
@@ -480,24 +505,31 @@ gbp_meson_test_provider_run_build_cb (GObject      *object,
 static void
 gbp_meson_test_provider_run_async (IdeTestProvider     *provider,
                                    IdeTest             *test,
-                                   IdePipeline    *pipeline,
+                                   IdePipeline         *pipeline,
+                                   VtePty              *pty,
                                    GCancellable        *cancellable,
                                    GAsyncReadyCallback  callback,
                                    gpointer             user_data)
 {
   GbpMesonTestProvider *self = (GbpMesonTestProvider *)provider;
   g_autoptr(IdeTask) task = NULL;
+  Run *run;
 
   IDE_ENTRY;
 
   g_assert (GBP_IS_MESON_TEST_PROVIDER (self));
   g_assert (GBP_IS_MESON_TEST (test));
   g_assert (IDE_IS_PIPELINE (pipeline));
+  g_assert (!pty || VTE_IS_PTY (pty));
   g_assert (!cancellable || G_IS_CANCELLABLE (cancellable));
 
+  run = g_slice_new0 (Run);
+  run->test = g_object_ref (test);
+  run->pty = pty ? g_object_ref (pty) : NULL;
+
   task = ide_task_new (self, cancellable, callback, user_data);
   ide_task_set_source_tag (task, gbp_meson_test_provider_run_async);
-  ide_task_set_task_data (task, g_object_ref (test), g_object_unref);
+  ide_task_set_task_data (task, run, run_free);
   ide_task_set_priority (task, G_PRIORITY_LOW);
 
   /* Currently, we don't have a way to determine what targets
@@ -506,10 +538,10 @@ gbp_meson_test_provider_run_async (IdeTestProvider     *provider,
    */
 
   ide_pipeline_build_async (pipeline,
-                                  IDE_PIPELINE_PHASE_BUILD,
-                                  cancellable,
-                                  gbp_meson_test_provider_run_build_cb,
-                                  g_steal_pointer (&task));
+                            IDE_PIPELINE_PHASE_BUILD,
+                            cancellable,
+                            gbp_meson_test_provider_run_build_cb,
+                            g_steal_pointer (&task));
 
   IDE_EXIT;
 }


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