genericmakestep.cpp 9.11 KB
Newer Older
Roberto Raggi's avatar
Roberto Raggi committed
1
2
3
4
5
6
/**************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
**
7
** Contact: Nokia Corporation (qt-info@nokia.com)
Roberto Raggi's avatar
Roberto Raggi committed
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
**
** Commercial Usage
**
** Licensees holding valid Qt Commercial licenses may use this file in
** accordance with the Qt Commercial License Agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Nokia.
**
** GNU Lesser General Public License Usage
**
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file.  Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** If you are unsure which license is appropriate for your use, please
hjk's avatar
hjk committed
26
** contact the sales department at http://qt.nokia.com/contact.
Roberto Raggi's avatar
Roberto Raggi committed
27
28
29
**
**************************************************************************/

30
#include "genericmakestep.h"
Roberto Raggi's avatar
Roberto Raggi committed
31
32
#include "genericprojectconstants.h"
#include "genericproject.h"
33
#include "ui_genericmakestep.h"
Roberto Raggi's avatar
Roberto Raggi committed
34

35
#include <extensionsystem/pluginmanager.h>
36
#include <projectexplorer/toolchain.h>
Roberto Raggi's avatar
Roberto Raggi committed
37
#include <utils/qtcassert.h>
38
#include <coreplugin/variablemanager.h>
39

Roberto Raggi's avatar
Roberto Raggi committed
40
41
42
43
44
45
46
47
48
#include <QtGui/QFormLayout>
#include <QtGui/QGroupBox>
#include <QtGui/QCheckBox>
#include <QtGui/QLineEdit>
#include <QtGui/QListWidget>

using namespace GenericProjectManager;
using namespace GenericProjectManager::Internal;

49
GenericMakeStep::GenericMakeStep(GenericProject *pro)
50
    : AbstractMakeStep(pro), m_pro(pro)
Roberto Raggi's avatar
Roberto Raggi committed
51
52
53
{
}

54
GenericMakeStep::~GenericMakeStep()
Roberto Raggi's avatar
Roberto Raggi committed
55
56
57
{
}

58
bool GenericMakeStep::init(const QString &buildConfiguration)
Roberto Raggi's avatar
Roberto Raggi committed
59
60
{
    const QString buildParser = m_pro->buildParser(buildConfiguration);
61
    setBuildParser(buildParser);
Roberto Raggi's avatar
Roberto Raggi committed
62
63
64
    qDebug() << "*** build parser:" << buildParser;

    setEnabled(buildConfiguration, true);
65
66
67
68
    Core::VariableManager *vm = Core::VariableManager::instance();
    const QString rawBuildDir = m_pro->buildDirectory(buildConfiguration);
    const QString buildDir = vm->resolve(rawBuildDir);
    setWorkingDirectory(buildConfiguration, buildDir);
69

70
71
    setCommand(buildConfiguration, makeCommand(buildConfiguration));
    setArguments(buildConfiguration, replacedArguments(buildConfiguration));
72

73
74
75
76
77
78
79
    setEnvironment(buildConfiguration, m_pro->environment(buildConfiguration));
    return AbstractMakeStep::init(buildConfiguration);
}

QStringList GenericMakeStep::replacedArguments(const QString &buildConfiguration) const
{
    Core::VariableManager *vm = Core::VariableManager::instance();
80
81
    const QStringList targets = value(buildConfiguration, "buildTargets").toStringList();
    QStringList arguments = value(buildConfiguration, "makeArguments").toStringList();
82
83
84
85
86
87
88
    QStringList replacedArguments;
    foreach (const QString &arg, arguments) {
      replacedArguments.append(vm->resolve(arg));
    }
    foreach (const QString &arg, targets) {
      replacedArguments.append(vm->resolve(arg));
    }
89
90
    return replacedArguments;
}
91

92
93
94
95
96
97
98
99
100
101
QString GenericMakeStep::makeCommand(const QString &buildConfiguration) const
{
    QString command = value(buildConfiguration, "makeCommand").toString();
    if (command.isEmpty()) {
        if (ProjectExplorer::ToolChain *toolChain = m_pro->toolChain())
            command = toolChain->makeCommand();
        else
            command = QLatin1String("make");
    }
    return command;
Roberto Raggi's avatar
Roberto Raggi committed
102
103
}

104
void GenericMakeStep::run(QFutureInterface<bool> &fi)
Roberto Raggi's avatar
Roberto Raggi committed
105
106
107
108
{
    AbstractProcessStep::run(fi);
}

109
QString GenericMakeStep::name()
Roberto Raggi's avatar
Roberto Raggi committed
110
111
112
113
{
    return Constants::MAKESTEP;
}

114
QString GenericMakeStep::displayName()
Roberto Raggi's avatar
Roberto Raggi committed
115
116
117
118
{
    return "Make";
}

119
ProjectExplorer::BuildStepConfigWidget *GenericMakeStep::createConfigWidget()
Roberto Raggi's avatar
Roberto Raggi committed
120
{
121
    return new GenericMakeStepConfigWidget(this);
Roberto Raggi's avatar
Roberto Raggi committed
122
123
}

124
bool GenericMakeStep::immutable() const
Roberto Raggi's avatar
Roberto Raggi committed
125
126
127
128
{
    return true;
}

129
GenericProject *GenericMakeStep::project() const
Roberto Raggi's avatar
Roberto Raggi committed
130
131
132
133
{
    return m_pro;
}

134
bool GenericMakeStep::buildsTarget(const QString &buildConfiguration, const QString &target) const
Roberto Raggi's avatar
Roberto Raggi committed
135
136
137
138
{
    return value(buildConfiguration, "buildTargets").toStringList().contains(target);
}

139
void GenericMakeStep::setBuildTarget(const QString &buildConfiguration, const QString &target, bool on)
Roberto Raggi's avatar
Roberto Raggi committed
140
141
142
143
144
145
146
147
148
{
    QStringList old = value(buildConfiguration, "buildTargets").toStringList();
    if (on && !old.contains(target))
        setValue(buildConfiguration, "buildTargets", old << target);
    else if(!on && old.contains(target))
        setValue(buildConfiguration, "buildTargets", old.removeOne(target));
}

//
149
// GenericMakeStepConfigWidget
Roberto Raggi's avatar
Roberto Raggi committed
150
//
151
152

GenericMakeStepConfigWidget::GenericMakeStepConfigWidget(GenericMakeStep *makeStep)
Roberto Raggi's avatar
Roberto Raggi committed
153
154
    : m_makeStep(makeStep)
{
155
156
    m_ui = new Ui::GenericMakeStep;
    m_ui->setupUi(this);
Roberto Raggi's avatar
Roberto Raggi committed
157
158
159

    // TODO update this list also on rescans of the GenericLists.txt
    GenericProject *pro = m_makeStep->project();
160
161
    foreach (const QString &target, pro->targets()) {
        QListWidgetItem *item = new QListWidgetItem(target, m_ui->targetsList);
Roberto Raggi's avatar
Roberto Raggi committed
162
163
164
165
        item->setFlags(item->flags() | Qt::ItemIsUserCheckable);
        item->setCheckState(Qt::Unchecked);
    }

166
167
    connect(m_ui->targetsList, SIGNAL(itemChanged(QListWidgetItem*)),
            this, SLOT(itemChanged(QListWidgetItem*)));
168
    connect(m_ui->makeLineEdit, SIGNAL(textEdited(QString)),
169
            this, SLOT(makeLineEditTextEdited()));
170
    connect(m_ui->makeArgumentsLineEdit, SIGNAL(textEdited(QString)),
171
            this, SLOT(makeArgumentsLineEditTextEdited()));
172
173
174
175
176

    connect(ProjectExplorer::ProjectExplorerPlugin::instance(), SIGNAL(settingsChanged()),
            this, SLOT(updateMakeOverrrideLabel()));
    connect(ProjectExplorer::ProjectExplorerPlugin::instance(), SIGNAL(settingsChanged()),
            this, SLOT(updateDetails()));
Roberto Raggi's avatar
Roberto Raggi committed
177
178
}

179
QString GenericMakeStepConfigWidget::displayName() const
Roberto Raggi's avatar
Roberto Raggi committed
180
181
182
183
{
    return "Make";
}

184
185
186
187
188
189
// TODO: Label should update when tool chain is changed
void GenericMakeStepConfigWidget::updateMakeOverrrideLabel()
{
    m_ui->makeLabel->setText(tr("Override %1:").arg(m_makeStep->makeCommand(m_buildConfiguration)));
}

190
void GenericMakeStepConfigWidget::init(const QString &buildConfiguration)
Roberto Raggi's avatar
Roberto Raggi committed
191
192
{
    m_buildConfiguration = buildConfiguration;
193

194
    updateMakeOverrrideLabel();
195

196
    QString makeCommand = m_makeStep->value(buildConfiguration, "makeCommand").toString();
197
198
199
200
201
202
203
204
205
206
207
208
    m_ui->makeLineEdit->setText(makeCommand);

    const QStringList &makeArguments =
            m_makeStep->value(buildConfiguration, "makeArguments").toStringList();
    m_ui->makeArgumentsLineEdit->setText(ProjectExplorer::Environment::joinArgumentList(makeArguments));

    // Disconnect to make the changes to the items
    disconnect(m_ui->targetsList, SIGNAL(itemChanged(QListWidgetItem*)), this, SLOT(itemChanged(QListWidgetItem*)));

    int count = m_ui->targetsList->count();
    for (int i = 0; i < count; ++i) {
        QListWidgetItem *item = m_ui->targetsList->item(i);
Roberto Raggi's avatar
Roberto Raggi committed
209
210
        item->setCheckState(m_makeStep->buildsTarget(buildConfiguration, item->text()) ? Qt::Checked : Qt::Unchecked);
    }
211

212
    updateDetails();
Roberto Raggi's avatar
Roberto Raggi committed
213
    // and connect again
214
215
216
    connect(m_ui->targetsList, SIGNAL(itemChanged(QListWidgetItem*)), this, SLOT(itemChanged(QListWidgetItem*)));
}

217
218
219
220
221
222
223
224
void GenericMakeStepConfigWidget::updateDetails()
{
    m_summaryText = tr("<b>Make:</b> %1 %2")
                    .arg(m_makeStep->makeCommand(m_buildConfiguration),
                         ProjectExplorer::Environment::joinArgumentList(m_makeStep->replacedArguments(m_buildConfiguration)));
    emit updateSummary();
}

dt's avatar
dt committed
225
226
QString GenericMakeStepConfigWidget::summaryText() const
{
227
    return m_summaryText;
dt's avatar
dt committed
228
229
}

230
231
232
233
void GenericMakeStepConfigWidget::itemChanged(QListWidgetItem *item)
{
    QTC_ASSERT(!m_buildConfiguration.isNull(), return);
    m_makeStep->setBuildTarget(m_buildConfiguration, item->text(), item->checkState() & Qt::Checked);
234
    updateDetails();
235
236
237
238
239
240
}

void GenericMakeStepConfigWidget::makeLineEditTextEdited()
{
    QTC_ASSERT(!m_buildConfiguration.isNull(), return);
    m_makeStep->setValue(m_buildConfiguration, "makeCommand", m_ui->makeLineEdit->text());
241
    updateDetails();
242
243
244
245
246
247
248
}

void GenericMakeStepConfigWidget::makeArgumentsLineEditTextEdited()
{
    QTC_ASSERT(!m_buildConfiguration.isNull(), return);
    m_makeStep->setValue(m_buildConfiguration, "makeArguments",
                         ProjectExplorer::Environment::parseCombinedArgString(m_ui->makeArgumentsLineEdit->text()));
249
    updateDetails();
Roberto Raggi's avatar
Roberto Raggi committed
250
251
252
}

//
253
// GenericMakeStepFactory
Roberto Raggi's avatar
Roberto Raggi committed
254
255
//

256
bool GenericMakeStepFactory::canCreate(const QString &name) const
Roberto Raggi's avatar
Roberto Raggi committed
257
258
259
260
{
    return (Constants::MAKESTEP == name);
}

261
ProjectExplorer::BuildStep *GenericMakeStepFactory::create(ProjectExplorer::Project *project, const QString &name) const
Roberto Raggi's avatar
Roberto Raggi committed
262
263
264
265
{
    Q_ASSERT(name == Constants::MAKESTEP);
    GenericProject *pro = qobject_cast<GenericProject *>(project);
    Q_ASSERT(pro);
266
    return new GenericMakeStep(pro);
Roberto Raggi's avatar
Roberto Raggi committed
267
268
}

269
QStringList GenericMakeStepFactory::canCreateForProject(ProjectExplorer::Project * /* pro */) const
Roberto Raggi's avatar
Roberto Raggi committed
270
271
272
273
{
    return QStringList();
}

274
QString GenericMakeStepFactory::displayNameForName(const QString & /* name */) const
Roberto Raggi's avatar
Roberto Raggi committed
275
276
277
{
    return "Make";
}