[gnome-builder] build-panel: diagnostics color codes filtered
- From: Sébastien Lafargue <slafargue src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder] build-panel: diagnostics color codes filtered
- Date: Tue, 14 Feb 2017 21:58:55 +0000 (UTC)
commit 7c39cf1e195642517ee7cbd66ac8ed4064fc4516
Author: Sebastien Lafargue <slafargue gnome org>
Date: Tue Feb 14 22:03:40 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.
libide/Makefile.am | 2 +
libide/buildsystem/ide-build-pipeline.c | 8 ++-
libide/buildsystem/ide-build-utils.c | 141 +++++++++++++++++++++++++++++++
libide/buildsystem/ide-build-utils.h | 30 +++++++
4 files changed, 179 insertions(+), 2 deletions(-)
---
diff --git a/libide/Makefile.am b/libide/Makefile.am
index 723ca68..50b944d 100644
--- a/libide/Makefile.am
+++ b/libide/Makefile.am
@@ -42,6 +42,7 @@ libide_1_0_la_public_headers = \
buildsystem/ide-build-stage-transfer.h \
buildsystem/ide-build-system.h \
buildsystem/ide-build-target.h \
+ buildsystem/ide-build-utils.h \
buildsystem/ide-configuration-manager.h \
buildsystem/ide-configuration.h \
buildsystem/ide-configuration-provider.h \
@@ -215,6 +216,7 @@ libide_1_0_la_public_sources = \
buildsystem/ide-build-stage-transfer.c \
buildsystem/ide-build-system.c \
buildsystem/ide-build-target.c \
+ buildsystem/ide-build-utils.c \
buildsystem/ide-configuration-manager.c \
buildsystem/ide-configuration.c \
buildsystem/ide-configuration-provider.c \
diff --git a/libide/buildsystem/ide-build-pipeline.c b/libide/buildsystem/ide-build-pipeline.c
index 0153918..fa4f947 100644
--- a/libide/buildsystem/ide-build-pipeline.c
+++ b/libide/buildsystem/ide-build-pipeline.c
@@ -37,6 +37,7 @@
#include "buildsystem/ide-build-stage-launcher.h"
#include "buildsystem/ide-build-stage-private.h"
#include "buildsystem/ide-build-system.h"
+#include "buildsystem/ide-build-utils.h"
#include "diagnostics/ide-diagnostic.h"
#include "diagnostics/ide-source-location.h"
#include "diagnostics/ide-source-range.h"
@@ -464,6 +465,7 @@ ide_build_pipeline_log_observer (IdeBuildLogStream stream,
{
IdeBuildPipeline *self = user_data;
const gchar *enterdir;
+ g_autofree gchar *filtered_message = NULL;
g_assert (stream == IDE_BUILD_LOG_STDOUT || stream == IDE_BUILD_LOG_STDERR);
g_assert (IDE_IS_BUILD_PIPELINE (self));
@@ -478,12 +480,14 @@ ide_build_pipeline_log_observer (IdeBuildLogStream stream,
if (self->log != NULL)
ide_build_log_observer (stream, message, message_len, self->log);
+ filtered_message = ide_build_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;
@@ -507,7 +511,7 @@ ide_build_pipeline_log_observer (IdeBuildLogStream stream,
const ErrorFormat *errfmt = &g_array_index (self->errfmts, ErrorFormat, i);
g_autoptr(GMatchInfo) match_info = NULL;
- if (g_regex_match (errfmt->regex, message, 0, &match_info))
+ if (g_regex_match (errfmt->regex, filtered_message, 0, &match_info))
{
g_autoptr(IdeDiagnostic) diagnostic = create_diagnostic (self, match_info);
diff --git a/libide/buildsystem/ide-build-utils.c b/libide/buildsystem/ide-build-utils.c
new file mode 100644
index 0000000..356f950
--- /dev/null
+++ b/libide/buildsystem/ide-build-utils.c
@@ -0,0 +1,141 @@
+/* ide-build-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 "ide-build-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 *
+ide_build_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 (txt != NULL);
+
+ if (*txt == '\0')
+ return g_strdup ("\0");
+
+ 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/libide/buildsystem/ide-build-utils.h b/libide/buildsystem/ide-build-utils.h
new file mode 100644
index 0000000..3db5dda
--- /dev/null
+++ b/libide/buildsystem/ide-build-utils.h
@@ -0,0 +1,30 @@
+/* ide-build-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 IDE_BUILD_UTILS_H
+#define IDE_BUILD_UTILS_H
+
+#include <glib.h>
+
+G_BEGIN_DECLS
+
+gchar *ide_build_utils_color_codes_filtering (const gchar *txt);
+
+G_END_DECLS
+
+#endif /* IDE_BUILD_UTILS_H */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]