[gnome-builder] io: add helper to check host system path for program
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder] io: add helper to check host system path for program
- Date: Tue, 7 May 2019 03:55:48 +0000 (UTC)
commit 3b45211232bb389c1d32cb32fa3c0e1ea949daf9
Author: Christian Hergert <chergert redhat com>
Date: Mon May 6 20:47:18 2019 -0700
io: add helper to check host system path for program
src/libide/io/ide-path.c | 51 ++++++++++++++++++++++++++++++++++++++++++++++++
src/libide/io/ide-path.h | 2 ++
2 files changed, 53 insertions(+)
---
diff --git a/src/libide/io/ide-path.c b/src/libide/io/ide-path.c
index 89377f383..8a5626960 100644
--- a/src/libide/io/ide-path.c
+++ b/src/libide/io/ide-path.c
@@ -26,6 +26,8 @@
#include <unistd.h>
#include <wordexp.h>
+#include <libide-threading.h>
+
#include "ide-path.h"
/**
@@ -133,3 +135,52 @@ ide_path_is_cpp_like (const gchar *path)
return FALSE;
}
+
+/**
+ * ide_find_program_in_host_path:
+ * @program: the name of the executable
+ *
+ * Like g_find_program_in_path() but checks the host system which may not be
+ * the same as the container we're running within.
+ *
+ * Returns: (transfer full) (nullable): a path or %NULL
+ *
+ * Since: 3.34
+ */
+gchar *
+ide_find_program_in_host_path (const gchar *program)
+{
+ if (ide_is_flatpak ())
+ {
+ g_autoptr(IdeSubprocessLauncher) launcher = NULL;
+ g_autoptr(IdeSubprocess) subprocess = NULL;
+
+ if (program == NULL)
+ return NULL;
+
+ launcher = ide_subprocess_launcher_new (G_SUBPROCESS_FLAGS_STDOUT_PIPE |
+ G_SUBPROCESS_FLAGS_STDERR_SILENCE);
+ ide_subprocess_launcher_set_run_on_host (launcher, TRUE);
+ ide_subprocess_launcher_push_argv (launcher, "which");
+ ide_subprocess_launcher_push_argv (launcher, program);
+
+ if ((subprocess = ide_subprocess_launcher_spawn (launcher, NULL, NULL)))
+ {
+ g_autofree gchar *path = NULL;
+
+ if (ide_subprocess_communicate_utf8 (subprocess, NULL, NULL, &path, NULL, NULL))
+ {
+ g_strstrip (path);
+
+ if (!ide_str_empty0 (path))
+ return g_steal_pointer (&path);
+ }
+ }
+
+ return NULL;
+ }
+ else
+ {
+ return g_find_program_in_path (program);
+ }
+}
diff --git a/src/libide/io/ide-path.h b/src/libide/io/ide-path.h
index 5d395c828..9d7e2786d 100644
--- a/src/libide/io/ide-path.h
+++ b/src/libide/io/ide-path.h
@@ -36,5 +36,7 @@ IDE_AVAILABLE_IN_3_34
gboolean ide_path_is_c_like (const gchar *path);
IDE_AVAILABLE_IN_3_34
gboolean ide_path_is_cpp_like (const gchar *path);
+IDE_AVAILABLE_IN_3_34
+gchar *ide_find_program_in_host_path (const gchar *program);
G_END_DECLS
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]