1 /**************************************************************************
3 ** This file is part of Qt Creator
5 ** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
7 ** Contact: Nokia Corporation (qt-info@nokia.com)
11 ** This file contains pre-release code and may not be distributed.
12 ** You may use this file in accordance with the terms and conditions
13 ** contained in the Technology Preview License Agreement accompanying
16 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
25 ** In addition, as a special exception, Nokia gives you certain additional
26 ** rights. These rights are described in the Nokia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
29 ** If you have questions regarding the use of this file, please contact
30 ** Nokia at qt-info@nokia.com.
32 **************************************************************************/
34 #include "qmakeparser.h"
35 #include "qt4projectmanagerconstants.h"
37 #include <projectexplorer/taskwindow.h>
38 #include <projectexplorer/projectexplorerconstants.h>
39 #include <utils/qtcassert.h>
41 #include <QtCore/QDir>
43 using namespace Qt4ProjectManager;
44 using namespace Qt4ProjectManager::Internal;
45 using ProjectExplorer::Task;
47 QMakeParser::QMakeParser()
49 setObjectName(QLatin1String("QMakeParser"));
51 m_error.setPattern("^(.+):(\\d+):\\s(.+)$");
52 m_error.setMinimal(true);
55 void QMakeParser::stdError(const QString &line)
57 QString lne(line.trimmed());
58 if (lne.startsWith(QLatin1String("Project ERROR:"))) {
59 const QString description = lne.mid(15);
60 emit addTask(Task(Task::Error,
62 QString() /* filename */,
64 ProjectExplorer::Constants::TASK_CATEGORY_BUILDSYSTEM));
67 if (lne.startsWith(QLatin1String("Project WARNING:"))) {
68 const QString description = lne.mid(17);
69 emit addTask(Task(Task::Warning,
71 QString() /* filename */,
73 ProjectExplorer::Constants::TASK_CATEGORY_BUILDSYSTEM));
76 if (m_error.indexIn(lne) > -1) {
77 QString fileName = QDir::fromNativeSeparators(m_error.cap(1));
78 Task::TaskType type = Task::Error;
79 if (fileName.startsWith("WARNING: ")) {
81 fileName = fileName.mid(9);
82 } else if (fileName.startsWith("ERROR: ")) {
83 fileName = fileName.mid(7);
85 emit addTask(Task(type,
86 m_error.cap(3) /* description */,
88 m_error.cap(2).toInt() /* line */,
89 ProjectExplorer::Constants::TASK_CATEGORY_BUILDSYSTEM));
92 IOutputParser::stdError(line);
101 # include "qt4projectmanagerplugin.h"
103 # include "projectexplorer/outputparser_test.h"
105 using namespace Qt4ProjectManager::Internal;
106 using namespace ProjectExplorer;
108 void Qt4ProjectManagerPlugin::testQmakeOutputParsers_data()
110 QTest::addColumn<QString>("input");
111 QTest::addColumn<OutputParserTester::Channel>("inputChannel");
112 QTest::addColumn<QString>("childStdOutLines");
113 QTest::addColumn<QString>("childStdErrLines");
114 QTest::addColumn<QList<ProjectExplorer::Task> >("tasks");
115 QTest::addColumn<QString>("outputLines");
118 QTest::newRow("pass-through stdout")
119 << QString::fromLatin1("Sometext") << OutputParserTester::STDOUT
120 << QString::fromLatin1("Sometext") << QString()
121 << QList<ProjectExplorer::Task>()
123 QTest::newRow("pass-through stderr")
124 << QString::fromLatin1("Sometext") << OutputParserTester::STDERR
125 << QString() << QString::fromLatin1("Sometext")
126 << QList<ProjectExplorer::Task>()
129 QTest::newRow("qMake error")
130 << QString::fromLatin1("Project ERROR: undefined file")
131 << OutputParserTester::STDERR
132 << QString() << QString()
133 << (QList<ProjectExplorer::Task>()
135 QLatin1String("undefined file"),
137 ProjectExplorer::Constants::TASK_CATEGORY_BUILDSYSTEM))
140 QTest::newRow("qMake Parse Error")
141 << QString::fromLatin1("e:\\project.pro:14: Parse Error ('sth odd')")
142 << OutputParserTester::STDERR
143 << QString() << QString()
144 << (QList<ProjectExplorer::Task>()
146 QLatin1String("Parse Error ('sth odd')"),
147 QDir::fromNativeSeparators(QLatin1String("e:\\project.pro")),
149 ProjectExplorer::Constants::TASK_CATEGORY_BUILDSYSTEM))
152 QTest::newRow("qMake warning")
153 << QString::fromLatin1("Project WARNING: bearer module might require ReadUserData capability")
154 << OutputParserTester::STDERR
155 << QString() << QString()
156 << (QList<ProjectExplorer::Task>()
157 << Task(Task::Warning,
158 QLatin1String("bearer module might require ReadUserData capability"),
160 ProjectExplorer::Constants::TASK_CATEGORY_BUILDSYSTEM))
163 QTest::newRow("qMake warning with location")
164 << QString::fromLatin1("WARNING: e:\\NokiaQtSDK\\Simulator\\Qt\\msvc2008\\lib\\qtmaind.prl:1: Unescaped backslashes are deprecated.")
165 << OutputParserTester::STDERR
166 << QString() << QString()
167 << (QList<ProjectExplorer::Task>()
168 << Task(Task::Warning,
169 QLatin1String("Unescaped backslashes are deprecated."),
170 QLatin1String("e:/NokiaQtSDK/Simulator/Qt/msvc2008/lib/qtmaind.prl"), 1,
171 ProjectExplorer::Constants::TASK_CATEGORY_BUILDSYSTEM))
175 void Qt4ProjectManagerPlugin::testQmakeOutputParsers()
177 OutputParserTester testbench;
178 testbench.appendOutputParser(new QMakeParser);
179 QFETCH(QString, input);
180 QFETCH(OutputParserTester::Channel, inputChannel);
181 QFETCH(QList<Task>, tasks);
182 QFETCH(QString, childStdOutLines);
183 QFETCH(QString, childStdErrLines);
184 QFETCH(QString, outputLines);
186 testbench.testParsing(input, inputChannel,
187 tasks, childStdOutLines, childStdErrLines,