[gnome-builder] libide/foundry: use -l instead of --login for shells



commit cf2e8ee01c973b754636a0fd8bc73018add02f77
Author: Christian Hergert <chergert redhat com>
Date:   Wed Sep 14 12:49:46 2022 -0700

    libide/foundry: use -l instead of --login for shells
    
    It's more widely supported in the shells we want to support.
    
    Fixes #1786

 src/libide/foundry/ide-run-context.c           |  2 +-
 src/libide/io/ide-shell.c                      | 20 ++++++++++++++++++++
 src/libide/terminal/ide-terminal-run-command.c |  8 ++++----
 src/plugins/gopls/gbp-gopls-service.c          |  2 +-
 src/plugins/jhbuild/gbp-jhbuild-runtime.c      |  2 +-
 src/tests/test-run-context.c                   |  2 +-
 6 files changed, 28 insertions(+), 8 deletions(-)
---
diff --git a/src/libide/foundry/ide-run-context.c b/src/libide/foundry/ide-run-context.c
index 2378d395c..121cd3072 100644
--- a/src/libide/foundry/ide-run-context.c
+++ b/src/libide/foundry/ide-run-context.c
@@ -366,7 +366,7 @@ ide_run_context_shell_handler (IdeRunContext       *self,
 
   ide_run_context_append_argv (self, "/bin/sh");
   if (login)
-    ide_run_context_append_argv (self, "--login");
+    ide_run_context_append_argv (self, "-l");
   ide_run_context_append_argv (self, "-c");
 
   str = g_string_new (NULL);
diff --git a/src/libide/io/ide-shell.c b/src/libide/io/ide-shell.c
index b188167cd..77e141206 100644
--- a/src/libide/io/ide-shell.c
+++ b/src/libide/io/ide-shell.c
@@ -38,9 +38,21 @@ ide_shell_supports_dash_c (const char *shell)
   return strcmp (shell, "bash") == 0 || g_str_has_suffix (shell, "/bash") ||
          strcmp (shell, "fish") == 0 || g_str_has_suffix (shell, "/fish") ||
          strcmp (shell, "zsh") == 0 || g_str_has_suffix (shell, "/zsh") ||
+         strcmp (shell, "dash") == 0 || g_str_has_suffix (shell, "/dash") ||
+         strcmp (shell, "tcsh") == 0 || g_str_has_suffix (shell, "/tcsh") ||
          strcmp (shell, "sh") == 0 || g_str_has_suffix (shell, "/sh");
 }
 
+/**
+ * ide_shell_supports_dash_login:
+ * @shell: the name of the shell, such as `sh` or `/bin/sh`
+ *
+ * Checks if the shell is known to support login semantics. Originally,
+ * this meant `--login`, but now is meant to mean `-l` as more shells
+ * support `-l` than `--login` (notably dash).
+ *
+ * Returns: %TRUE if @shell likely supports `-l`.
+ */
 gboolean
 ide_shell_supports_dash_login (const char *shell)
 {
@@ -50,6 +62,14 @@ ide_shell_supports_dash_login (const char *shell)
   return strcmp (shell, "bash") == 0 || g_str_has_suffix (shell, "/bash") ||
          strcmp (shell, "fish") == 0 || g_str_has_suffix (shell, "/fish") ||
          strcmp (shell, "zsh") == 0 || g_str_has_suffix (shell, "/zsh") ||
+         strcmp (shell, "dash") == 0 || g_str_has_suffix (shell, "/dash") ||
+#if 0
+         /* tcsh supports -l and -c but not combined! To do that, you'd have
+          * to instead launch the login shell like `-tcsh -c 'command'`, which
+          * is possible, but we lack the abstractions for that currently.
+          */
+         strcmp (shell, "tcsh") == 0 || g_str_has_suffix (shell, "/tcsh") ||
+#endif
          strcmp (shell, "sh") == 0 || g_str_has_suffix (shell, "/sh");
 }
 
diff --git a/src/libide/terminal/ide-terminal-run-command.c b/src/libide/terminal/ide-terminal-run-command.c
index 1f37c3a59..73751f5ed 100644
--- a/src/libide/terminal/ide-terminal-run-command.c
+++ b/src/libide/terminal/ide-terminal-run-command.c
@@ -63,7 +63,7 @@ ide_terminal_run_command_prepare_to_run (IdeRunCommand *run_command,
       ide_run_context_add_minimal_environment (run_context);
       ide_run_context_append_argv (run_context, user_shell);
       if (ide_shell_supports_dash_login (user_shell))
-        ide_run_context_append_argv (run_context, "--login");
+        ide_run_context_append_argv (run_context, "-l");
       break;
 
     case IDE_TERMINAL_RUN_AS_SUBPROCESS:
@@ -72,12 +72,12 @@ ide_terminal_run_command_prepare_to_run (IdeRunCommand *run_command,
         {
           ide_run_context_append_argv (run_context, user_shell);
           if (ide_shell_supports_dash_login (user_shell))
-            ide_run_context_append_argv (run_context, "--login");
+            ide_run_context_append_argv (run_context, "-l");
         }
       else
         {
           ide_run_context_append_argv (run_context, "/bin/sh");
-          ide_run_context_append_argv (run_context, "--login");
+          ide_run_context_append_argv (run_context, "-l");
         }
       break;
 
@@ -110,7 +110,7 @@ ide_terminal_run_command_prepare_to_run (IdeRunCommand *run_command,
 
         ide_run_context_append_argv (run_context, user_shell);
         if (ide_shell_supports_dash_login (user_shell))
-          ide_run_context_append_argv (run_context, "--login");
+          ide_run_context_append_argv (run_context, "-l");
       }
       break;
 
diff --git a/src/plugins/gopls/gbp-gopls-service.c b/src/plugins/gopls/gbp-gopls-service.c
index 8e8095507..e5c2f276a 100644
--- a/src/plugins/gopls/gbp-gopls-service.c
+++ b/src/plugins/gopls/gbp-gopls-service.c
@@ -90,7 +90,7 @@ gbp_gopls_service_configure_launcher (IdeLspService         *service,
 
       quoted = g_strjoinv (" ", (char **)(gpointer)ar->pdata);
       ide_subprocess_launcher_set_argv (launcher,
-                                        IDE_STRV_INIT (user_shell, "--login", "-c", quoted));
+                                        IDE_STRV_INIT (user_shell, "-l", "-c", quoted));
     }
 
   IDE_EXIT;
diff --git a/src/plugins/jhbuild/gbp-jhbuild-runtime.c b/src/plugins/jhbuild/gbp-jhbuild-runtime.c
index ece74570a..115dac836 100644
--- a/src/plugins/jhbuild/gbp-jhbuild-runtime.c
+++ b/src/plugins/jhbuild/gbp-jhbuild-runtime.c
@@ -133,7 +133,7 @@ gbp_jhbuild_runtime_contains_program_in_path (IdeRuntime   *runtime,
                         g_object_ref (self),
                         g_object_unref);
 
-  /* Will use /bin/sh --login -c 'which program' */
+  /* Will use /bin/sh -l -c 'which program' */
   ide_run_context_push_shell (run_context, TRUE);
   ide_run_context_append_argv (run_context, "which");
   ide_run_context_append_argv (run_context, program);
diff --git a/src/tests/test-run-context.c b/src/tests/test-run-context.c
index 676d5cb8e..386a91c87 100644
--- a/src/tests/test-run-context.c
+++ b/src/tests/test-run-context.c
@@ -217,7 +217,7 @@ test_run_context_push_shell (void)
   g_assert_nonnull (launcher);
 
   g_assert_true (g_strv_equal (ide_subprocess_launcher_get_argv (launcher),
-                               IDE_STRV_INIT ("/bin/sh", "--login", "-c", "env 'PATH=path' 'which' 'foo'")));
+                               IDE_STRV_INIT ("/bin/sh", "-l", "-c", "env 'PATH=path' 'which' 'foo'")));
 
   g_assert_finalize_object (launcher);
   g_assert_finalize_object (run_context);


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