From 156db185922238a3a214012cf406efba2b6c8b2c Mon Sep 17 00:00:00 2001
From: dt <qtc-committer@nokia.com>
Date: Thu, 3 Sep 2009 15:07:12 +0200
Subject: [PATCH] Fix not trying hard enough to find the correct file on build
 errors.

If there are multiple files with the same name, then we try harder to
find the correct one. That is for jom and nmake we have a relative path
so we try to find a file which matches the relative path completly.
Instead of just comparing the last part.
---
 src/plugins/cmakeprojectmanager/makestep.cpp  |  1 -
 .../projectexplorer/abstractmakestep.cpp      | 22 ++++++++++++++++---
 src/plugins/projectexplorer/msvcparser.cpp    |  5 +++--
 3 files changed, 22 insertions(+), 6 deletions(-)

diff --git a/src/plugins/cmakeprojectmanager/makestep.cpp b/src/plugins/cmakeprojectmanager/makestep.cpp
index 8053d23f362..61a4a814487 100644
--- a/src/plugins/cmakeprojectmanager/makestep.cpp
+++ b/src/plugins/cmakeprojectmanager/makestep.cpp
@@ -26,7 +26,6 @@
 ** contact the sales department at http://qt.nokia.com/contact.
 **
 **************************************************************************/
-
 #include "makestep.h"
 #include "cmakeprojectconstants.h"
 #include "cmakeproject.h"
diff --git a/src/plugins/projectexplorer/abstractmakestep.cpp b/src/plugins/projectexplorer/abstractmakestep.cpp
index e19715b9b8e..18a3abecd59 100644
--- a/src/plugins/projectexplorer/abstractmakestep.cpp
+++ b/src/plugins/projectexplorer/abstractmakestep.cpp
@@ -149,10 +149,26 @@ void AbstractMakeStep::slotAddToTaskWindow(const QString & fn, int type, int lin
                 }
             }
         }
-        if (possibleFiles.count() == 1)
+        if (possibleFiles.count() == 1) {
             filePath = possibleFiles.first().filePath();
-        else
-            qWarning() << "Could not find absolute location of file " << filePath;
+        } else {
+            // More then one filename, so do a better compare
+            // Chop of any "../"
+            while (filePath.startsWith("../"))
+                filePath = filePath.mid(3);
+            int count = 0;
+            QString possibleFilePath;
+            foreach(const QFileInfo & fi, possibleFiles) {
+                if (fi.filePath().endsWith(filePath)) {
+                    possibleFilePath = fi.filePath();
+                    ++count;
+                }
+            }
+            if (count == 1)
+                filePath = possibleFilePath;
+            else
+                qWarning() << "Could not find absolute location of file " << filePath;
+        }
     }
     emit addToTaskWindow(filePath, type, linenumber, description);
 }
diff --git a/src/plugins/projectexplorer/msvcparser.cpp b/src/plugins/projectexplorer/msvcparser.cpp
index b245db783db..f4e7c715503 100644
--- a/src/plugins/projectexplorer/msvcparser.cpp
+++ b/src/plugins/projectexplorer/msvcparser.cpp
@@ -31,6 +31,7 @@
 #include "projectexplorerconstants.h"
 
 #include <QtCore/QStringList>
+#include <QtCore/QDir>
 
 using namespace ProjectExplorer;
 
@@ -58,7 +59,7 @@ void MsvcParser::stdOutput(const QString & line)
     QString lne = line.trimmed();
     if (m_compileRegExp.indexIn(lne) > -1 && m_compileRegExp.numCaptures() == 4) {
         emit addToTaskWindow(
-            m_compileRegExp.cap(1), //filename
+            QDir::cleanPath(m_compileRegExp.cap(1)), //filename
             toType(m_compileRegExp.cap(3).toInt()), // PatternType
             m_compileRegExp.cap(2).toInt(), //linenumber
             m_compileRegExp.cap(4) //description
@@ -70,7 +71,7 @@ void MsvcParser::stdOutput(const QString & line)
             fileName.clear();
 
         emit addToTaskWindow(
-            fileName, //filename
+            QDir::cleanPath(fileName), //filename
             toType(m_linkRegExp.cap(2).toInt()), // pattern type
             -1, // line number
             m_linkRegExp.cap(3) // description
-- 
GitLab