[gnome-builder] libide/foundry: add ide_pty_new_sync()



commit aa33207f67e34e8da03a40ad57537e58148ff3e4
Author: Christian Hergert <chergert redhat com>
Date:   Thu Jul 14 14:51:08 2022 -0700

    libide/foundry: add ide_pty_new_sync()
    
    This is to unify the creation of PTY for use within Builder so that we
    don't have to track what has which sort of options and where. The goal is
    to have a PTY that is suitable for passing across to another PTY namespace
    (which requires further work in IdeRunContext).

 src/libide/foundry/ide-pipeline.c                  |  6 +-
 src/libide/foundry/ide-pty.c                       | 66 ++++++++++++++++++++++
 src/libide/foundry/ide-pty.h                       | 36 ++++++++++++
 src/libide/foundry/ide-test-manager.c              |  4 +-
 src/libide/foundry/libide-foundry.h                |  1 +
 src/libide/foundry/meson.build                     |  2 +
 src/libide/terminal/ide-terminal-page.c            | 17 +++---
 .../terminal/gbp-terminal-workspace-addin.c        |  2 +-
 8 files changed, 118 insertions(+), 16 deletions(-)
---
diff --git a/src/libide/foundry/ide-pipeline.c b/src/libide/foundry/ide-pipeline.c
index e5f70c551..d16aa4371 100644
--- a/src/libide/foundry/ide-pipeline.c
+++ b/src/libide/foundry/ide-pipeline.c
@@ -51,6 +51,7 @@
 #include "ide-foundry-enums.h"
 #include "ide-local-deploy-strategy.h"
 #include "ide-local-device.h"
+#include "ide-pty.h"
 #include "ide-run-command.h"
 #include "ide-run-context.h"
 #include "ide-run-manager-private.h"
@@ -1543,12 +1544,9 @@ ide_pipeline_initable_init (GInitable     *initable,
    * Create a PTY for subprocess launchers. PTY initialization does not
    * support cancellation, so do not pass @cancellable along to it.
    */
-  self->pty = vte_pty_new_sync (VTE_PTY_DEFAULT, NULL, error);
-  if (self->pty == NULL)
+  if (!(self->pty = ide_pty_new_sync (error)))
     IDE_RETURN (FALSE);
 
-  vte_pty_set_utf8 (self->pty, TRUE, NULL);
-
   consumer_fd = vte_pty_get_fd (self->pty);
 
   if (!ide_pty_intercept_init (&self->intercept, consumer_fd, NULL))
diff --git a/src/libide/foundry/ide-pty.c b/src/libide/foundry/ide-pty.c
new file mode 100644
index 000000000..4d33e95c7
--- /dev/null
+++ b/src/libide/foundry/ide-pty.c
@@ -0,0 +1,66 @@
+/* ide-pty.c
+ *
+ * Copyright 2022 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/>.
+ *
+ * SPDX-License-Identifier: GPL-3.0-or-later
+ */
+
+#define G_LOG_DOMAIN "ide-pty"
+
+#include "config.h"
+
+#include <libide-io.h>
+
+#include "ide-pty.h"
+
+/**
+ * ide_pty_new_sync:
+ * @error: a location for a #GError or %NULL
+ *
+ * Creates a new #VtePty suitable for Builder to be able to pass the
+ * PTY across PTY namespaces on Linux.
+ *
+ * Use this instead of vte_pty_new_sync() or similar.
+ *
+ * Returns: (transfer full): a #VtePty if successful, otherwise %NULL
+ *   and @error is set.
+ */
+VtePty *
+ide_pty_new_sync (GError **error)
+{
+  VtePty *ret;
+  int fd;
+
+  fd = ide_pty_intercept_create_consumer ();
+
+  if (fd == IDE_PTY_FD_INVALID)
+    {
+      int errsv = errno;
+      g_set_error_literal (error,
+                           G_IO_ERROR,
+                           g_io_error_from_errno (errsv),
+                           g_strerror (errsv));
+      return NULL;
+    }
+
+  if ((ret = vte_pty_new_foreign_sync (fd, NULL, error)))
+    {
+      if (!vte_pty_set_utf8 (ret, TRUE, error))
+        g_clear_object (&ret);
+    }
+
+  return ret;
+}
diff --git a/src/libide/foundry/ide-pty.h b/src/libide/foundry/ide-pty.h
new file mode 100644
index 000000000..f80d18dcd
--- /dev/null
+++ b/src/libide/foundry/ide-pty.h
@@ -0,0 +1,36 @@
+/* ide-pty.h
+ *
+ * Copyright 2022 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/>.
+ *
+ * SPDX-License-Identifier: GPL-3.0-or-later
+ */
+
+#pragma once
+
+#if !defined (IDE_FOUNDRY_INSIDE) && !defined (IDE_FOUNDRY_COMPILATION)
+# error "Only <libide-foundry.h> can be included directly."
+#endif
+
+#include <vte/vte.h>
+
+#include <libide-core.h>
+
+G_BEGIN_DECLS
+
+IDE_AVAILABLE_IN_ALL
+VtePty *ide_pty_new_sync (GError **error);
+
+G_END_DECLS
diff --git a/src/libide/foundry/ide-test-manager.c b/src/libide/foundry/ide-test-manager.c
index 9227339b8..6fdd80117 100644
--- a/src/libide/foundry/ide-test-manager.c
+++ b/src/libide/foundry/ide-test-manager.c
@@ -31,6 +31,7 @@
 #include "ide-build-manager.h"
 #include "ide-foundry-compat.h"
 #include "ide-pipeline.h"
+#include "ide-pty.h"
 #include "ide-run-command.h"
 #include "ide-run-commands.h"
 #include "ide-run-manager.h"
@@ -236,8 +237,7 @@ ide_test_manager_init (IdeTestManager *self)
   GtkCustomFilter *filter;
   GtkMapListModel *map;
 
-  self->pty = vte_pty_new_sync (VTE_PTY_DEFAULT, NULL, NULL);
-  vte_pty_set_utf8 (self->pty, TRUE, NULL);
+  self->pty = ide_pty_new_sync (NULL);
 
   filter = gtk_custom_filter_new (filter_tests_func, NULL, NULL);
   self->filtered = gtk_filter_list_model_new (NULL, GTK_FILTER (filter));
diff --git a/src/libide/foundry/libide-foundry.h b/src/libide/foundry/libide-foundry.h
index 362c7eeab..a0a76a150 100644
--- a/src/libide/foundry/libide-foundry.h
+++ b/src/libide/foundry/libide-foundry.h
@@ -56,6 +56,7 @@ G_BEGIN_DECLS
 #include "ide-pipeline-stage-transfer.h"
 #include "ide-pipeline-stage.h"
 #include "ide-pipeline.h"
+#include "ide-pty.h"
 #include "ide-run-command.h"
 #include "ide-run-command-provider.h"
 #include "ide-run-commands.h"
diff --git a/src/libide/foundry/meson.build b/src/libide/foundry/meson.build
index e8155ec93..2198cb241 100644
--- a/src/libide/foundry/meson.build
+++ b/src/libide/foundry/meson.build
@@ -41,6 +41,7 @@ libide_foundry_public_headers = [
   'ide-pipeline-stage-transfer.h',
   'ide-pipeline-stage.h',
   'ide-pipeline.h',
+  'ide-pty.h',
   'ide-run-command.h',
   'ide-run-command-provider.h',
   'ide-run-commands.h',
@@ -122,6 +123,7 @@ libide_foundry_public_sources = [
   'ide-pipeline-stage-transfer.c',
   'ide-pipeline-stage.c',
   'ide-pipeline.c',
+  'ide-pty.c',
   'ide-run-command.c',
   'ide-run-command-provider.c',
   'ide-run-commands.c',
diff --git a/src/libide/terminal/ide-terminal-page.c b/src/libide/terminal/ide-terminal-page.c
index b85039e65..53d5c8fe4 100644
--- a/src/libide/terminal/ide-terminal-page.c
+++ b/src/libide/terminal/ide-terminal-page.c
@@ -22,17 +22,16 @@
 
 #include "config.h"
 
-#include <fcntl.h>
 #include <glib/gi18n.h>
-#include <libide-foundry.h>
-#include <libide-gui.h>
-#include <libide-terminal.h>
+
+#include <fcntl.h>
 #include <stdlib.h>
-#include <vte/vte.h>
 #include <unistd.h>
+#include <vte/vte.h>
 
-#define PCRE2_CODE_UNIT_WIDTH 0
-#include <pcre2.h>
+#include <libide-foundry.h>
+#include <libide-gui.h>
+#include <libide-terminal.h>
 
 #include "ide-terminal-page.h"
 #include "ide-terminal-page-private.h"
@@ -149,7 +148,7 @@ ide_terminal_page_spawn_cb (GObject      *object,
 
   g_clear_object (&self->pty);
   vte_terminal_reset (VTE_TERMINAL (self->terminal), TRUE, TRUE);
-  self->pty = vte_pty_new_sync (VTE_PTY_DEFAULT, NULL, NULL);
+  self->pty = ide_pty_new_sync (NULL);
   vte_terminal_set_pty (VTE_TERMINAL (self->terminal), self->pty);
 
   /* Spawn our terminal and wait for it to exit */
@@ -181,7 +180,7 @@ ide_terminal_page_do_spawn_in_idle (IdeTerminalPage *self)
     {
       g_autoptr(GError) error = NULL;
 
-      if (!(self->pty = vte_pty_new_sync (VTE_PTY_DEFAULT, NULL, &error)))
+      if (!(self->pty = ide_pty_new_sync (&error)))
         {
           g_critical ("Failed to create PTY for terminal: %s", error->message);
           IDE_RETURN (G_SOURCE_REMOVE);
diff --git a/src/plugins/terminal/gbp-terminal-workspace-addin.c 
b/src/plugins/terminal/gbp-terminal-workspace-addin.c
index c8f7d20b4..009e0c099 100644
--- a/src/plugins/terminal/gbp-terminal-workspace-addin.c
+++ b/src/plugins/terminal/gbp-terminal-workspace-addin.c
@@ -247,7 +247,7 @@ gbp_terminal_workspace_addin_load (IdeWorkspaceAddin *addin,
       IdeWorkbench *workbench = ide_workspace_get_workbench (workspace);
       IdeContext *context = ide_workbench_get_context (workbench);
       IdeRunManager *run_manager = ide_run_manager_from_context (context);
-      VtePty *pty = vte_pty_new_sync (VTE_PTY_DEFAULT, NULL, NULL);
+      VtePty *pty = ide_pty_new_sync (NULL);
 
       self->app_page = g_object_new (IDE_TYPE_TERMINAL_PAGE,
                                      "respawn-on-exit", FALSE,


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