From a6e1c200dda155f5f6ee5ba16c4f8651ba0bc322 Mon Sep 17 00:00:00 2001
From: Pawel Polanski <pawel.3.polanski@nokia.com>
Date: Mon, 8 Nov 2010 13:37:44 +0100
Subject: [PATCH] qmake error/warning parser has been improved

---
 src/plugins/qt4projectmanager/qmakeparser.cpp | 107 ++++++++++++++++++
 src/plugins/qt4projectmanager/qmakeparser.h   |   5 +
 .../qt4projectmanagerplugin.h                 |   2 +
 3 files changed, 114 insertions(+)

diff --git a/src/plugins/qt4projectmanager/qmakeparser.cpp b/src/plugins/qt4projectmanager/qmakeparser.cpp
index 26c049a35e2..ec1d334e2e4 100644
--- a/src/plugins/qt4projectmanager/qmakeparser.cpp
+++ b/src/plugins/qt4projectmanager/qmakeparser.cpp
@@ -33,6 +33,7 @@
 #include <projectexplorer/taskwindow.h>
 #include <projectexplorer/projectexplorerconstants.h>
 #include <utils/qtcassert.h>
+#include <QDir>
 
 using namespace Qt4ProjectManager;
 using namespace Qt4ProjectManager::Internal;
@@ -41,6 +42,9 @@ using ProjectExplorer::Task;
 QMakeParser::QMakeParser()
 {
     setObjectName(QLatin1String("QMakeParser"));
+
+    m_error.setPattern("^(.+):(\\d+):\\s(.+)$");
+    m_error.setMinimal(true);
 }
 
 void QMakeParser::stdError(const QString &line)
@@ -55,5 +59,108 @@ void QMakeParser::stdError(const QString &line)
                           ProjectExplorer::Constants::TASK_CATEGORY_BUILDSYSTEM));
         return;
     }
+    if (lne.startsWith(QLatin1String("Project WARNING:"))) {
+        const QString description = lne.mid(17);
+        emit addTask(Task(Task::Warning,
+                          description,
+                          QString() /* filename */,
+                          -1 /* linenumber */,
+                          ProjectExplorer::Constants::TASK_CATEGORY_BUILDSYSTEM));
+        return;
+    }
+    if (m_error.indexIn(lne) > -1) {
+       emit addTask(Task(Task::Error,
+                          m_error.cap(3) /* description */,
+                          QDir::fromNativeSeparators(m_error.cap(1)) /* file */,
+                          m_error.cap(2).toInt() /* line */,
+                          ProjectExplorer::Constants::TASK_CATEGORY_BUILDSYSTEM));
+        return;
+    }
     IOutputParser::stdError(line);
 }
+
+
+// Unit tests:
+
+#ifdef WITH_TESTS
+#   include <QTest>
+
+#   include "qt4projectmanagerplugin.h"
+
+#   include "projectexplorer/outputparser_test.h"
+
+using namespace Qt4ProjectManager::Internal;
+using namespace ProjectExplorer;
+
+void Qt4ProjectManagerPlugin::testQmakeOutputParsers_data()
+{
+    QTest::addColumn<QString>("input");
+    QTest::addColumn<OutputParserTester::Channel>("inputChannel");
+    QTest::addColumn<QString>("childStdOutLines");
+    QTest::addColumn<QString>("childStdErrLines");
+    QTest::addColumn<QList<ProjectExplorer::Task> >("tasks");
+    QTest::addColumn<QString>("outputLines");
+
+
+    QTest::newRow("pass-through stdout")
+            << QString::fromLatin1("Sometext") << OutputParserTester::STDOUT
+            << QString::fromLatin1("Sometext") << QString()
+            << QList<ProjectExplorer::Task>()
+            << QString();
+    QTest::newRow("pass-through stderr")
+            << QString::fromLatin1("Sometext") << OutputParserTester::STDERR
+            << QString() << QString::fromLatin1("Sometext")
+            << QList<ProjectExplorer::Task>()
+            << QString();
+
+    QTest::newRow("qMake error")
+            << QString::fromLatin1("Project ERROR: undefined file")
+            << OutputParserTester::STDERR
+            << QString() << QString()
+            << (QList<ProjectExplorer::Task>()
+                << Task(Task::Error,
+                        QLatin1String("undefined file"),
+                        QString(), -1,
+                        ProjectExplorer::Constants::TASK_CATEGORY_BUILDSYSTEM))
+            << QString();
+
+    QTest::newRow("qMake Parse Error")
+            << QString::fromLatin1("e:\\project.pro:14: Parse Error ('sth odd')")
+            << OutputParserTester::STDERR
+            << QString() << QString()
+            << (QList<ProjectExplorer::Task>()
+                << Task(Task::Error,
+                        QLatin1String("Parse Error ('sth odd')"),
+                        QDir::fromNativeSeparators(QLatin1String("e:\\project.pro")),
+                        14,
+                        ProjectExplorer::Constants::TASK_CATEGORY_BUILDSYSTEM))
+            << QString();
+
+    QTest::newRow("qMake warning")
+            << QString::fromLatin1("Project WARNING: bearer module might require ReadUserData capability")
+            << OutputParserTester::STDERR
+            << QString() << QString()
+            << (QList<ProjectExplorer::Task>()
+                << Task(Task::Warning,
+                        QLatin1String("bearer module might require ReadUserData capability"),
+                        QString(), -1,
+                        ProjectExplorer::Constants::TASK_CATEGORY_BUILDSYSTEM))
+            << QString();
+}
+
+void Qt4ProjectManagerPlugin::testQmakeOutputParsers()
+{
+    OutputParserTester testbench;
+    testbench.appendOutputParser(new QMakeParser);
+    QFETCH(QString, input);
+    QFETCH(OutputParserTester::Channel, inputChannel);
+    QFETCH(QList<Task>, tasks);
+    QFETCH(QString, childStdOutLines);
+    QFETCH(QString, childStdErrLines);
+    QFETCH(QString, outputLines);
+
+    testbench.testParsing(input, inputChannel,
+                          tasks, childStdOutLines, childStdErrLines,
+                          outputLines);
+}
+#endif
diff --git a/src/plugins/qt4projectmanager/qmakeparser.h b/src/plugins/qt4projectmanager/qmakeparser.h
index 0bbd17e30e3..0a261973944 100644
--- a/src/plugins/qt4projectmanager/qmakeparser.h
+++ b/src/plugins/qt4projectmanager/qmakeparser.h
@@ -32,6 +32,8 @@
 
 #include <projectexplorer/ioutputparser.h>
 
+#include <QtCore/QRegExp>
+
 namespace Qt4ProjectManager {
 namespace Internal {
 
@@ -42,6 +44,9 @@ class QMakeParser : public ProjectExplorer::IOutputParser
 public:
     QMakeParser();
     virtual void stdError(const QString &line);
+
+private:
+    QRegExp m_error;
 };
 
 } // namesapce Internal
diff --git a/src/plugins/qt4projectmanager/qt4projectmanagerplugin.h b/src/plugins/qt4projectmanager/qt4projectmanagerplugin.h
index f2f8164325c..a74a978ae3c 100644
--- a/src/plugins/qt4projectmanager/qt4projectmanagerplugin.h
+++ b/src/plugins/qt4projectmanager/qt4projectmanagerplugin.h
@@ -88,6 +88,8 @@ private slots:
     void testSbsV2OutputParsers();
     void testRvctOutputParser_data();
     void testRvctOutputParser();
+    void testQmakeOutputParsers_data();
+    void testQmakeOutputParsers();
 #endif
 
 private:
-- 
GitLab