2012-10-02 09:12:39 +02:00
|
|
|
/****************************************************************************
|
2010-08-03 17:24:20 +02:00
|
|
|
**
|
2014-01-07 13:27:11 +01:00
|
|
|
** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
|
2012-10-02 09:12:39 +02:00
|
|
|
** Contact: http://www.qt-project.org/legal
|
2010-08-03 17:24:20 +02:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** This file is part of Qt Creator.
|
2010-08-03 17:24:20 +02:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** Commercial License Usage
|
|
|
|
|
** Licensees holding valid commercial Qt licenses may use this file in
|
|
|
|
|
** accordance with the commercial license agreement provided with the
|
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
|
|
|
|
** a written agreement between you and Digia. For licensing terms and
|
2014-10-01 13:21:18 +02:00
|
|
|
** conditions see http://www.qt.io/licensing. For further information
|
|
|
|
|
** use the contact form at http://www.qt.io/contact-us.
|
2010-08-03 17:24:20 +02:00
|
|
|
**
|
|
|
|
|
** GNU Lesser General Public License Usage
|
2012-10-02 09:12:39 +02:00
|
|
|
** Alternatively, this file may be used under the terms of the GNU Lesser
|
2014-10-01 13:21:18 +02:00
|
|
|
** General Public License version 2.1 or version 3 as published by the Free
|
|
|
|
|
** Software Foundation and appearing in the file LICENSE.LGPLv21 and
|
|
|
|
|
** LICENSE.LGPLv3 included in the packaging of this file. Please review the
|
|
|
|
|
** following information to ensure the GNU Lesser General Public License
|
|
|
|
|
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
|
|
|
|
|
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
2012-10-02 09:12:39 +02:00
|
|
|
**
|
|
|
|
|
** In addition, as a special exception, Digia gives you certain additional
|
|
|
|
|
** rights. These rights are described in the Digia Qt LGPL Exception
|
2010-12-17 16:01:08 +01:00
|
|
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
****************************************************************************/
|
2010-08-03 17:24:20 +02:00
|
|
|
|
|
|
|
|
#include "qtparser.h"
|
|
|
|
|
|
2011-08-18 13:46:52 +02:00
|
|
|
#include <projectexplorer/task.h>
|
2010-08-03 17:24:20 +02:00
|
|
|
#include <projectexplorer/projectexplorerconstants.h>
|
2011-08-18 13:46:52 +02:00
|
|
|
|
2011-05-24 16:15:15 +02:00
|
|
|
using namespace QtSupport;
|
2010-08-03 17:24:20 +02:00
|
|
|
using ProjectExplorer::Task;
|
|
|
|
|
|
2011-08-17 11:34:57 +02:00
|
|
|
// opt. drive letter + filename: (2 brackets)
|
2011-08-18 13:46:52 +02:00
|
|
|
#define FILE_PATTERN "^(([A-Za-z]:)?[^:]+\\.[^:]+)"
|
2010-08-03 17:24:20 +02:00
|
|
|
|
2011-08-18 13:46:52 +02:00
|
|
|
QtParser::QtParser() :
|
2014-07-24 11:46:58 +02:00
|
|
|
m_mocRegExp(QLatin1String(FILE_PATTERN"[:\\(](\\d+)\\)?:\\s([Ww]arning|[Ee]rror|[Nn]ote):\\s(.+)$")),
|
2013-12-11 17:50:17 +01:00
|
|
|
m_translationRegExp(QLatin1String("^([Ww]arning|[Ee]rror):\\s+(.*) in '(.*)'$"))
|
2010-08-03 17:24:20 +02:00
|
|
|
{
|
2010-09-15 13:55:01 +02:00
|
|
|
setObjectName(QLatin1String("QtParser"));
|
2010-08-03 17:24:20 +02:00
|
|
|
m_mocRegExp.setMinimal(true);
|
2013-12-11 17:50:17 +01:00
|
|
|
m_translationRegExp.setMinimal(true);
|
2010-08-03 17:24:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void QtParser::stdError(const QString &line)
|
|
|
|
|
{
|
2013-04-02 15:21:59 +02:00
|
|
|
QString lne = rightTrimmed(line);
|
2010-08-03 17:24:20 +02:00
|
|
|
if (m_mocRegExp.indexIn(lne) > -1) {
|
|
|
|
|
bool ok;
|
|
|
|
|
int lineno = m_mocRegExp.cap(3).toInt(&ok);
|
|
|
|
|
if (!ok)
|
|
|
|
|
lineno = -1;
|
2014-01-14 10:28:16 +01:00
|
|
|
Task::TaskType type = Task::Error;
|
2014-07-24 11:46:58 +02:00
|
|
|
const QString level = m_mocRegExp.cap(4);
|
|
|
|
|
if (level.compare(QLatin1String("Warning"), Qt::CaseInsensitive) == 0)
|
2014-01-14 10:28:16 +01:00
|
|
|
type = Task::Warning;
|
2014-07-24 11:46:58 +02:00
|
|
|
if (level.compare(QLatin1String("Note"), Qt::CaseInsensitive) == 0)
|
|
|
|
|
type = Task::Unknown;
|
2014-01-14 10:28:16 +01:00
|
|
|
Task task(type, m_mocRegExp.cap(5).trimmed() /* description */,
|
2012-01-26 13:38:25 +01:00
|
|
|
Utils::FileName::fromUserInput(m_mocRegExp.cap(1)) /* filename */,
|
2010-08-03 17:24:20 +02:00
|
|
|
lineno,
|
2013-08-19 15:51:26 +02:00
|
|
|
ProjectExplorer::Constants::TASK_CATEGORY_COMPILE);
|
2010-08-03 17:24:20 +02:00
|
|
|
emit addTask(task);
|
|
|
|
|
return;
|
|
|
|
|
}
|
2013-12-11 17:50:17 +01:00
|
|
|
if (m_translationRegExp.indexIn(lne) > -1) {
|
|
|
|
|
Task::TaskType type = Task::Warning;
|
|
|
|
|
if (m_translationRegExp.cap(1) == QLatin1String("Error"))
|
|
|
|
|
type = Task::Error;
|
|
|
|
|
Task task(type, m_translationRegExp.cap(2),
|
|
|
|
|
Utils::FileName::fromUserInput(m_translationRegExp.cap(3)) /* filename */,
|
|
|
|
|
-1,
|
|
|
|
|
ProjectExplorer::Constants::TASK_CATEGORY_COMPILE);
|
|
|
|
|
emit addTask(task);
|
|
|
|
|
return;
|
|
|
|
|
}
|
2010-08-03 17:24:20 +02:00
|
|
|
IOutputParser::stdError(line);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Unit tests:
|
|
|
|
|
|
|
|
|
|
#ifdef WITH_TESTS
|
|
|
|
|
# include <QTest>
|
|
|
|
|
|
2011-05-24 16:15:15 +02:00
|
|
|
# include "qtsupportplugin.h"
|
2010-08-03 17:24:20 +02:00
|
|
|
# include <projectexplorer/projectexplorerconstants.h>
|
|
|
|
|
# include <projectexplorer/metatypedeclarations.h>
|
|
|
|
|
# include <projectexplorer/outputparser_test.h>
|
|
|
|
|
|
|
|
|
|
using namespace ProjectExplorer;
|
2011-05-24 16:15:15 +02:00
|
|
|
using namespace QtSupport::Internal;
|
2010-08-03 17:24:20 +02:00
|
|
|
|
2011-05-24 16:15:15 +02:00
|
|
|
void QtSupportPlugin::testQtOutputParser_data()
|
2010-08-03 17:24:20 +02:00
|
|
|
{
|
|
|
|
|
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
|
2011-05-18 18:39:14 +02:00
|
|
|
<< QString::fromLatin1("Sometext\n") << QString()
|
2010-08-03 17:24:20 +02:00
|
|
|
<< QList<ProjectExplorer::Task>()
|
|
|
|
|
<< QString();
|
|
|
|
|
QTest::newRow("pass-through stderr")
|
|
|
|
|
<< QString::fromLatin1("Sometext") << OutputParserTester::STDERR
|
2011-05-18 18:39:14 +02:00
|
|
|
<< QString() << QString::fromLatin1("Sometext\n")
|
2010-08-03 17:24:20 +02:00
|
|
|
<< QList<ProjectExplorer::Task>()
|
|
|
|
|
<< QString();
|
2010-09-15 13:55:01 +02:00
|
|
|
QTest::newRow("pass-through gcc infos")
|
|
|
|
|
<< QString::fromLatin1("/temp/test/untitled8/main.cpp: In function `int main(int, char**)':\n"
|
|
|
|
|
"../../scriptbug/main.cpp: At global scope:\n"
|
|
|
|
|
"../../scriptbug/main.cpp: In instantiation of void bar(i) [with i = double]:\n"
|
|
|
|
|
"../../scriptbug/main.cpp:8: instantiated from void foo(i) [with i = double]\n"
|
2011-05-18 18:39:14 +02:00
|
|
|
"../../scriptbug/main.cpp:22: instantiated from here")
|
2010-09-15 13:55:01 +02:00
|
|
|
<< OutputParserTester::STDERR
|
|
|
|
|
<< QString()
|
|
|
|
|
<< QString::fromLatin1("/temp/test/untitled8/main.cpp: In function `int main(int, char**)':\n"
|
|
|
|
|
"../../scriptbug/main.cpp: At global scope:\n"
|
|
|
|
|
"../../scriptbug/main.cpp: In instantiation of void bar(i) [with i = double]:\n"
|
|
|
|
|
"../../scriptbug/main.cpp:8: instantiated from void foo(i) [with i = double]\n"
|
|
|
|
|
"../../scriptbug/main.cpp:22: instantiated from here\n")
|
|
|
|
|
<< QList<ProjectExplorer::Task>()
|
|
|
|
|
<< QString();
|
2012-10-11 18:32:08 +02:00
|
|
|
QTest::newRow("qdoc warning")
|
|
|
|
|
<< QString::fromLatin1("/home/user/dev/qt5/qtscript/src/script/api/qscriptengine.cpp:295: warning: Can't create link to 'Object Trees & Ownership'")
|
|
|
|
|
<< OutputParserTester::STDERR
|
|
|
|
|
<< QString() << QString()
|
|
|
|
|
<< (QList<ProjectExplorer::Task>() << Task(Task::Warning,
|
|
|
|
|
QLatin1String("Can't create link to 'Object Trees & Ownership'"),
|
|
|
|
|
Utils::FileName::fromUserInput(QLatin1String("/home/user/dev/qt5/qtscript/src/script/api/qscriptengine.cpp")), 295,
|
2013-08-19 15:51:26 +02:00
|
|
|
ProjectExplorer::Constants::TASK_CATEGORY_COMPILE))
|
2012-10-11 18:32:08 +02:00
|
|
|
<< QString();
|
2010-08-03 17:24:20 +02:00
|
|
|
QTest::newRow("moc warning")
|
|
|
|
|
<< QString::fromLatin1("..\\untitled\\errorfile.h:0: Warning: No relevant classes found. No output generated.")
|
|
|
|
|
<< OutputParserTester::STDERR
|
|
|
|
|
<< QString() << QString()
|
|
|
|
|
<< (QList<ProjectExplorer::Task>() << Task(Task::Warning,
|
|
|
|
|
QLatin1String("No relevant classes found. No output generated."),
|
2012-07-05 17:14:20 +02:00
|
|
|
Utils::FileName::fromUserInput(QLatin1String("..\\untitled\\errorfile.h")), 0,
|
2013-08-19 15:51:26 +02:00
|
|
|
ProjectExplorer::Constants::TASK_CATEGORY_COMPILE))
|
2010-08-03 17:24:20 +02:00
|
|
|
<< QString();
|
2011-01-20 11:16:00 +01:00
|
|
|
QTest::newRow("moc warning 2")
|
|
|
|
|
<< QString::fromLatin1("c:\\code\\test.h(96): Warning: Property declaration ) has no READ accessor function. The property will be invalid.")
|
|
|
|
|
<< OutputParserTester::STDERR
|
|
|
|
|
<< QString() << QString()
|
|
|
|
|
<< (QList<ProjectExplorer::Task>() << Task(Task::Warning,
|
|
|
|
|
QLatin1String("Property declaration ) has no READ accessor function. The property will be invalid."),
|
2012-07-05 17:14:20 +02:00
|
|
|
Utils::FileName::fromUserInput(QLatin1String("c:\\code\\test.h")), 96,
|
2013-08-19 15:51:26 +02:00
|
|
|
ProjectExplorer::Constants::TASK_CATEGORY_COMPILE))
|
2011-01-20 11:16:00 +01:00
|
|
|
<< QString();
|
2014-07-24 11:46:58 +02:00
|
|
|
QTest::newRow("moc note")
|
|
|
|
|
<< QString::fromLatin1("/home/qtwebkithelpviewer.h:0: Note: No relevant classes found. No output generated.")
|
|
|
|
|
<< OutputParserTester::STDERR
|
|
|
|
|
<< QString() << QString()
|
|
|
|
|
<< (QList<ProjectExplorer::Task>() << Task(Task::Unknown,
|
|
|
|
|
QLatin1String("No relevant classes found. No output generated."),
|
|
|
|
|
Utils::FileName::fromUserInput(QLatin1String("/home/qtwebkithelpviewer.h")), 0,
|
|
|
|
|
ProjectExplorer::Constants::TASK_CATEGORY_COMPILE))
|
|
|
|
|
<< QString();
|
2012-09-26 17:41:50 +02:00
|
|
|
QTest::newRow("ninja with moc")
|
|
|
|
|
<< QString::fromLatin1("E:/sandbox/creator/loaden/src/libs/utils/iwelcomepage.h(54): Error: Undefined interface")
|
|
|
|
|
<< OutputParserTester::STDERR
|
|
|
|
|
<< QString() << QString()
|
|
|
|
|
<< (QList<ProjectExplorer::Task>() << Task(Task::Error,
|
|
|
|
|
QLatin1String("Undefined interface"),
|
|
|
|
|
Utils::FileName::fromUserInput(QLatin1String("E:/sandbox/creator/loaden/src/libs/utils/iwelcomepage.h")), 54,
|
2013-08-19 15:51:26 +02:00
|
|
|
ProjectExplorer::Constants::TASK_CATEGORY_COMPILE))
|
2012-09-26 17:41:50 +02:00
|
|
|
<< QString();
|
2013-12-11 17:50:17 +01:00
|
|
|
QTest::newRow("translation")
|
|
|
|
|
<< QString::fromLatin1("Warning: dropping duplicate messages in '/some/place/qtcreator_fr.qm'")
|
|
|
|
|
<< OutputParserTester::STDERR
|
|
|
|
|
<< QString() << QString()
|
|
|
|
|
<< (QList<ProjectExplorer::Task>() << Task(Task::Warning,
|
|
|
|
|
QLatin1String("dropping duplicate messages"),
|
|
|
|
|
Utils::FileName::fromUserInput(QLatin1String("/some/place/qtcreator_fr.qm")), -1,
|
|
|
|
|
ProjectExplorer::Constants::TASK_CATEGORY_COMPILE))
|
|
|
|
|
<< QString();
|
2010-08-03 17:24:20 +02:00
|
|
|
}
|
|
|
|
|
|
2011-05-24 16:15:15 +02:00
|
|
|
void QtSupportPlugin::testQtOutputParser()
|
2010-08-03 17:24:20 +02:00
|
|
|
{
|
|
|
|
|
OutputParserTester testbench;
|
|
|
|
|
testbench.appendOutputParser(new QtParser);
|
|
|
|
|
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
|