[gnome-builder] flatpak: convert environment variables to --env= parameters
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder] flatpak: convert environment variables to --env= parameters
- Date: Sat, 29 Oct 2016 05:35:25 +0000 (UTC)
commit d87f5e64a98d0723e8c30fd9c02b88a414982a66
Author: Christian Hergert <chergert redhat com>
Date: Fri Oct 28 22:34:54 2016 -0700
flatpak: convert environment variables to --env= parameters
The "flatpak build" operation will filter out our environment variables.
So we need to convert the environ to --env=Foo=Bar parameters to the
flatpak build command.
plugins/flatpak/Makefile.am | 2 +
plugins/flatpak/gbp-flatpak-runtime.c | 6 +-
plugins/flatpak/gbp-flatpak-subprocess-launcher.c | 106 +++++++++++++++++++++
plugins/flatpak/gbp-flatpak-subprocess-launcher.h | 34 +++++++
4 files changed, 146 insertions(+), 2 deletions(-)
---
diff --git a/plugins/flatpak/Makefile.am b/plugins/flatpak/Makefile.am
index 302e6d6..be3fea1 100644
--- a/plugins/flatpak/Makefile.am
+++ b/plugins/flatpak/Makefile.am
@@ -14,6 +14,8 @@ libflatpak_plugin_la_SOURCES = \
gbp-flatpak-runtime-provider.h \
gbp-flatpak-runtime.c \
gbp-flatpak-runtime.h \
+ gbp-flatpak-subprocess-launcher.c \
+ gbp-flatpak-subprocess-launcher.h \
gbp-flatpak-plugin.c \
$(NULL)
diff --git a/plugins/flatpak/gbp-flatpak-runtime.c b/plugins/flatpak/gbp-flatpak-runtime.c
index 9597a25..39a9393 100644
--- a/plugins/flatpak/gbp-flatpak-runtime.c
+++ b/plugins/flatpak/gbp-flatpak-runtime.c
@@ -16,7 +16,10 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
+#define G_LOG_DOMAIN "gbp-flatpak-runtime"
+
#include "gbp-flatpak-runtime.h"
+#include "gbp-flatpak-subprocess-launcher.h"
struct _GbpFlatpakRuntime
{
@@ -196,7 +199,7 @@ gbp_flatpak_runtime_create_launcher (IdeRuntime *runtime,
g_return_val_if_fail (GBP_IS_FLATPAK_RUNTIME (self), NULL);
- ret = IDE_RUNTIME_CLASS (gbp_flatpak_runtime_parent_class)->create_launcher (runtime, error);
+ ret = gbp_flatpak_subprocess_launcher_new (G_SUBPROCESS_FLAGS_STDOUT_PIPE |
G_SUBPROCESS_FLAGS_STDERR_PIPE);
if (ret != NULL)
{
@@ -207,7 +210,6 @@ gbp_flatpak_runtime_create_launcher (IdeRuntime *runtime,
ide_subprocess_launcher_push_argv (ret, build_path);
ide_subprocess_launcher_set_run_on_host (ret, TRUE);
- ide_subprocess_launcher_set_clear_env (ret, FALSE);
}
return ret;
diff --git a/plugins/flatpak/gbp-flatpak-subprocess-launcher.c
b/plugins/flatpak/gbp-flatpak-subprocess-launcher.c
new file mode 100644
index 0000000..73c9cc9
--- /dev/null
+++ b/plugins/flatpak/gbp-flatpak-subprocess-launcher.c
@@ -0,0 +1,106 @@
+/* gbp-flatpak-subprocess-launcher.c
+ *
+ * Copyright (C) 2016 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/>.
+ */
+
+#define G_LOG_DOMAIN "gbp-flatpak-subprocess-launcher"
+
+#include "gbp-flatpak-subprocess-launcher.h"
+
+struct _GbpFlatpakSubprocessLauncher
+{
+ IdeSubprocessLauncher parent_instance;
+};
+
+G_DEFINE_TYPE (GbpFlatpakSubprocessLauncher, gbp_flatpak_subprocess_launcher, IDE_TYPE_SUBPROCESS_LAUNCHER)
+
+static IdeSubprocess *
+gbp_flatpak_subprocess_launcher_spawn (IdeSubprocessLauncher *launcher,
+ GCancellable *cancellable,
+ GError **error)
+{
+ const gchar * const * envp;
+ IdeSubprocess *ret;
+
+ IDE_ENTRY;
+
+ g_assert (IDE_IS_SUBPROCESS_LAUNCHER (launcher));
+ g_assert (!cancellable || G_IS_CANCELLABLE (cancellable));
+
+ /*
+ * The "flatpak build" command will filter out all of our environment variables
+ * from the subprocess. So we need to look at our configured environment and
+ * convert the KEY=VALUE pairs into --env=key=value command line arguments.
+ */
+
+ envp = ide_subprocess_launcher_get_environ (launcher);
+
+ if (envp != NULL)
+ {
+ const gchar * const * argv;
+ guint argpos = 0;
+
+ argv = ide_subprocess_launcher_get_argv (launcher);
+
+ /*
+ * Locate the position after our ["flatpak", "build"] arguments.
+ */
+ for (argpos = 0; argv[argpos] != NULL; argpos++)
+ {
+ if (strcmp (argv[argpos], "flatpak") == 0)
+ break;
+ }
+ for (; argv[argpos] != NULL; argpos++)
+ {
+ if (strcmp (argv[argpos], "build") == 0)
+ {
+ argpos++;
+ break;
+ }
+ }
+
+ for (guint i = 0; envp[i] != NULL; i++)
+ {
+ g_autofree gchar *arg = g_strdup_printf ("--env=%s", envp[i]);
+ ide_subprocess_launcher_insert_argv (launcher, argpos, arg);
+ }
+ }
+
+ ret = IDE_SUBPROCESS_LAUNCHER_CLASS (gbp_flatpak_subprocess_launcher_parent_class)->spawn (launcher,
cancellable, error);
+
+ IDE_RETURN (ret);
+}
+
+static void
+gbp_flatpak_subprocess_launcher_class_init (GbpFlatpakSubprocessLauncherClass *klass)
+{
+ IdeSubprocessLauncherClass *launcher_class = IDE_SUBPROCESS_LAUNCHER_CLASS (klass);
+
+ launcher_class->spawn = gbp_flatpak_subprocess_launcher_spawn;
+}
+
+static void
+gbp_flatpak_subprocess_launcher_init (GbpFlatpakSubprocessLauncher *self)
+{
+}
+
+IdeSubprocessLauncher *
+gbp_flatpak_subprocess_launcher_new (GSubprocessFlags flags)
+{
+ return g_object_new (GBP_TYPE_FLATPAK_SUBPROCESS_LAUNCHER,
+ "flags", flags,
+ NULL);
+}
diff --git a/plugins/flatpak/gbp-flatpak-subprocess-launcher.h
b/plugins/flatpak/gbp-flatpak-subprocess-launcher.h
new file mode 100644
index 0000000..e89a4e9
--- /dev/null
+++ b/plugins/flatpak/gbp-flatpak-subprocess-launcher.h
@@ -0,0 +1,34 @@
+/* gbp-flatpak-subprocess-launcher.h
+ *
+ * Copyright (C) 2016 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/>.
+ */
+
+#ifndef GBP_FLATPAK_SUBPROCESS_LAUNCHER_H
+#define GBP_FLATPAK_SUBPROCESS_LAUNCHER_H
+
+#include <ide.h>
+
+G_BEGIN_DECLS
+
+#define GBP_TYPE_FLATPAK_SUBPROCESS_LAUNCHER (gbp_flatpak_subprocess_launcher_get_type())
+
+G_DECLARE_FINAL_TYPE (GbpFlatpakSubprocessLauncher, gbp_flatpak_subprocess_launcher, GBP,
FLATPAK_SUBPROCESS_LAUNCHER, IdeSubprocessLauncher)
+
+IdeSubprocessLauncher *gbp_flatpak_subprocess_launcher_new (GSubprocessFlags flags);
+
+G_END_DECLS
+
+#endif /* GBP_FLATPAK_SUBPROCESS_LAUNCHER_H */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]