[gnome-builder/wip/chergert/fix-rust-analyzer-on-host: 3/4] runtime: use user shell for locating program with which
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder/wip/chergert/fix-rust-analyzer-on-host: 3/4] runtime: use user shell for locating program with which
- Date: Sun, 26 Dec 2021 22:44:09 +0000 (UTC)
commit 7286cd2a004739955c626663f9cf4057472de8b7
Author: Christian Hergert <chergert redhat com>
Date: Sun Dec 26 14:32:26 2021 -0800
runtime: use user shell for locating program with which
This has to use the API with some special handling because we don't yet
have access to the libide-terminal (it requires libide-gui first).
It tries to use something like `bash --login -c 'which $program'` so that
we have the potential to discover where the binary is, even with an
alternate $PATH set by the user's shell.
Related #1384
src/libide/foundry/ide-runtime.c | 26 +++++++++++++++++++++++---
src/plugins/meson/meson.build | 2 +-
2 files changed, 24 insertions(+), 4 deletions(-)
---
diff --git a/src/libide/foundry/ide-runtime.c b/src/libide/foundry/ide-runtime.c
index 894762c4d..92935b6a4 100644
--- a/src/libide/foundry/ide-runtime.c
+++ b/src/libide/foundry/ide-runtime.c
@@ -24,9 +24,15 @@
#include <dazzle.h>
#include <glib/gi18n.h>
-#include <libide-threading.h>
#include <string.h>
+#include <libide-io.h>
+#include <libide-threading.h>
+
+#define IDE_TERMINAL_INSIDE
+# include "../terminal/ide-terminal-util.h"
+#undef IDE_TERMINAL_INSIDE
+
#include "ide-build-target.h"
#include "ide-config.h"
#include "ide-config-manager.h"
@@ -114,10 +120,24 @@ ide_runtime_real_contains_program_in_path (IdeRuntime *self,
if (NULL != (launcher = ide_runtime_create_launcher (self, NULL)))
{
g_autoptr(IdeSubprocess) subprocess = NULL;
+ g_autofree char *escaped = g_shell_quote (program);
+ g_autofree char *command = g_strdup_printf ("which %s", escaped);
+ const char *user_shell = ide_get_user_shell ();
ide_subprocess_launcher_set_run_on_host (launcher, TRUE);
- ide_subprocess_launcher_push_argv (launcher, "which");
- ide_subprocess_launcher_push_argv (launcher, program);
+
+ /* Try to get a real PATH by using the preferred shell */
+ if (ide_shell_supports_dash_c (user_shell))
+ ide_subprocess_launcher_push_argv (launcher, user_shell);
+ else
+ ide_subprocess_launcher_push_argv (launcher, "sh");
+
+ /* Try a login shell as well to improve reliability */
+ if (ide_shell_supports_dash_login (user_shell))
+ ide_subprocess_launcher_push_argv (launcher, "--login");
+
+ ide_subprocess_launcher_push_argv (launcher, "-c");
+ ide_subprocess_launcher_push_argv (launcher, command);
if (NULL != (subprocess = ide_subprocess_launcher_spawn (launcher, cancellable, NULL)))
return ide_subprocess_wait_check (subprocess, NULL, NULL);
diff --git a/src/plugins/meson/meson.build b/src/plugins/meson/meson.build
index eb30d3a1a..f5161cc07 100644
--- a/src/plugins/meson/meson.build
+++ b/src/plugins/meson/meson.build
@@ -36,7 +36,7 @@ test_sources += files([
test_meson = executable('test-meson', test_sources,
c_args: test_cflags,
- dependencies: [ libide_foundry_dep ],
+ dependencies: [ libide_foundry_dep, libide_terminal_dep ],
)
test('test-meson', test_meson, env: test_env)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]