OSDN Git Service

107d7baaf6c322da80e00f4421dc0caf1878713a
[qt-creator-jp/qt-creator-jp.git] / src / plugins / qt4projectmanager / qmakeparser.cpp
1 /**************************************************************************
2 **
3 ** This file is part of Qt Creator
4 **
5 ** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
6 **
7 ** Contact: Nokia Corporation (qt-info@nokia.com)
8 **
9 ** No Commercial Usage
10 **
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
14 ** this package.
15 **
16 ** GNU Lesser General Public License Usage
17 **
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.
24 **
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.
28 **
29 ** If you have questions regarding the use of this file, please contact
30 ** Nokia at qt-info@nokia.com.
31 **
32 **************************************************************************/
33
34 #include "qmakeparser.h"
35 #include "qt4projectmanagerconstants.h"
36
37 #include <projectexplorer/taskwindow.h>
38 #include <projectexplorer/projectexplorerconstants.h>
39 #include <utils/qtcassert.h>
40
41 #include <QtCore/QDir>
42
43 using namespace Qt4ProjectManager;
44 using namespace Qt4ProjectManager::Internal;
45 using ProjectExplorer::Task;
46
47 QMakeParser::QMakeParser()
48 {
49     setObjectName(QLatin1String("QMakeParser"));
50
51     m_error.setPattern("^(.+):(\\d+):\\s(.+)$");
52     m_error.setMinimal(true);
53 }
54
55 void QMakeParser::stdError(const QString &line)
56 {
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,
61                           description,
62                           QString() /* filename */,
63                           -1 /* linenumber */,
64                           ProjectExplorer::Constants::TASK_CATEGORY_BUILDSYSTEM));
65         return;
66     }
67     if (lne.startsWith(QLatin1String("Project WARNING:"))) {
68         const QString description = lne.mid(17);
69         emit addTask(Task(Task::Warning,
70                           description,
71                           QString() /* filename */,
72                           -1 /* linenumber */,
73                           ProjectExplorer::Constants::TASK_CATEGORY_BUILDSYSTEM));
74         return;
75     }
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: ")) {
80             type = Task::Warning;
81             fileName = fileName.mid(9);
82         } else if (fileName.startsWith("ERROR: ")) {
83             fileName = fileName.mid(7);
84         }
85         emit addTask(Task(type,
86                           m_error.cap(3) /* description */,
87                           fileName,
88                           m_error.cap(2).toInt() /* line */,
89                           ProjectExplorer::Constants::TASK_CATEGORY_BUILDSYSTEM));
90         return;
91     }
92     IOutputParser::stdError(line);
93 }
94
95
96 // Unit tests:
97
98 #ifdef WITH_TESTS
99 #   include <QTest>
100
101 #   include "qt4projectmanagerplugin.h"
102
103 #   include "projectexplorer/outputparser_test.h"
104
105 using namespace Qt4ProjectManager::Internal;
106 using namespace ProjectExplorer;
107
108 void Qt4ProjectManagerPlugin::testQmakeOutputParsers_data()
109 {
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");
116
117
118     QTest::newRow("pass-through stdout")
119             << QString::fromLatin1("Sometext") << OutputParserTester::STDOUT
120             << QString::fromLatin1("Sometext") << QString()
121             << QList<ProjectExplorer::Task>()
122             << QString();
123     QTest::newRow("pass-through stderr")
124             << QString::fromLatin1("Sometext") << OutputParserTester::STDERR
125             << QString() << QString::fromLatin1("Sometext")
126             << QList<ProjectExplorer::Task>()
127             << QString();
128
129     QTest::newRow("qMake error")
130             << QString::fromLatin1("Project ERROR: undefined file")
131             << OutputParserTester::STDERR
132             << QString() << QString()
133             << (QList<ProjectExplorer::Task>()
134                 << Task(Task::Error,
135                         QLatin1String("undefined file"),
136                         QString(), -1,
137                         ProjectExplorer::Constants::TASK_CATEGORY_BUILDSYSTEM))
138             << QString();
139
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>()
145                 << Task(Task::Error,
146                         QLatin1String("Parse Error ('sth odd')"),
147                         QDir::fromNativeSeparators(QLatin1String("e:\\project.pro")),
148                         14,
149                         ProjectExplorer::Constants::TASK_CATEGORY_BUILDSYSTEM))
150             << QString();
151
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"),
159                         QString(), -1,
160                         ProjectExplorer::Constants::TASK_CATEGORY_BUILDSYSTEM))
161             << QString();
162
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))
172             << QString();
173 }
174
175 void Qt4ProjectManagerPlugin::testQmakeOutputParsers()
176 {
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);
185
186     testbench.testParsing(input, inputChannel,
187                           tasks, childStdOutLines, childStdErrLines,
188                           outputLines);
189 }
190 #endif