[gnome-builder] runtime: check host system for binaries under flatpak



commit 8e513ae2b44b51b211bab1bb0064c62a14c75bb0
Author: Christian Hergert <chergert redhat com>
Date:   Sun Mar 12 19:36:39 2017 -0700

    runtime: check host system for binaries under flatpak
    
    If we are the "host" runtime, we want to check the host system for binaries
    rather than inside the flatpak mount namespace. To do this, we can just
    defer to `which` on the host, accessiable via the breakout subprocess.

 libide/runtimes/ide-runtime.c |   41 ++++++++++++++++++++++++++++++++++-------
 1 files changed, 34 insertions(+), 7 deletions(-)
---
diff --git a/libide/runtimes/ide-runtime.c b/libide/runtimes/ide-runtime.c
index 0e5294f..516068a 100644
--- a/libide/runtimes/ide-runtime.c
+++ b/libide/runtimes/ide-runtime.c
@@ -24,6 +24,9 @@
 #include "buildsystem/ide-configuration.h"
 #include "projects/ide-project.h"
 #include "runtimes/ide-runtime.h"
+#include "subprocess/ide-subprocess.h"
+#include "subprocess/ide-subprocess-launcher.h"
+#include "util/ide-flatpak.h"
 
 typedef struct
 {
@@ -75,18 +78,42 @@ ide_runtime_real_contains_program_in_path (IdeRuntime   *self,
                                            const gchar  *program,
                                            GCancellable *cancellable)
 {
-  gchar *path;
-  gboolean ret;
-
   g_assert (IDE_IS_RUNTIME (self));
   g_assert (program != NULL);
   g_assert (!cancellable || G_IS_CANCELLABLE (cancellable));
 
-  path = g_find_program_in_path (program);
-  ret = path != NULL;
-  g_free (path);
+  if (!ide_is_flatpak ())
+    {
+      g_autofree gchar *path = NULL;
+      path = g_find_program_in_path (program);
+      return path != NULL;
+    }
+  else
+    {
+      g_autoptr(IdeSubprocessLauncher) launcher = NULL;
 
-  return ret;
+      /*
+       * If we are in flatpak, we have to execute a program on the host to
+       * determine if there is a program available, as we cannot resolve
+       * file paths from inside the mount namespace.
+       */
+
+      if (NULL != (launcher = ide_runtime_create_launcher (self, NULL)))
+        {
+          g_autoptr(IdeSubprocess) subprocess = NULL;
+
+          ide_subprocess_launcher_set_run_on_host (launcher, TRUE);
+          ide_subprocess_launcher_push_argv (launcher, "which");
+          ide_subprocess_launcher_push_argv (launcher, program);
+
+          if (NULL != (subprocess = ide_subprocess_launcher_spawn (launcher, cancellable, NULL)))
+            return ide_subprocess_wait_check (subprocess, NULL, NULL);
+        }
+
+      return FALSE;
+    }
+
+  g_assert_not_reached ();
 }
 
 gboolean


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