[gnome-builder] libide/foundry: add private API to attach PTY to run context
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder] libide/foundry: add private API to attach PTY to run context
- Date: Mon, 26 Sep 2022 19:40:02 +0000 (UTC)
commit aedaf5f5f2450411b346ca64196bcd524888c1c3
Author: Christian Hergert <chergert redhat com>
Date: Mon Sep 26 12:34:10 2022 -0700
libide/foundry: add private API to attach PTY to run context
We can make this public in 44, but for now keep it private to simplify the
backport to 43.
We want to use this to attach PTY to the top-most layer of the run context
so that layers like runtimes can see if there is a PTY required. They might
use that information to set additional feature flags.
For example, GbpPodmanRuntime needs this to determine if --tty should be
used when spawning with `podman exec`.
src/libide/foundry/ide-pipeline-private.h | 30 ++++++++++++++++++++++
src/libide/foundry/ide-pipeline.c | 41 +++++++++++++++++++++++++++++++
2 files changed, 71 insertions(+)
---
diff --git a/src/libide/foundry/ide-pipeline-private.h b/src/libide/foundry/ide-pipeline-private.h
new file mode 100644
index 000000000..46fb02983
--- /dev/null
+++ b/src/libide/foundry/ide-pipeline-private.h
@@ -0,0 +1,30 @@
+/* ide-pipeline-private.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
+
+#include "ide-pipeline.h"
+
+G_BEGIN_DECLS
+
+void _ide_pipeline_attach_pty_to_run_context (IdePipeline *self,
+ IdeRunContext *run_context);
+
+G_END_DECLS
diff --git a/src/libide/foundry/ide-pipeline.c b/src/libide/foundry/ide-pipeline.c
index 8b6dac9cf..9adefee4e 100644
--- a/src/libide/foundry/ide-pipeline.c
+++ b/src/libide/foundry/ide-pipeline.c
@@ -39,6 +39,7 @@
#include "ide-deploy-strategy.h"
#include "ide-pipeline-addin.h"
#include "ide-pipeline.h"
+#include "ide-pipeline-private.h"
#include "ide-build-private.h"
#include "ide-pipeline-stage-command.h"
#include "ide-pipeline-stage-launcher.h"
@@ -3046,6 +3047,46 @@ ide_pipeline_create_launcher (IdePipeline *self,
return g_steal_pointer (&ret);
}
+void
+_ide_pipeline_attach_pty_to_run_context (IdePipeline *self,
+ IdeRunContext *run_context)
+{
+ static const int fileno_mapping[] = { STDIN_FILENO, STDOUT_FILENO, STDERR_FILENO };
+
+ IDE_ENTRY;
+
+ g_return_if_fail (IDE_IS_MAIN_THREAD ());
+ g_return_if_fail (IDE_IS_PIPELINE (self));
+ g_return_if_fail (IDE_IS_RUN_CONTEXT (run_context));
+
+ if (self->pty_producer == -1)
+ {
+ IdePtyFd consumer_fd = ide_pty_intercept_get_fd (&self->intercept);
+ self->pty_producer = ide_pty_intercept_create_producer (consumer_fd, TRUE);
+ }
+
+ for (guint i = 0; i < G_N_ELEMENTS (fileno_mapping); i++)
+ {
+ int fd = self->pty_producer > -1 ? dup (self->pty_producer) : -1;
+
+ if (fd == -1)
+ {
+ ide_run_context_push_error (run_context,
+ g_error_new_literal (G_IO_ERROR,
+ G_IO_ERROR_FAILED,
+ _("Pseudo terminal creation failed. Terminal
features will be limited.")));
+ IDE_EXIT;
+ }
+
+ ide_run_context_take_fd (run_context, fd, fileno_mapping[i]);
+ }
+
+ ide_run_context_setenv (run_context, "TERM", "xterm-256color");
+ ide_run_context_setenv (run_context, "COLORTERM", "truecolor");
+
+ IDE_EXIT;
+}
+
/**
* ide_pipeline_attach_pty:
* @self: an #IdePipeline
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]