[gnome-builder/wip/gtk4-port: 1648/1774] libide/foundry: add minimal shell helper




commit 24b92c38962ac1fd362f7c81c4bcd884303f4423
Author: Christian Hergert <chergert redhat com>
Date:   Fri Jun 24 04:46:04 2022 -0700

    libide/foundry: add minimal shell helper
    
    This should allow us to remove the same code from a few places eventually.

 src/libide/foundry/ide-run-context.c |  53 +++++++++++++++++
 src/libide/foundry/ide-run-context.h | 112 ++++++++++++++++++-----------------
 2 files changed, 110 insertions(+), 55 deletions(-)
---
diff --git a/src/libide/foundry/ide-run-context.c b/src/libide/foundry/ide-run-context.c
index 76fe73b56..736f5956b 100644
--- a/src/libide/foundry/ide-run-context.c
+++ b/src/libide/foundry/ide-run-context.c
@@ -28,6 +28,8 @@
 
 #include <libide-io.h>
 
+#include "ide-private.h"
+
 #include "ide-run-context.h"
 
 typedef struct
@@ -58,6 +60,57 @@ ide_run_context_new (void)
   return g_object_new (IDE_TYPE_RUN_CONTEXT, NULL);
 }
 
+/**
+ * ide_run_context_add_minimal_environment:
+ * @self: a #IdeRunContext
+ *
+ * Adds a minimal set of environment variables.
+ *
+ * This is useful to get access to things like the display or other
+ * expected variables.
+ */
+void
+ide_run_context_add_minimal_environment (IdeRunContext *self)
+{
+  const gchar * const *host_environ = _ide_host_environ ();
+  static const char *copy_env[] = {
+    "AT_SPI_BUS_ADDRESS",
+    "COLORTERM",
+    "DBUS_SESSION_BUS_ADDRESS",
+    "DBUS_SYSTEM_BUS_ADDRESS",
+    "DESKTOP_SESSION",
+    "DISPLAY",
+    "LANG",
+    "SHELL",
+    "SSH_AUTH_SOCK",
+    "USER",
+    "WAYLAND_DISPLAY",
+    "XAUTHORITY",
+    "XDG_CURRENT_DESKTOP",
+    "XDG_MENU_PREFIX",
+    "XDG_SEAT",
+    "XDG_SESSION_DESKTOP",
+    "XDG_SESSION_ID",
+    "XDG_SESSION_TYPE",
+    "XDG_VTNR",
+  };
+
+  IDE_ENTRY;
+
+  g_return_if_fail (IDE_IS_RUN_CONTEXT (self));
+
+  for (guint i = 0; i < G_N_ELEMENTS (copy_env); i++)
+    {
+      const char *key = copy_env[i];
+      const char *val = g_environ_getenv ((char **)host_environ, key);
+
+      if (val != NULL)
+        ide_run_context_setenv (self, key, val);
+    }
+
+  IDE_EXIT;
+}
+
 static void
 ide_run_context_layer_clear (IdeRunContextLayer *layer)
 {
diff --git a/src/libide/foundry/ide-run-context.h b/src/libide/foundry/ide-run-context.h
index 7c9fecc8d..51bcf13a8 100644
--- a/src/libide/foundry/ide-run-context.h
+++ b/src/libide/foundry/ide-run-context.h
@@ -49,86 +49,88 @@ typedef gboolean (*IdeRunContextHandler) (IdeRunContext       *run_context,
                                           GError             **error);
 
 IDE_AVAILABLE_IN_ALL
-IdeRunContext         *ide_run_context_new                (void);
+IdeRunContext         *ide_run_context_new                     (void);
 IDE_AVAILABLE_IN_ALL
-void                   ide_run_context_push               (IdeRunContext         *self,
-                                                           IdeRunContextHandler   handler,
-                                                           gpointer               handler_data,
-                                                           GDestroyNotify         handler_data_destroy);
+void                   ide_run_context_push                    (IdeRunContext         *self,
+                                                                IdeRunContextHandler   handler,
+                                                                gpointer               handler_data,
+                                                                GDestroyNotify         handler_data_destroy);
 IDE_AVAILABLE_IN_ALL
-void                   ide_run_context_push_host          (IdeRunContext         *self);
+void                   ide_run_context_push_host               (IdeRunContext         *self);
 IDE_AVAILABLE_IN_ALL
-void                   ide_run_context_push_expansion     (IdeRunContext         *self,
-                                                           const char * const    *environ);
+void                   ide_run_context_push_expansion          (IdeRunContext         *self,
+                                                                const char * const    *environ);
 IDE_AVAILABLE_IN_ALL
-const char * const    *ide_run_context_get_argv           (IdeRunContext         *self);
+const char * const    *ide_run_context_get_argv                (IdeRunContext         *self);
 IDE_AVAILABLE_IN_ALL
-void                   ide_run_context_set_argv           (IdeRunContext         *self,
-                                                           const char * const    *argv);
+void                   ide_run_context_set_argv                (IdeRunContext         *self,
+                                                                const char * const    *argv);
 IDE_AVAILABLE_IN_ALL
-const char * const    *ide_run_context_get_environ        (IdeRunContext         *self);
+const char * const    *ide_run_context_get_environ             (IdeRunContext         *self);
 IDE_AVAILABLE_IN_ALL
-void                   ide_run_context_set_environ        (IdeRunContext         *self,
-                                                           const char * const    *environ);
+void                   ide_run_context_set_environ             (IdeRunContext         *self,
+                                                                const char * const    *environ);
 IDE_AVAILABLE_IN_ALL
-void                   ide_run_context_add_environ        (IdeRunContext         *self,
-                                                           const char * const    *environ);
+void                   ide_run_context_add_environ             (IdeRunContext         *self,
+                                                                const char * const    *environ);
 IDE_AVAILABLE_IN_ALL
-void                   ide_run_context_environ_to_argv    (IdeRunContext         *self);
+void                   ide_run_context_add_minimal_environment (IdeRunContext         *self);
 IDE_AVAILABLE_IN_ALL
-const char            *ide_run_context_get_cwd            (IdeRunContext         *self);
+void                   ide_run_context_environ_to_argv         (IdeRunContext         *self);
 IDE_AVAILABLE_IN_ALL
-void                   ide_run_context_set_cwd            (IdeRunContext         *self,
-                                                           const char            *cwd);
+const char            *ide_run_context_get_cwd                 (IdeRunContext         *self);
 IDE_AVAILABLE_IN_ALL
-void                   ide_run_context_set_pty_fd         (IdeRunContext         *self,
-                                                           int                    consumer_fd);
+void                   ide_run_context_set_cwd                 (IdeRunContext         *self,
+                                                                const char            *cwd);
 IDE_AVAILABLE_IN_ALL
-void                   ide_run_context_set_pty            (IdeRunContext         *self,
-                                                           VtePty                *pty);
+void                   ide_run_context_set_pty_fd              (IdeRunContext         *self,
+                                                                int                    consumer_fd);
 IDE_AVAILABLE_IN_ALL
-void                   ide_run_context_take_fd            (IdeRunContext         *self,
-                                                           int                    source_fd,
-                                                           int                    dest_fd);
+void                   ide_run_context_set_pty                 (IdeRunContext         *self,
+                                                                VtePty                *pty);
 IDE_AVAILABLE_IN_ALL
-gboolean               ide_run_context_merge_unix_fd_map  (IdeRunContext         *self,
-                                                           IdeUnixFDMap          *unix_fd_map,
-                                                           GError               **error);
+void                   ide_run_context_take_fd                 (IdeRunContext         *self,
+                                                                int                    source_fd,
+                                                                int                    dest_fd);
 IDE_AVAILABLE_IN_ALL
-void                   ide_run_context_prepend_argv       (IdeRunContext         *self,
-                                                           const char            *arg);
+gboolean               ide_run_context_merge_unix_fd_map       (IdeRunContext         *self,
+                                                                IdeUnixFDMap          *unix_fd_map,
+                                                                GError               **error);
 IDE_AVAILABLE_IN_ALL
-void                   ide_run_context_prepend_args       (IdeRunContext         *self,
-                                                           const char * const    *args);
+void                   ide_run_context_prepend_argv            (IdeRunContext         *self,
+                                                                const char            *arg);
 IDE_AVAILABLE_IN_ALL
-void                   ide_run_context_append_argv        (IdeRunContext         *self,
-                                                           const char            *arg);
+void                   ide_run_context_prepend_args            (IdeRunContext         *self,
+                                                                const char * const    *args);
 IDE_AVAILABLE_IN_ALL
-void                   ide_run_context_append_args        (IdeRunContext         *self,
-                                                           const char * const    *args);
+void                   ide_run_context_append_argv             (IdeRunContext         *self,
+                                                                const char            *arg);
 IDE_AVAILABLE_IN_ALL
-gboolean               ide_run_context_append_args_parsed (IdeRunContext         *self,
-                                                           const char            *args,
-                                                           GError               **error);
+void                   ide_run_context_append_args             (IdeRunContext         *self,
+                                                                const char * const    *args);
 IDE_AVAILABLE_IN_ALL
-void                   ide_run_context_append_formatted   (IdeRunContext         *self,
-                                                           const char            *format,
-                                                           ...) G_GNUC_PRINTF (2, 3);
+gboolean               ide_run_context_append_args_parsed      (IdeRunContext         *self,
+                                                                const char            *args,
+                                                                GError               **error);
 IDE_AVAILABLE_IN_ALL
-const char            *ide_run_context_getenv             (IdeRunContext         *self,
-                                                           const char            *key);
+void                   ide_run_context_append_formatted        (IdeRunContext         *self,
+                                                                const char            *format,
+                                                                ...) G_GNUC_PRINTF (2, 3);
 IDE_AVAILABLE_IN_ALL
-void                   ide_run_context_setenv             (IdeRunContext         *self,
-                                                           const char            *key,
-                                                           const char            *value);
+const char            *ide_run_context_getenv                  (IdeRunContext         *self,
+                                                                const char            *key);
 IDE_AVAILABLE_IN_ALL
-void                   ide_run_context_unsetenv           (IdeRunContext         *self,
-                                                           const char            *key);
+void                   ide_run_context_setenv                  (IdeRunContext         *self,
+                                                                const char            *key,
+                                                                const char            *value);
 IDE_AVAILABLE_IN_ALL
-IdeSubprocessLauncher *ide_run_context_end                (IdeRunContext         *self,
-                                                           GError               **error);
+void                   ide_run_context_unsetenv                (IdeRunContext         *self,
+                                                                const char            *key);
 IDE_AVAILABLE_IN_ALL
-IdeSubprocess         *ide_run_context_spawn              (IdeRunContext         *self,
-                                                           GError               **error);
+IdeSubprocessLauncher *ide_run_context_end                     (IdeRunContext         *self,
+                                                                GError               **error);
+IDE_AVAILABLE_IN_ALL
+IdeSubprocess         *ide_run_context_spawn                   (IdeRunContext         *self,
+                                                                GError               **error);
 
 G_END_DECLS


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