From 51d4e56e5d8b51966b4c7250f8561beeddbc105c Mon Sep 17 00:00:00 2001
From: Friedemann Kleint <Friedemann.Kleint@theqtcompany.com>
Date: Thu, 4 Feb 2016 13:29:04 +0100
Subject: [PATCH] MsvcParser: Factor out shared functionality.

Factor out functions for handling jom/nmake messages and determining
task types.

Task-number: QTBUG-50804
Task-number: QTCREATORBUG-15641
Change-Id: If938f13d79d20b9c5eb422bf5ac0d07c4ce533b9
Reviewed-by: Tobias Hunger <tobias.hunger@theqtcompany.com>
---
 src/plugins/projectexplorer/msvcparser.cpp | 62 ++++++++++++----------
 1 file changed, 34 insertions(+), 28 deletions(-)

diff --git a/src/plugins/projectexplorer/msvcparser.cpp b/src/plugins/projectexplorer/msvcparser.cpp
index 95ceda734ad..3ddac5fea65 100644
--- a/src/plugins/projectexplorer/msvcparser.cpp
+++ b/src/plugins/projectexplorer/msvcparser.cpp
@@ -60,6 +60,36 @@ static QPair<Utils::FileName, int> parseFileName(const QString &input)
 
 using namespace ProjectExplorer;
 
+// nmake/jom messages.
+static bool handleNmakeJomMessage(const QString &line, Task *task)
+{
+    int matchLength = 0;
+    if (line.startsWith(QLatin1String("Error:")))
+        matchLength = 6;
+    else if (line.startsWith(QLatin1String("Warning:")))
+        matchLength = 8;
+
+    if (!matchLength)
+        return false;
+
+    *task = Task(Task::Error,
+                 line.mid(matchLength).trimmed(), /* description */
+                 Utils::FileName(), /* fileName */
+                 -1, /* linenumber */
+                 Constants::TASK_CATEGORY_COMPILE);
+    return true;
+}
+
+static Task::TaskType taskType(const QString &category)
+{
+    Task::TaskType type = Task::Unknown;
+    if (category == QLatin1String("warning"))
+        type = Task::Warning;
+    else if (category == QLatin1String("error"))
+        type = Task::Error;
+    return type;
+}
+
 MsvcParser::MsvcParser()
 {
     setObjectName(QLatin1String("MsvcParser"));
@@ -103,21 +133,7 @@ void MsvcParser::stdOutput(const QString &line)
 
     if (processCompileLine(line))
         return;
-    if (line.startsWith(QLatin1String("Error:"))) {
-        m_lastTask = Task(Task::Error,
-                          line.mid(6).trimmed(), /* description */
-                          Utils::FileName(), /* fileName */
-                          -1, /* linenumber */
-                          Constants::TASK_CATEGORY_COMPILE);
-        m_lines = 1;
-        return;
-    }
-    if (line.startsWith(QLatin1String("Warning:"))) {
-        m_lastTask = Task(Task::Warning,
-                          line.mid(8).trimmed(), /* description */
-                          Utils::FileName(), /* fileName */
-                          -1, /* linenumber */
-                          Constants::TASK_CATEGORY_COMPILE);
+    if (handleNmakeJomMessage(line, &m_lastTask)) {
         m_lines = 1;
         return;
     }
@@ -141,12 +157,7 @@ void MsvcParser::stdError(const QString &line)
     if (processCompileLine(line))
         return;
     // Jom outputs errors to stderr
-    if (line.startsWith(QLatin1String("Error:"))) {
-        m_lastTask = Task(Task::Error,
-                          line.mid(6).trimmed(), /* description */
-                          Utils::FileName(), /* fileName */
-                          -1, /* linenumber */
-                          Constants::TASK_CATEGORY_COMPILE);
+    if (handleNmakeJomMessage(line, &m_lastTask)) {
         m_lines = 1;
         return;
     }
@@ -160,13 +171,8 @@ bool MsvcParser::processCompileLine(const QString &line)
     QRegularExpressionMatch match = m_compileRegExp.match(line);
     if (match.hasMatch()) {
         QPair<Utils::FileName, int> position = parseFileName(match.captured(1));
-        Task::TaskType type = Task::Unknown;
-        const QString category = match.captured(3);
-        if (category == QLatin1String("warning"))
-            type = Task::Warning;
-        else if (category == QLatin1String("error"))
-            type = Task::Error;
-        m_lastTask = Task(type, match.captured(4).trimmed() /* description */,
+        m_lastTask = Task(taskType(match.captured(3)),
+                          match.captured(4).trimmed() /* description */,
                           position.first, position.second,
                           Constants::TASK_CATEGORY_COMPILE);
         m_lines = 1;
-- 
GitLab