[gnome-builder] build-stage-launcher: log subprocess arguments



commit f6adc34f8a626b66c622a4b03754177a7f7bfdb2
Author: Christian Hergert <chergert redhat com>
Date:   Wed Jan 31 02:03:35 2018 -0800

    build-stage-launcher: log subprocess arguments
    
    When executing an IdeBuildStageLauncher, log the command
    arguments to the terminal so that the user has more insight into
    what is going on behind the scenes.

 src/libide/buildsystem/ide-build-stage-launcher.c | 62 +++++++++++++++++++++++
 1 file changed, 62 insertions(+)
---
diff --git a/src/libide/buildsystem/ide-build-stage-launcher.c 
b/src/libide/buildsystem/ide-build-stage-launcher.c
index 17e6c703d..3ab95c79d 100644
--- a/src/libide/buildsystem/ide-build-stage-launcher.c
+++ b/src/libide/buildsystem/ide-build-stage-launcher.c
@@ -46,6 +46,60 @@ G_DEFINE_TYPE_WITH_PRIVATE (IdeBuildStageLauncher, ide_build_stage_launcher, IDE
 
 static GParamSpec *properties [N_PROPS];
 
+static inline gboolean
+needs_quoting (const gchar *str)
+{
+  for (; *str; str = g_utf8_next_char (str))
+    {
+      gunichar ch = g_utf8_get_char (str);
+
+      switch (ch)
+        {
+        case '\'':
+        case '"':
+        case '\\':
+          return TRUE;
+
+        default:
+          if (g_unichar_isspace (ch))
+            return TRUE;
+          break;
+        }
+    }
+
+  return FALSE;
+}
+
+static gchar *
+pretty_print_args (IdeSubprocessLauncher *launcher)
+{
+  const gchar * const *argv;
+  g_autoptr(GString) command = NULL;
+
+  g_assert (IDE_IS_SUBPROCESS_LAUNCHER (launcher));
+
+  if (!(argv = ide_subprocess_launcher_get_argv (launcher)))
+    return NULL;
+
+  command = g_string_new (NULL);
+
+  for (guint i = 0; argv[i] != NULL; i++)
+    {
+      if (command->len > 0)
+        g_string_append_c (command, ' ');
+
+      if (needs_quoting (argv[i]))
+        {
+          g_autofree gchar *quoted = g_shell_quote (argv[i]);
+          g_string_append (command, quoted);
+        }
+      else
+        g_string_append (command, argv[i]);
+    }
+
+  return g_string_free (g_steal_pointer (&command), FALSE);
+}
+
 static void
 ide_build_stage_launcher_wait_cb (GObject      *object,
                                   GAsyncResult *result,
@@ -183,6 +237,14 @@ ide_build_stage_launcher_run (IdeBuildStage         *stage,
       ide_subprocess_launcher_set_flags (launcher, flags);
     }
 
+  if (priv->use_pty)
+    {
+      g_autofree gchar *command = pretty_print_args (launcher);
+
+      if (command != NULL)
+        ide_build_stage_log (IDE_BUILD_STAGE (self), IDE_BUILD_LOG_STDOUT, command, -1);
+    }
+
   /* Now launch the process */
 
   subprocess = ide_subprocess_launcher_spawn (launcher, cancellable, &error);


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