[gnome-builder] flatpak: be more flexible in runner creation



commit 87346392e8fa94ff44ed1a50824ee5d3daee740b
Author: Christian Hergert <chergert redhat com>
Date:   Tue Aug 6 14:49:37 2019 -0700

    flatpak: be more flexible in runner creation
    
    We need to be more flexible here so that we can provide alternate binaries
    to be executed and have things work as expected. Doing this improves the
    use case for terminal processes via the runner interface.

 src/plugins/flatpak/gbp-flatpak-runner.c  | 35 ++++++++++++++++++++++---------
 src/plugins/flatpak/gbp-flatpak-runner.h  |  7 ++++---
 src/plugins/flatpak/gbp-flatpak-runtime.c | 31 +--------------------------
 3 files changed, 30 insertions(+), 43 deletions(-)
---
diff --git a/src/plugins/flatpak/gbp-flatpak-runner.c b/src/plugins/flatpak/gbp-flatpak-runner.c
index 7da47f454..c74a7eeb2 100644
--- a/src/plugins/flatpak/gbp-flatpak-runner.c
+++ b/src/plugins/flatpak/gbp-flatpak-runner.c
@@ -35,7 +35,7 @@ struct _GbpFlatpakRunner
   IdeRunner parent_instance;
 
   gchar *build_path;
-  gchar *binary_path;
+  gchar *manifest_command;
 };
 
 G_DEFINE_TYPE (GbpFlatpakRunner, gbp_flatpak_runner, IDE_TYPE_RUNNER)
@@ -180,23 +180,38 @@ gbp_flatpak_runner_fixup_launcher (IdeRunner             *runner,
 }
 
 GbpFlatpakRunner *
-gbp_flatpak_runner_new (IdeContext  *context,
-                        const gchar *build_path,
-                        const gchar *binary_path)
+gbp_flatpak_runner_new (IdeContext     *context,
+                        const gchar    *build_path,
+                        IdeBuildTarget *build_target,
+                        const gchar    *manifest_command)
 {
   GbpFlatpakRunner *self;
 
   g_return_val_if_fail (IDE_IS_CONTEXT (context), NULL);
+  g_return_val_if_fail (!build_target || IDE_IS_BUILD_TARGET (build_target), NULL);
 
   self = g_object_new (GBP_TYPE_FLATPAK_RUNNER, NULL);
+  self->build_path = g_strdup (build_path);
+  self->manifest_command = g_strdup (manifest_command);
+
+  if (build_target == NULL)
+    {
+      ide_runner_append_argv (IDE_RUNNER (self), manifest_command);
+    }
+  else
+    {
+      g_auto(GStrv) argv = ide_build_target_get_argv (build_target);
 
-  if (binary_path != NULL)
-    ide_runner_append_argv (IDE_RUNNER (self), binary_path);
+      if (argv != NULL)
+        {
+          for (guint i = 0; argv[i]; i++)
+            ide_runner_append_argv (IDE_RUNNER (self), argv[i]);
+        }
 
-  self->build_path = g_strdup (build_path);
-  self->binary_path = g_strdup (binary_path);
+      ide_runner_set_build_target (IDE_RUNNER (self), build_target);
+    }
 
-  return self;
+  return g_steal_pointer (&self);
 }
 
 static void
@@ -205,7 +220,7 @@ gbp_flatpak_runner_finalize (GObject *object)
   GbpFlatpakRunner *self = (GbpFlatpakRunner *)object;
 
   g_clear_pointer (&self->build_path, g_free);
-  g_clear_pointer (&self->binary_path, g_free);
+  g_clear_pointer (&self->manifest_command, g_free);
 
   G_OBJECT_CLASS (gbp_flatpak_runner_parent_class)->finalize (object);
 }
diff --git a/src/plugins/flatpak/gbp-flatpak-runner.h b/src/plugins/flatpak/gbp-flatpak-runner.h
index 0f7d226fd..a7e5eaeea 100644
--- a/src/plugins/flatpak/gbp-flatpak-runner.h
+++ b/src/plugins/flatpak/gbp-flatpak-runner.h
@@ -28,8 +28,9 @@ G_BEGIN_DECLS
 
 G_DECLARE_FINAL_TYPE (GbpFlatpakRunner, gbp_flatpak_runner, GBP, FLATPAK_RUNNER, IdeRunner)
 
-GbpFlatpakRunner *gbp_flatpak_runner_new (IdeContext  *context,
-                                          const gchar *build_path,
-                                          const gchar *binary_name);
+GbpFlatpakRunner *gbp_flatpak_runner_new (IdeContext     *context,
+                                          const gchar    *build_path,
+                                          IdeBuildTarget *build_target,
+                                          const gchar    *manifest_command);
 
 G_END_DECLS
diff --git a/src/plugins/flatpak/gbp-flatpak-runtime.c b/src/plugins/flatpak/gbp-flatpak-runtime.c
index 9b86647e7..630cac83b 100644
--- a/src/plugins/flatpak/gbp-flatpak-runtime.c
+++ b/src/plugins/flatpak/gbp-flatpak-runtime.c
@@ -242,23 +242,6 @@ gbp_flatpak_runtime_create_launcher (IdeRuntime  *runtime,
   return ret;
 }
 
-static gboolean
-is_a_shell (const gchar *str)
-{
-  static const gchar *suffixes[] = { "/bash", "/sh", "/dash", "/zsh" };
-
-  if (str)
-    {
-      for (guint i = 0; i < G_N_ELEMENTS (suffixes); i++)
-        {
-          if (g_str_has_suffix (str, suffixes[i]))
-            return TRUE;
-        }
-    }
-
-  return FALSE;
-}
-
 static gchar *
 get_binary_name (GbpFlatpakRuntime *self,
                  IdeBuildTarget    *build_target)
@@ -267,15 +250,6 @@ get_binary_name (GbpFlatpakRuntime *self,
   IdeConfigManager *config_manager = ide_config_manager_from_context (context);
   IdeConfig *config = ide_config_manager_get_current (config_manager);
   g_autofree gchar *build_target_name = ide_build_target_get_name (build_target);
-  g_auto(GStrv) argv = ide_build_target_get_argv (build_target);
-
-  /* XXX: temporary workaround while we come up with how to
-   *      spawn shells in the mount namespace appropriately.
-   */
-  if (is_a_shell (build_target_name))
-    return g_steal_pointer (&build_target_name);
-  else if (argv && is_a_shell (argv[0]))
-    return g_strdup (argv[0]);
 
   if (GBP_IS_FLATPAK_MANIFEST (config))
     {
@@ -313,12 +287,9 @@ gbp_flatpak_runtime_create_runner (IdeRuntime     *runtime,
   if (build_target != NULL)
     binary_name = get_binary_name (self, build_target);
 
-  if ((runner = IDE_RUNNER (gbp_flatpak_runner_new (context, build_path, binary_name))))
+  if ((runner = IDE_RUNNER (gbp_flatpak_runner_new (context, build_path, build_target, binary_name))))
     ide_object_append (IDE_OBJECT (self), IDE_OBJECT (runner));
 
-  if (build_target != NULL)
-    ide_runner_set_build_target (runner, build_target);
-
   return runner;
 }
 


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