~bzoltan/kubuntu-packaging/decouple_cmake_plugin

« back to all changes in this revision

Viewing changes to src/plugins/qmakeprojectmanager/qmakeparser.cpp

  • Committer: Timo Jyrinki
  • Date: 2013-12-02 09:16:15 UTC
  • mfrom: (1.1.29)
  • Revision ID: timo.jyrinki@canonical.com-20131202091615-xbj1os1f604ber1m
New upstream release candidate.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/****************************************************************************
 
2
**
 
3
** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
 
4
** Contact: http://www.qt-project.org/legal
 
5
**
 
6
** This file is part of Qt Creator.
 
7
**
 
8
** Commercial License Usage
 
9
** Licensees holding valid commercial Qt licenses may use this file in
 
10
** accordance with the commercial license agreement provided with the
 
11
** Software or, alternatively, in accordance with the terms contained in
 
12
** a written agreement between you and Digia.  For licensing terms and
 
13
** conditions see http://qt.digia.com/licensing.  For further information
 
14
** use the contact form at http://qt.digia.com/contact-us.
 
15
**
 
16
** GNU Lesser General Public License Usage
 
17
** Alternatively, this file may be used under the terms of the GNU Lesser
 
18
** General Public License version 2.1 as published by the Free Software
 
19
** Foundation and appearing in the file LICENSE.LGPL included in the
 
20
** packaging of this file.  Please review the following information to
 
21
** ensure the GNU Lesser General Public License version 2.1 requirements
 
22
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
 
23
**
 
24
** In addition, as a special exception, Digia gives you certain additional
 
25
** rights.  These rights are described in the Digia Qt LGPL Exception
 
26
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
 
27
**
 
28
****************************************************************************/
 
29
 
 
30
#include "qmakeparser.h"
 
31
 
 
32
#include <projectexplorer/task.h>
 
33
#include <projectexplorer/projectexplorerconstants.h>
 
34
 
 
35
using namespace QmakeProjectManager;
 
36
using namespace QmakeProjectManager::Internal;
 
37
using ProjectExplorer::Task;
 
38
 
 
39
QMakeParser::QMakeParser() : m_error(QLatin1String("^(.+):(\\d+):\\s(.+)$"))
 
40
{
 
41
    setObjectName(QLatin1String("QMakeParser"));
 
42
    m_error.setMinimal(true);
 
43
}
 
44
 
 
45
void QMakeParser::stdError(const QString &line)
 
46
{
 
47
    QString lne = rightTrimmed(line);
 
48
    if (lne.startsWith(QLatin1String("Project ERROR:"))) {
 
49
        const QString description = lne.mid(15);
 
50
        emit addTask(Task(Task::Error,
 
51
                          description,
 
52
                          Utils::FileName() /* filename */,
 
53
                          -1 /* linenumber */,
 
54
                          Core::Id(ProjectExplorer::Constants::TASK_CATEGORY_BUILDSYSTEM)));
 
55
        return;
 
56
    }
 
57
    if (lne.startsWith(QLatin1String("Project WARNING:"))) {
 
58
        const QString description = lne.mid(17);
 
59
        emit addTask(Task(Task::Warning,
 
60
                          description,
 
61
                          Utils::FileName() /* filename */,
 
62
                          -1 /* linenumber */,
 
63
                          Core::Id(ProjectExplorer::Constants::TASK_CATEGORY_BUILDSYSTEM)));
 
64
        return;
 
65
    }
 
66
    if (m_error.indexIn(lne) > -1) {
 
67
        QString fileName = m_error.cap(1);
 
68
        Task::TaskType type = Task::Error;
 
69
        if (fileName.startsWith(QLatin1String("WARNING: "))) {
 
70
            type = Task::Warning;
 
71
            fileName = fileName.mid(9);
 
72
        } else if (fileName.startsWith(QLatin1String("ERROR: "))) {
 
73
            fileName = fileName.mid(7);
 
74
        }
 
75
        emit addTask(Task(type,
 
76
                          m_error.cap(3) /* description */,
 
77
                          Utils::FileName::fromUserInput(fileName),
 
78
                          m_error.cap(2).toInt() /* line */,
 
79
                          Core::Id(ProjectExplorer::Constants::TASK_CATEGORY_BUILDSYSTEM)));
 
80
        return;
 
81
    }
 
82
    IOutputParser::stdError(line);
 
83
}
 
84
 
 
85
 
 
86
// Unit tests:
 
87
 
 
88
#ifdef WITH_TESTS
 
89
#   include <QTest>
 
90
 
 
91
#   include "qmakeprojectmanagerplugin.h"
 
92
 
 
93
#   include "projectexplorer/outputparser_test.h"
 
94
 
 
95
using namespace QmakeProjectManager::Internal;
 
96
using namespace ProjectExplorer;
 
97
 
 
98
void QmakeProjectManagerPlugin::testQmakeOutputParsers_data()
 
99
{
 
100
    const Core::Id categoryBuildSystem = Core::Id(ProjectExplorer::Constants::TASK_CATEGORY_BUILDSYSTEM);
 
101
    QTest::addColumn<QString>("input");
 
102
    QTest::addColumn<OutputParserTester::Channel>("inputChannel");
 
103
    QTest::addColumn<QString>("childStdOutLines");
 
104
    QTest::addColumn<QString>("childStdErrLines");
 
105
    QTest::addColumn<QList<ProjectExplorer::Task> >("tasks");
 
106
    QTest::addColumn<QString>("outputLines");
 
107
 
 
108
 
 
109
    QTest::newRow("pass-through stdout")
 
110
            << QString::fromLatin1("Sometext") << OutputParserTester::STDOUT
 
111
            << QString::fromLatin1("Sometext\n") << QString()
 
112
            << QList<ProjectExplorer::Task>()
 
113
            << QString();
 
114
    QTest::newRow("pass-through stderr")
 
115
            << QString::fromLatin1("Sometext") << OutputParserTester::STDERR
 
116
            << QString() << QString::fromLatin1("Sometext\n")
 
117
            << QList<ProjectExplorer::Task>()
 
118
            << QString();
 
119
 
 
120
    QTest::newRow("qMake error")
 
121
            << QString::fromLatin1("Project ERROR: undefined file")
 
122
            << OutputParserTester::STDERR
 
123
            << QString() << QString()
 
124
            << (QList<ProjectExplorer::Task>()
 
125
                << Task(Task::Error,
 
126
                        QLatin1String("undefined file"),
 
127
                        Utils::FileName(), -1,
 
128
                        categoryBuildSystem))
 
129
            << QString();
 
130
 
 
131
    QTest::newRow("qMake Parse Error")
 
132
            << QString::fromLatin1("e:\\project.pro:14: Parse Error ('sth odd')")
 
133
            << OutputParserTester::STDERR
 
134
            << QString() << QString()
 
135
            << (QList<ProjectExplorer::Task>()
 
136
                << Task(Task::Error,
 
137
                        QLatin1String("Parse Error ('sth odd')"),
 
138
                        Utils::FileName::fromUserInput(QLatin1String("e:\\project.pro")),
 
139
                        14,
 
140
                        categoryBuildSystem))
 
141
            << QString();
 
142
 
 
143
    QTest::newRow("qMake warning")
 
144
            << QString::fromLatin1("Project WARNING: bearer module might require ReadUserData capability")
 
145
            << OutputParserTester::STDERR
 
146
            << QString() << QString()
 
147
            << (QList<ProjectExplorer::Task>()
 
148
                << Task(Task::Warning,
 
149
                        QLatin1String("bearer module might require ReadUserData capability"),
 
150
                        Utils::FileName(), -1,
 
151
                        categoryBuildSystem))
 
152
            << QString();
 
153
 
 
154
    QTest::newRow("qMake warning with location")
 
155
            << QString::fromLatin1("WARNING: e:\\QtSDK\\Simulator\\Qt\\msvc2008\\lib\\qtmaind.prl:1: Unescaped backslashes are deprecated.")
 
156
            << OutputParserTester::STDERR
 
157
            << QString() << QString()
 
158
            << (QList<ProjectExplorer::Task>()
 
159
                << Task(Task::Warning,
 
160
                        QLatin1String("Unescaped backslashes are deprecated."),
 
161
                        Utils::FileName::fromUserInput(QLatin1String("e:\\QtSDK\\Simulator\\Qt\\msvc2008\\lib\\qtmaind.prl")), 1,
 
162
                        categoryBuildSystem))
 
163
            << QString();
 
164
}
 
165
 
 
166
void QmakeProjectManagerPlugin::testQmakeOutputParsers()
 
167
{
 
168
    OutputParserTester testbench;
 
169
    testbench.appendOutputParser(new QMakeParser);
 
170
    QFETCH(QString, input);
 
171
    QFETCH(OutputParserTester::Channel, inputChannel);
 
172
    QFETCH(QList<Task>, tasks);
 
173
    QFETCH(QString, childStdOutLines);
 
174
    QFETCH(QString, childStdErrLines);
 
175
    QFETCH(QString, outputLines);
 
176
 
 
177
    testbench.testParsing(input, inputChannel,
 
178
                          tasks, childStdOutLines, childStdErrLines,
 
179
                          outputLines);
 
180
}
 
181
#endif