From 35bb768f4a007d17056ab052708f4b00a2d3838c Mon Sep 17 00:00:00 2001 From: Tobias Hunger Date: Wed, 24 Jul 2019 17:37:58 +0200 Subject: [PATCH] CMake: Make CMakeParser work again The CMakeParser used to set relative paths in the Tasks it creates. Since is problematic: Task tries to match that relative file name to one of the files that exist in the session. At the time cmake runs only the top-level CMakeLists.txt file is known, so this logic will map all the relative file paths to that file. Make sure to write absolute file paths into tasks so that this mapping is not attempted. Change-Id: I4ab72df21f18d2eff27ca9a502d605e00df2ad85 Reviewed-by: Cristian Adam Reviewed-by: Eike Ziller --- .../cmakeprojectmanager/cmakebuildstep.cpp | 7 +++++-- src/plugins/cmakeprojectmanager/cmakeparser.cpp | 16 ++++++++++++++-- src/plugins/cmakeprojectmanager/cmakeparser.h | 3 +++ src/plugins/cmakeprojectmanager/cmakeprocess.cpp | 1 + .../cmakeprojectmanager/servermodereader.cpp | 1 + 5 files changed, 24 insertions(+), 4 deletions(-) diff --git a/src/plugins/cmakeprojectmanager/cmakebuildstep.cpp b/src/plugins/cmakeprojectmanager/cmakebuildstep.cpp index 7711ca42c0a..90c4bca5068 100644 --- a/src/plugins/cmakeprojectmanager/cmakebuildstep.cpp +++ b/src/plugins/cmakeprojectmanager/cmakebuildstep.cpp @@ -52,9 +52,10 @@ #include #include +#include +#include #include #include -#include #include #include @@ -212,7 +213,9 @@ bool CMakeBuildStep::init() pp->setCommandLine(cmakeCommand(rc)); pp->resolveAll(); - setOutputParser(new CMakeParser); + CMakeParser *cmakeParser = new CMakeParser; + cmakeParser->setSourceDirectory(projectDirectory.toString()); + setOutputParser(cmakeParser); appendOutputParser(new GnuMakeParser); IOutputParser *parser = target()->kit()->createOutputParser(); if (parser) diff --git a/src/plugins/cmakeprojectmanager/cmakeparser.cpp b/src/plugins/cmakeprojectmanager/cmakeparser.cpp index be67db464f6..515bf892227 100644 --- a/src/plugins/cmakeprojectmanager/cmakeparser.cpp +++ b/src/plugins/cmakeprojectmanager/cmakeparser.cpp @@ -50,6 +50,11 @@ CMakeParser::CMakeParser() QTC_CHECK(m_locationLine.isValid()); } +void CMakeParser::setSourceDirectory(const QString &sourceDir) +{ + m_sourceDirectory = QDir(sourceDir); +} + void CMakeParser::stdError(const QString &line) { QString trimmedLine = rightTrimmed(line); @@ -67,8 +72,15 @@ void CMakeParser::stdError(const QString &line) m_skippedFirstEmptyLine = false; if (m_commonError.indexIn(trimmedLine) != -1) { - m_lastTask = Task(Task::Error, QString(), Utils::FilePath::fromUserInput(m_commonError.cap(1)), - m_commonError.cap(2).toInt(), Constants::TASK_CATEGORY_BUILDSYSTEM); + QString path = m_sourceDirectory ? m_sourceDirectory->absoluteFilePath( + QDir::fromNativeSeparators(m_commonError.cap(1))) + : QDir::fromNativeSeparators(m_commonError.cap(1)); + + m_lastTask = Task(Task::Error, + QString(), + Utils::FilePath::fromUserInput(path), + m_commonError.cap(2).toInt(), + Constants::TASK_CATEGORY_BUILDSYSTEM); m_lines = 1; return; } else if (m_nextSubError.indexIn(trimmedLine) != -1) { diff --git a/src/plugins/cmakeprojectmanager/cmakeparser.h b/src/plugins/cmakeprojectmanager/cmakeparser.h index 85a20d870d9..57b41ce559c 100644 --- a/src/plugins/cmakeprojectmanager/cmakeparser.h +++ b/src/plugins/cmakeprojectmanager/cmakeparser.h @@ -30,6 +30,7 @@ #include #include +#include #include #include @@ -41,6 +42,7 @@ class CMAKE_EXPORT CMakeParser : public ProjectExplorer::IOutputParser public: explicit CMakeParser(); + void setSourceDirectory(const QString &sourceDir); void stdError(const QString &line) override; protected: @@ -51,6 +53,7 @@ private: TripleLineError m_expectTripleLineErrorData = NONE; + Utils::optional m_sourceDirectory; ProjectExplorer::Task m_lastTask; QRegExp m_commonError; QRegExp m_nextSubError; diff --git a/src/plugins/cmakeprojectmanager/cmakeprocess.cpp b/src/plugins/cmakeprojectmanager/cmakeprocess.cpp index cd6a3d626a6..45b7b119eeb 100644 --- a/src/plugins/cmakeprojectmanager/cmakeprocess.cpp +++ b/src/plugins/cmakeprojectmanager/cmakeprocess.cpp @@ -104,6 +104,7 @@ void CMakeProcess::run(const BuildDirParameters ¶meters, const QStringList & const QString srcDir = parameters.sourceDirectory.toString(); auto parser = std::make_unique(); + parser->setSourceDirectory(srcDir); QDir source = QDir(srcDir); connect(parser.get(), &IOutputParser::addTask, parser.get(), [source](const Task &task) { diff --git a/src/plugins/cmakeprojectmanager/servermodereader.cpp b/src/plugins/cmakeprojectmanager/servermodereader.cpp index d88e6523227..5c4b1f7a810 100644 --- a/src/plugins/cmakeprojectmanager/servermodereader.cpp +++ b/src/plugins/cmakeprojectmanager/servermodereader.cpp @@ -103,6 +103,7 @@ void ServerModeReader::setParameters(const BuildDirParameters &p) m_parameters = p; + m_parser.setSourceDirectory(m_parameters.sourceDirectory.toString()); createNewServer(); }