[gnome-builder] flatpak: allow using subprocess launcher without project
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder] flatpak: allow using subprocess launcher without project
- Date: Thu, 2 May 2019 00:52:59 +0000 (UTC)
commit e0f03a15d7438906b1fe325551fffcdd15cfc703
Author: Christian Hergert <chergert redhat com>
Date: Wed May 1 17:51:09 2019 -0700
flatpak: allow using subprocess launcher without project
We would like to be able to have runtimes available without a project so
that they can be reused in a context for terminal access. To do this, we
need to remove the reliance on a current pipeline.
src/plugins/flatpak/gbp-flatpak-runtime.c | 19 +++++-
.../flatpak/gbp-flatpak-subprocess-launcher.c | 74 +++++++++++++++++++++-
.../flatpak/gbp-flatpak-subprocess-launcher.h | 4 +-
3 files changed, 90 insertions(+), 7 deletions(-)
---
diff --git a/src/plugins/flatpak/gbp-flatpak-runtime.c b/src/plugins/flatpak/gbp-flatpak-runtime.c
index f219f880f..a559b6e3e 100644
--- a/src/plugins/flatpak/gbp-flatpak-runtime.c
+++ b/src/plugins/flatpak/gbp-flatpak-runtime.c
@@ -161,12 +161,27 @@ gbp_flatpak_runtime_create_launcher (IdeRuntime *runtime,
{
IdeSubprocessLauncher *ret;
GbpFlatpakRuntime *self = (GbpFlatpakRuntime *)runtime;
+ g_autoptr(IdeContext) context = NULL;
+ const gchar *runtime_id;
g_return_val_if_fail (GBP_IS_FLATPAK_RUNTIME (self), NULL);
+ context = ide_object_ref_context (IDE_OBJECT (self));
+ g_return_val_if_fail (IDE_IS_CONTEXT (context), NULL);
+
+ runtime_id = ide_runtime_get_id (runtime);
+ g_return_val_if_fail (g_str_has_prefix (runtime_id, "flatpak:"), NULL);
+
ret = gbp_flatpak_subprocess_launcher_new (G_SUBPROCESS_FLAGS_STDOUT_PIPE |
G_SUBPROCESS_FLAGS_STDERR_PIPE);
- if (ret != NULL)
+ if (ret != NULL && !ide_context_has_project (context))
+ {
+ ide_subprocess_launcher_set_cwd (ret, g_get_home_dir ());
+ ide_subprocess_launcher_set_run_on_host (ret, TRUE);
+ gbp_flatpak_subprocess_launcher_use_run (GBP_FLATPAK_SUBPROCESS_LAUNCHER (ret),
+ runtime_id + strlen ("flatpak:"));
+ }
+ else if (ret != NULL)
{
g_autofree gchar *build_path = NULL;
g_autofree gchar *ccache_dir = NULL;
@@ -175,11 +190,9 @@ gbp_flatpak_runtime_create_launcher (IdeRuntime *runtime,
const gchar *project_path = NULL;
const gchar * const *build_args = NULL;
g_autoptr(IdeConfigManager) config_manager = NULL;
- g_autoptr(IdeContext) context = NULL;
IdeConfig *configuration;
IdeVcs *vcs;
- context = ide_object_ref_context (IDE_OBJECT (self));
config_manager = ide_config_manager_ref_from_context (context);
configuration = ide_config_manager_ref_current (config_manager);
diff --git a/src/plugins/flatpak/gbp-flatpak-subprocess-launcher.c
b/src/plugins/flatpak/gbp-flatpak-subprocess-launcher.c
index 7cd275db6..b1d9f1ad6 100644
--- a/src/plugins/flatpak/gbp-flatpak-subprocess-launcher.c
+++ b/src/plugins/flatpak/gbp-flatpak-subprocess-launcher.c
@@ -25,6 +25,8 @@
struct _GbpFlatpakSubprocessLauncher
{
IdeSubprocessLauncher parent_instance;
+ gchar *ref;
+ guint use_run : 1;
};
G_DEFINE_TYPE (GbpFlatpakSubprocessLauncher, gbp_flatpak_subprocess_launcher, IDE_TYPE_SUBPROCESS_LAUNCHER)
@@ -34,17 +36,52 @@ gbp_flatpak_subprocess_launcher_spawn (IdeSubprocessLauncher *launcher,
GCancellable *cancellable,
GError **error)
{
+ GbpFlatpakSubprocessLauncher *self = (GbpFlatpakSubprocessLauncher *)launcher;
+ g_autofree gchar *build_dir_option = NULL;
const gchar * const * envp;
- IdeSubprocess *ret;
const gchar * const * argv;
+ IdeSubprocess *ret;
guint argpos = 0;
- g_autofree gchar *build_dir_option = NULL;
IDE_ENTRY;
- g_assert (IDE_IS_SUBPROCESS_LAUNCHER (launcher));
+ g_assert (GBP_IS_FLATPAK_SUBPROCESS_LAUNCHER (self));
g_assert (!cancellable || G_IS_CANCELLABLE (cancellable));
+ if (self->use_run)
+ {
+ g_autofree gchar *newval = NULL;
+ const gchar *oldval;
+ guint savepos;
+
+ ide_subprocess_launcher_insert_argv (launcher, argpos++, "flatpak");
+ ide_subprocess_launcher_insert_argv (launcher, argpos++, "run");
+ ide_subprocess_launcher_insert_argv (launcher, argpos++, "--allow=devel");
+ ide_subprocess_launcher_insert_argv (launcher, argpos++, "--device=dri");
+ ide_subprocess_launcher_insert_argv (launcher, argpos++, "--filesystem=home");
+ ide_subprocess_launcher_insert_argv (launcher, argpos++, "--share=ipc");
+ ide_subprocess_launcher_insert_argv (launcher, argpos++, "--share=network");
+ ide_subprocess_launcher_insert_argv (launcher, argpos++, "--socket=wayland");
+ ide_subprocess_launcher_insert_argv (launcher, argpos++, "--socket=fallback-x11");
+ ide_subprocess_launcher_insert_argv (launcher, argpos++, "--socket=pulseaudio");
+ ide_subprocess_launcher_insert_argv (launcher, argpos++, "--socket=system-bus");
+ ide_subprocess_launcher_insert_argv (launcher, argpos++, "--socket=session-bus");
+ ide_subprocess_launcher_insert_argv (launcher, argpos++, "--socket=ssh-auth");
+#if 0
+ ide_subprocess_launcher_insert_argv (launcher, argpos++, "--verbose");
+#endif
+
+ savepos = argpos;
+
+ oldval = ide_subprocess_launcher_get_arg (launcher, argpos);
+ newval = g_strdup_printf ("--command=%s", oldval);
+ ide_subprocess_launcher_replace_argv (launcher, argpos++, newval);
+ ide_subprocess_launcher_insert_argv (launcher, argpos++, self->ref);
+
+ argpos = savepos;
+
+ goto apply_env;
+ }
/*
* The "flatpak build" command will filter out all of our environment variables
@@ -83,6 +120,8 @@ gbp_flatpak_subprocess_launcher_spawn (IdeSubprocessLauncher *launcher,
if (!g_strv_contains (argv, build_dir_option))
ide_subprocess_launcher_insert_argv (launcher, argpos, build_dir_option);
+apply_env:
+
envp = ide_subprocess_launcher_get_environ (launcher);
if (envp != NULL)
@@ -102,15 +141,30 @@ gbp_flatpak_subprocess_launcher_spawn (IdeSubprocessLauncher *launcher,
ide_subprocess_launcher_setenv (launcher, "PATH", NULL, TRUE);
}
+ g_print ("%s\n", g_strjoinv (" ", (gchar **)ide_subprocess_launcher_get_argv (launcher)));
+
ret = IDE_SUBPROCESS_LAUNCHER_CLASS (gbp_flatpak_subprocess_launcher_parent_class)->spawn (launcher,
cancellable, error);
IDE_RETURN (ret);
}
+static void
+gbp_flatpak_subprocess_launcher_finalize (GObject *object)
+{
+ GbpFlatpakSubprocessLauncher *self = (GbpFlatpakSubprocessLauncher *)object;
+
+ g_clear_pointer (&self->ref, g_free);
+
+ G_OBJECT_CLASS (gbp_flatpak_subprocess_launcher_parent_class)->finalize (object);
+}
+
static void
gbp_flatpak_subprocess_launcher_class_init (GbpFlatpakSubprocessLauncherClass *klass)
{
IdeSubprocessLauncherClass *launcher_class = IDE_SUBPROCESS_LAUNCHER_CLASS (klass);
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+ object_class->finalize = gbp_flatpak_subprocess_launcher_finalize;
launcher_class->spawn = gbp_flatpak_subprocess_launcher_spawn;
}
@@ -128,3 +182,17 @@ gbp_flatpak_subprocess_launcher_new (GSubprocessFlags flags)
"flags", flags,
NULL);
}
+
+void
+gbp_flatpak_subprocess_launcher_use_run (GbpFlatpakSubprocessLauncher *self,
+ const gchar *ref)
+{
+ g_return_if_fail (GBP_IS_FLATPAK_SUBPROCESS_LAUNCHER (self));
+ g_return_if_fail (ref != NULL);
+ g_return_if_fail (self->ref == NULL);
+
+ self->use_run = TRUE;
+ self->ref = g_strdup (ref);
+
+ ide_subprocess_launcher_set_argv (IDE_SUBPROCESS_LAUNCHER (self), NULL);
+}
diff --git a/src/plugins/flatpak/gbp-flatpak-subprocess-launcher.h
b/src/plugins/flatpak/gbp-flatpak-subprocess-launcher.h
index 4536d8054..e918d2631 100644
--- a/src/plugins/flatpak/gbp-flatpak-subprocess-launcher.h
+++ b/src/plugins/flatpak/gbp-flatpak-subprocess-launcher.h
@@ -28,6 +28,8 @@ G_BEGIN_DECLS
G_DECLARE_FINAL_TYPE (GbpFlatpakSubprocessLauncher, gbp_flatpak_subprocess_launcher, GBP,
FLATPAK_SUBPROCESS_LAUNCHER, IdeSubprocessLauncher)
-IdeSubprocessLauncher *gbp_flatpak_subprocess_launcher_new (GSubprocessFlags flags);
+IdeSubprocessLauncher *gbp_flatpak_subprocess_launcher_new (GSubprocessFlags flags);
+void gbp_flatpak_subprocess_launcher_use_run (GbpFlatpakSubprocessLauncher *self,
+ const gchar *ref);
G_END_DECLS
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]