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 <cristian.adam@qt.io>
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
Tobias Hunger
2019-07-24 17:37:58 +02:00
parent 12dea8f772
commit 35bb768f4a
5 changed files with 24 additions and 4 deletions

View File

@@ -52,9 +52,10 @@
#include <utils/qtcprocess.h> #include <utils/qtcprocess.h>
#include <utils/pathchooser.h> #include <utils/pathchooser.h>
#include <QCheckBox>
#include <QDir>
#include <QFormLayout> #include <QFormLayout>
#include <QGroupBox> #include <QGroupBox>
#include <QCheckBox>
#include <QLineEdit> #include <QLineEdit>
#include <QListWidget> #include <QListWidget>
@@ -212,7 +213,9 @@ bool CMakeBuildStep::init()
pp->setCommandLine(cmakeCommand(rc)); pp->setCommandLine(cmakeCommand(rc));
pp->resolveAll(); pp->resolveAll();
setOutputParser(new CMakeParser); CMakeParser *cmakeParser = new CMakeParser;
cmakeParser->setSourceDirectory(projectDirectory.toString());
setOutputParser(cmakeParser);
appendOutputParser(new GnuMakeParser); appendOutputParser(new GnuMakeParser);
IOutputParser *parser = target()->kit()->createOutputParser(); IOutputParser *parser = target()->kit()->createOutputParser();
if (parser) if (parser)

View File

@@ -50,6 +50,11 @@ CMakeParser::CMakeParser()
QTC_CHECK(m_locationLine.isValid()); QTC_CHECK(m_locationLine.isValid());
} }
void CMakeParser::setSourceDirectory(const QString &sourceDir)
{
m_sourceDirectory = QDir(sourceDir);
}
void CMakeParser::stdError(const QString &line) void CMakeParser::stdError(const QString &line)
{ {
QString trimmedLine = rightTrimmed(line); QString trimmedLine = rightTrimmed(line);
@@ -67,8 +72,15 @@ void CMakeParser::stdError(const QString &line)
m_skippedFirstEmptyLine = false; m_skippedFirstEmptyLine = false;
if (m_commonError.indexIn(trimmedLine) != -1) { if (m_commonError.indexIn(trimmedLine) != -1) {
m_lastTask = Task(Task::Error, QString(), Utils::FilePath::fromUserInput(m_commonError.cap(1)), QString path = m_sourceDirectory ? m_sourceDirectory->absoluteFilePath(
m_commonError.cap(2).toInt(), Constants::TASK_CATEGORY_BUILDSYSTEM); 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; m_lines = 1;
return; return;
} else if (m_nextSubError.indexIn(trimmedLine) != -1) { } else if (m_nextSubError.indexIn(trimmedLine) != -1) {

View File

@@ -30,6 +30,7 @@
#include <projectexplorer/ioutputparser.h> #include <projectexplorer/ioutputparser.h>
#include <projectexplorer/task.h> #include <projectexplorer/task.h>
#include <QDir>
#include <QRegExp> #include <QRegExp>
#include <QRegularExpression> #include <QRegularExpression>
@@ -41,6 +42,7 @@ class CMAKE_EXPORT CMakeParser : public ProjectExplorer::IOutputParser
public: public:
explicit CMakeParser(); explicit CMakeParser();
void setSourceDirectory(const QString &sourceDir);
void stdError(const QString &line) override; void stdError(const QString &line) override;
protected: protected:
@@ -51,6 +53,7 @@ private:
TripleLineError m_expectTripleLineErrorData = NONE; TripleLineError m_expectTripleLineErrorData = NONE;
Utils::optional<QDir> m_sourceDirectory;
ProjectExplorer::Task m_lastTask; ProjectExplorer::Task m_lastTask;
QRegExp m_commonError; QRegExp m_commonError;
QRegExp m_nextSubError; QRegExp m_nextSubError;

View File

@@ -104,6 +104,7 @@ void CMakeProcess::run(const BuildDirParameters &parameters, const QStringList &
const QString srcDir = parameters.sourceDirectory.toString(); const QString srcDir = parameters.sourceDirectory.toString();
auto parser = std::make_unique<CMakeParser>(); auto parser = std::make_unique<CMakeParser>();
parser->setSourceDirectory(srcDir);
QDir source = QDir(srcDir); QDir source = QDir(srcDir);
connect(parser.get(), &IOutputParser::addTask, parser.get(), connect(parser.get(), &IOutputParser::addTask, parser.get(),
[source](const Task &task) { [source](const Task &task) {

View File

@@ -103,6 +103,7 @@ void ServerModeReader::setParameters(const BuildDirParameters &p)
m_parameters = p; m_parameters = p;
m_parser.setSourceDirectory(m_parameters.sourceDirectory.toString());
createNewServer(); createNewServer();
} }