[gnome-builder/wip/tingping/runner: 2/3] IdeRunner: Implement ability to set env vars
- From: Patrick Griffis <pgriffis src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder/wip/tingping/runner: 2/3] IdeRunner: Implement ability to set env vars
- Date: Tue, 23 Aug 2016 23:00:23 +0000 (UTC)
commit a69951ec593b106e55e540a7fa2c9de4b7e8cf85
Author: Patrick Griffis <tingping tingping se>
Date: Tue Aug 23 18:24:34 2016 -0400
IdeRunner: Implement ability to set env vars
libide/runner/ide-runner.c | 35 +++++++++++++++++++++++++++++++++++
libide/runner/ide-runner.h | 2 ++
2 files changed, 37 insertions(+), 0 deletions(-)
---
diff --git a/libide/runner/ide-runner.c b/libide/runner/ide-runner.c
index eb26208..9c63f2b 100644
--- a/libide/runner/ide-runner.c
+++ b/libide/runner/ide-runner.c
@@ -33,6 +33,7 @@ typedef struct
{
PeasExtensionSet *addins;
GQueue argv;
+ IdeEnvironment *env;
} IdeRunnerPrivate;
typedef struct
@@ -44,6 +45,7 @@ typedef struct
enum {
PROP_0,
PROP_ARGV,
+ PROP_ENV,
N_PROPS
};
@@ -141,6 +143,7 @@ ide_runner_real_run_async (IdeRunner *self,
g_autoptr(GTask) task = NULL;
g_autoptr(IdeSubprocessLauncher) launcher = NULL;
g_autoptr(GSubprocess) subprocess = NULL;
+ g_auto(GStrv) environ = NULL;
const gchar *identifier;
GError *error = NULL;
@@ -154,6 +157,10 @@ ide_runner_real_run_async (IdeRunner *self,
launcher = ide_subprocess_launcher_new (G_SUBPROCESS_FLAGS_STDOUT_PIPE);
+ environ = g_get_environ (); /* We still rely on many system vars like DISPLAY */
+ ide_subprocess_launcher_set_environ (launcher, (const gchar * const *)environ);
+ ide_subprocess_launcher_overlay_environment (launcher, priv->env);
+
for (GList *iter = priv->argv.head; iter != NULL; iter = iter->next)
ide_subprocess_launcher_push_argv (launcher, iter->data);
@@ -264,6 +271,7 @@ ide_runner_finalize (GObject *object)
g_queue_foreach (&priv->argv, (GFunc)g_free, NULL);
g_queue_clear (&priv->argv);
+ g_clear_object (&priv->env);
G_OBJECT_CLASS (ide_runner_parent_class)->finalize (object);
}
@@ -282,6 +290,10 @@ ide_runner_get_property (GObject *object,
g_value_take_boxed (value, ide_runner_get_argv (self));
break;
+ case PROP_ENV:
+ g_value_set_object (value, ide_runner_get_environment (self));
+ break;
+
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
}
@@ -326,6 +338,13 @@ ide_runner_class_init (IdeRunnerClass *klass)
G_TYPE_STRV,
(G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS));
+ properties [PROP_ENV] =
+ g_param_spec_object ("environment",
+ "Environment",
+ "The environment variables for the command",
+ IDE_TYPE_ENVIRONMENT,
+ (G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
+
g_object_class_install_properties (object_class, N_PROPS, properties);
signals [SPAWNED] =
@@ -347,6 +366,7 @@ ide_runner_init (IdeRunner *self)
IdeRunnerPrivate *priv = ide_runner_get_instance_private (self);
g_queue_init (&priv->argv);
+ priv->env = ide_environment_new ();
}
/**
@@ -418,6 +438,21 @@ ide_runner_set_argv (IdeRunner *self,
}
/**
+ * ide_runner_get_environment:
+ *
+ * Returns: (transfer none): The #IdeEnvironment the process launched uses.
+ */
+IdeEnvironment *
+ide_runner_get_environment (IdeRunner *self)
+{
+ IdeRunnerPrivate *priv = ide_runner_get_instance_private (self);
+
+ g_return_val_if_fail (IDE_IS_RUNNER (self), NULL);
+
+ return priv->env;
+}
+
+/**
* ide_runner_get_argv:
*
* Gets the argument list as a newly allocated string array.
diff --git a/libide/runner/ide-runner.h b/libide/runner/ide-runner.h
index 39ac41f..74f4cd3 100644
--- a/libide/runner/ide-runner.h
+++ b/libide/runner/ide-runner.h
@@ -22,6 +22,7 @@
#include <gio/gio.h>
#include "ide-object.h"
+#include "buildsystem/ide-environment.h"
G_BEGIN_DECLS
@@ -62,6 +63,7 @@ void ide_runner_append_argv (IdeRunner *self,
gchar **ide_runner_get_argv (IdeRunner *self);
void ide_runner_set_argv (IdeRunner *self,
const gchar * const *argv);
+IdeEnvironment *ide_runner_get_environment(IdeRunner *self);
GInputStream *ide_runner_get_stdin (IdeRunner *self);
GOutputStream *ide_runner_get_stdout (IdeRunner *self);
GOutputStream *ide_runner_get_stderr (IdeRunner *self);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]