[gnome-builder/wip/slaf/colored-build-output] build-panel: diagnostics color codes filtered



commit 6f916912b1f87f4ff9dd8352a3a2b8dd7362e04f
Author: Sebastien Lafargue <slafargue gnome org>
Date:   Sun Feb 12 18:06:42 2017 +0100

    build-panel: diagnostics color codes filtered
    
    We now filter from color codes the diagnostics emitted for the
    build panel otherwise they do not appear in the panel.

 plugins/build-tools/gbp-build-log-panel.c |    1 -
 plugins/gcc/Makefile.am                   |    2 +
 plugins/gcc/gbp-gcc-build-result-addin.c  |    8 ++-
 plugins/gcc/gbp-gcc-build-result-utils.c  |  138 +++++++++++++++++++++++++++++
 plugins/gcc/gbp-gcc-build-result-utils.h  |   30 ++++++
 5 files changed, 176 insertions(+), 3 deletions(-)
---
diff --git a/plugins/build-tools/gbp-build-log-panel.c b/plugins/build-tools/gbp-build-log-panel.c
index 72358b2..529e96a 100644
--- a/plugins/build-tools/gbp-build-log-panel.c
+++ b/plugins/build-tools/gbp-build-log-panel.c
@@ -370,7 +370,6 @@ fetch_color_codes_tags (GbpBuildLogPanel  *self,
  * Returns: a #ColorCodeType indicating the state of the search.
  */
 
-/* TODO: handle attributes combination */
 static ColorCodeType
 find_color_code (GbpBuildLogPanel  *self,
                  const gchar       *msg,
diff --git a/plugins/gcc/Makefile.am b/plugins/gcc/Makefile.am
index b772044..40ad87c 100644
--- a/plugins/gcc/Makefile.am
+++ b/plugins/gcc/Makefile.am
@@ -9,6 +9,8 @@ dist_plugin_DATA = gcc.plugin
 libgcc_plugin_la_SOURCES = \
        gbp-gcc-build-result-addin.c \
        gbp-gcc-build-result-addin.h \
+       gbp-gcc-build-result-utils.c \
+       gbp-gcc-build-result-utils.h \
        gbp-gcc-plugin.c
 
 libgcc_plugin_la_CFLAGS = $(PLUGIN_CFLAGS)
diff --git a/plugins/gcc/gbp-gcc-build-result-addin.c b/plugins/gcc/gbp-gcc-build-result-addin.c
index ae295ff..452f518 100644
--- a/plugins/gcc/gbp-gcc-build-result-addin.c
+++ b/plugins/gcc/gbp-gcc-build-result-addin.c
@@ -19,6 +19,7 @@
 #include <string.h>
 
 #include "egg-signal-group.h"
+#include "gbp-gcc-build-result-utils.h"
 
 #include "gbp-gcc-build-result-addin.h"
 
@@ -174,6 +175,7 @@ gbp_gcc_build_result_addin_log (GbpGccBuildResultAddin *self,
 {
   GMatchInfo *match_info = NULL;
   const gchar *enterdir;
+  g_autofree gchar *filtered_message = NULL;
 
   g_assert (GBP_IS_GCC_BUILD_RESULT_ADDIN (self));
   g_assert (IDE_IS_BUILD_RESULT (result));
@@ -181,12 +183,14 @@ gbp_gcc_build_result_addin_log (GbpGccBuildResultAddin *self,
 #define ENTERING_DIRECTORY_BEGIN "Entering directory '"
 #define ENTERING_DIRECTORY_END   "'\n"
 
+  filtered_message = gbp_gcc_build_result_utils_color_codes_filtering (message);
+
   /*
    * This expects LANG=C, which is defined in the autotools Builder.
    * Not the most ideal decoupling of logic, but we don't have a whole
    * lot to work with here.
    */
-  if (NULL != (enterdir = strstr (message, ENTERING_DIRECTORY_BEGIN)) &&
+  if (NULL != (enterdir = strstr (filtered_message, ENTERING_DIRECTORY_BEGIN)) &&
       g_str_has_suffix (enterdir, ENTERING_DIRECTORY_END))
     {
       gssize len;
@@ -203,7 +207,7 @@ gbp_gcc_build_result_addin_log (GbpGccBuildResultAddin *self,
         }
     }
 
-  if (g_regex_match (errfmt, message, 0, &match_info))
+  if (g_regex_match (errfmt, filtered_message, 0, &match_info))
     {
       IdeDiagnostic *diagnostic;
 
diff --git a/plugins/gcc/gbp-gcc-build-result-utils.c b/plugins/gcc/gbp-gcc-build-result-utils.c
new file mode 100644
index 0000000..ffb01f3
--- /dev/null
+++ b/plugins/gcc/gbp-gcc-build-result-utils.c
@@ -0,0 +1,138 @@
+/* gbp-gcc-build-result-utils.c
+ *
+ * Copyright (C) 2017 Sebastien Lafargue <slafargue gnome org>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <ide.h>
+
+#include "gbp-gcc-build-result-utils.h"
+
+static void
+skip_color_codes_values (const gchar **cursor)
+{
+  g_assert (cursor != NULL && *cursor != NULL);
+
+  if (**cursor == 'm')
+    {
+      ++(*cursor);
+      return;
+    }
+
+  while (**cursor != '\0')
+    {
+      while (**cursor >= '0' && **cursor <= '9')
+        ++(*cursor);
+
+      if (**cursor == ';')
+        {
+          ++(*cursor);
+          continue;
+        }
+
+      if (**cursor == 'm')
+        {
+          ++(*cursor);
+          break;
+        }
+    }
+}
+
+static gboolean
+find_color_code (const gchar  *txt,
+                 const gchar **start_offset,
+                 const gchar **end_offset)
+{
+  const gchar *cursor = txt;
+
+  g_assert (!ide_str_empty0 (txt));
+  g_assert (start_offset != NULL);
+  g_assert (end_offset != NULL);
+
+  while (*cursor != '\0')
+    {
+      if (*cursor == '\\' && *(cursor + 1) == 'e')
+        {
+          *start_offset = cursor;
+          cursor += 2;
+        }
+      else if (*cursor == '\033' || *cursor == '\x01b')
+        {
+          *start_offset = cursor;
+          ++cursor;
+        }
+      else
+        goto next;
+
+      if (*cursor == '[')
+        {
+          ++cursor;
+          if (*cursor == '\0')
+            goto end;
+
+          if (*cursor == 'K')
+            {
+              *end_offset = cursor + 1;
+              return TRUE;
+            }
+
+          skip_color_codes_values (&cursor);
+          *end_offset = cursor;
+
+          return TRUE;
+        }
+
+      if (*cursor == '\0')
+        goto end;
+
+next:
+      /* TODO: skip a possible escaped char */
+      cursor = g_utf8_next_char (cursor);
+    }
+
+end:
+  *start_offset = *end_offset = cursor;
+  return FALSE;
+}
+
+gchar *
+gbp_gcc_build_result_utils_color_codes_filtering (const gchar *txt)
+{
+  const gchar *cursor = txt;
+  const gchar *start_offset;
+  const gchar *end_offset;
+  GString *string;
+  gsize len;
+  gboolean ret;
+
+  g_assert (!ide_str_empty0 (txt));
+
+  string = g_string_new (NULL);
+
+  while (*cursor != '\0')
+    {
+      ret = find_color_code (cursor, &start_offset, &end_offset);
+      len = start_offset - cursor;
+      if (len > 0)
+        g_string_append_len (string, cursor, len);
+
+      if (!ret)
+        break;
+
+      cursor = end_offset;
+    }
+
+  return g_string_free (string, FALSE);
+}
diff --git a/plugins/gcc/gbp-gcc-build-result-utils.h b/plugins/gcc/gbp-gcc-build-result-utils.h
new file mode 100644
index 0000000..5dc66b2
--- /dev/null
+++ b/plugins/gcc/gbp-gcc-build-result-utils.h
@@ -0,0 +1,30 @@
+/* gbp-gcc-build-result-utils.h
+ *
+ * Copyright (C) 2017 Sebastien Lafargue <slafargue gnome org>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GBP_GCC_BUILD_RESULT_UTILS_H
+#define GBP_GCC_BUILD_RESULT_UTILS_H
+
+#include <glib.h>
+
+G_BEGIN_DECLS
+
+gchar *gbp_gcc_build_result_utils_color_codes_filtering (const gchar *txt);
+
+G_END_DECLS
+
+#endif /* GBP_GCC_BUILD_RESULT_UTILS_H */


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