OSDN Git Service

Maemo: Remove "cd" call from package creation preparation.
[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) 2010 Nokia Corporation and/or its subsidiary(-ies).
6 **
7 ** Contact: Nokia Corporation (qt-info@nokia.com)
8 **
9 ** Commercial Usage
10 **
11 ** Licensees holding valid Qt Commercial licenses may use this file in
12 ** accordance with the Qt Commercial License Agreement provided with the
13 ** Software or, alternatively, in accordance with the terms contained in
14 ** a written agreement between you and Nokia.
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 ** If you are unsure which license is appropriate for your use, please
26 ** contact the sales department at http://qt.nokia.com/contact.
27 **
28 **************************************************************************/
29
30 #include "qmakeparser.h"
31 #include "qt4projectmanagerconstants.h"
32
33 #include <projectexplorer/taskwindow.h>
34 #include <projectexplorer/projectexplorerconstants.h>
35 #include <utils/qtcassert.h>
36 #include <QDir>
37
38 using namespace Qt4ProjectManager;
39 using namespace Qt4ProjectManager::Internal;
40 using ProjectExplorer::Task;
41
42 QMakeParser::QMakeParser()
43 {
44     setObjectName(QLatin1String("QMakeParser"));
45
46     m_error.setPattern("^(.+):(\\d+):\\s(.+)$");
47     m_error.setMinimal(true);
48 }
49
50 void QMakeParser::stdError(const QString &line)
51 {
52     QString lne(line.trimmed());
53     if (lne.startsWith(QLatin1String("Project ERROR:"))) {
54         const QString description = lne.mid(15);
55         emit addTask(Task(Task::Error,
56                           description,
57                           QString() /* filename */,
58                           -1 /* linenumber */,
59                           ProjectExplorer::Constants::TASK_CATEGORY_BUILDSYSTEM));
60         return;
61     }
62     if (lne.startsWith(QLatin1String("Project WARNING:"))) {
63         const QString description = lne.mid(17);
64         emit addTask(Task(Task::Warning,
65                           description,
66                           QString() /* filename */,
67                           -1 /* linenumber */,
68                           ProjectExplorer::Constants::TASK_CATEGORY_BUILDSYSTEM));
69         return;
70     }
71     if (m_error.indexIn(lne) > -1) {
72        emit addTask(Task(Task::Error,
73                           m_error.cap(3) /* description */,
74                           QDir::fromNativeSeparators(m_error.cap(1)) /* file */,
75                           m_error.cap(2).toInt() /* line */,
76                           ProjectExplorer::Constants::TASK_CATEGORY_BUILDSYSTEM));
77         return;
78     }
79     IOutputParser::stdError(line);
80 }
81
82
83 // Unit tests:
84
85 #ifdef WITH_TESTS
86 #   include <QTest>
87
88 #   include "qt4projectmanagerplugin.h"
89
90 #   include "projectexplorer/outputparser_test.h"
91
92 using namespace Qt4ProjectManager::Internal;
93 using namespace ProjectExplorer;
94
95 void Qt4ProjectManagerPlugin::testQmakeOutputParsers_data()
96 {
97     QTest::addColumn<QString>("input");
98     QTest::addColumn<OutputParserTester::Channel>("inputChannel");
99     QTest::addColumn<QString>("childStdOutLines");
100     QTest::addColumn<QString>("childStdErrLines");
101     QTest::addColumn<QList<ProjectExplorer::Task> >("tasks");
102     QTest::addColumn<QString>("outputLines");
103
104
105     QTest::newRow("pass-through stdout")
106             << QString::fromLatin1("Sometext") << OutputParserTester::STDOUT
107             << QString::fromLatin1("Sometext") << QString()
108             << QList<ProjectExplorer::Task>()
109             << QString();
110     QTest::newRow("pass-through stderr")
111             << QString::fromLatin1("Sometext") << OutputParserTester::STDERR
112             << QString() << QString::fromLatin1("Sometext")
113             << QList<ProjectExplorer::Task>()
114             << QString();
115
116     QTest::newRow("qMake error")
117             << QString::fromLatin1("Project ERROR: undefined file")
118             << OutputParserTester::STDERR
119             << QString() << QString()
120             << (QList<ProjectExplorer::Task>()
121                 << Task(Task::Error,
122                         QLatin1String("undefined file"),
123                         QString(), -1,
124                         ProjectExplorer::Constants::TASK_CATEGORY_BUILDSYSTEM))
125             << QString();
126
127     QTest::newRow("qMake Parse Error")
128             << QString::fromLatin1("e:\\project.pro:14: Parse Error ('sth odd')")
129             << OutputParserTester::STDERR
130             << QString() << QString()
131             << (QList<ProjectExplorer::Task>()
132                 << Task(Task::Error,
133                         QLatin1String("Parse Error ('sth odd')"),
134                         QDir::fromNativeSeparators(QLatin1String("e:\\project.pro")),
135                         14,
136                         ProjectExplorer::Constants::TASK_CATEGORY_BUILDSYSTEM))
137             << QString();
138
139     QTest::newRow("qMake warning")
140             << QString::fromLatin1("Project WARNING: bearer module might require ReadUserData capability")
141             << OutputParserTester::STDERR
142             << QString() << QString()
143             << (QList<ProjectExplorer::Task>()
144                 << Task(Task::Warning,
145                         QLatin1String("bearer module might require ReadUserData capability"),
146                         QString(), -1,
147                         ProjectExplorer::Constants::TASK_CATEGORY_BUILDSYSTEM))
148             << QString();
149 }
150
151 void Qt4ProjectManagerPlugin::testQmakeOutputParsers()
152 {
153     OutputParserTester testbench;
154     testbench.appendOutputParser(new QMakeParser);
155     QFETCH(QString, input);
156     QFETCH(OutputParserTester::Channel, inputChannel);
157     QFETCH(QList<Task>, tasks);
158     QFETCH(QString, childStdOutLines);
159     QFETCH(QString, childStdErrLines);
160     QFETCH(QString, outputLines);
161
162     testbench.testParsing(input, inputChannel,
163                           tasks, childStdOutLines, childStdErrLines,
164                           outputLines);
165 }
166 #endif