genericmakestep.cpp 9.56 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"
34
#include "genericbuildconfiguration.h"
Roberto Raggi's avatar
Roberto Raggi committed
35

36
#include <extensionsystem/pluginmanager.h>
37
#include <projectexplorer/toolchain.h>
38
#include <projectexplorer/projectexplorer.h>
Tobias Hunger's avatar
Tobias Hunger committed
39
#include <projectexplorer/gnumakeparser.h>
40
#include <coreplugin/variablemanager.h>
41
#include <utils/qtcassert.h>
42

Roberto Raggi's avatar
Roberto Raggi committed
43 44 45 46 47 48 49 50 51
#include <QtGui/QFormLayout>
#include <QtGui/QGroupBox>
#include <QtGui/QCheckBox>
#include <QtGui/QLineEdit>
#include <QtGui/QListWidget>

using namespace GenericProjectManager;
using namespace GenericProjectManager::Internal;

Tobias Hunger's avatar
Tobias Hunger committed
52 53
GenericMakeStep::GenericMakeStep(ProjectExplorer::BuildConfiguration *bc) :
    AbstractProcessStep(bc)
Roberto Raggi's avatar
Roberto Raggi committed
54 55 56
{
}

Tobias Hunger's avatar
Tobias Hunger committed
57 58
GenericMakeStep::GenericMakeStep(GenericMakeStep *bs, ProjectExplorer::BuildConfiguration *bc) :
    AbstractProcessStep(bs, bc)
dt's avatar
Compile  
dt committed
59 60 61 62 63 64
{
    m_buildTargets = bs->m_buildTargets;
    m_makeArguments = bs->m_makeArguments;
    m_makeCommand = bs->m_makeCommand;
}

65
GenericMakeStep::~GenericMakeStep()
Roberto Raggi's avatar
Roberto Raggi committed
66 67 68
{
}

dt's avatar
dt committed
69 70 71 72 73
GenericBuildConfiguration *GenericMakeStep::genericBuildConfiguration() const
{
    return static_cast<GenericBuildConfiguration *>(buildConfiguration());
}

74
bool GenericMakeStep::init()
Roberto Raggi's avatar
Roberto Raggi committed
75
{
dt's avatar
dt committed
76
    GenericBuildConfiguration *bc = genericBuildConfiguration();
Roberto Raggi's avatar
Roberto Raggi committed
77

78
    setEnabled(true);
79
    Core::VariableManager *vm = Core::VariableManager::instance();
80
    const QString rawBuildDir = bc->buildDirectory();
81
    const QString buildDir = vm->resolve(rawBuildDir);
82
    setWorkingDirectory(buildDir);
83

84 85
    setCommand(makeCommand());
    setArguments(replacedArguments());
86

87
    setEnvironment(bc->environment());
Tobias Hunger's avatar
Tobias Hunger committed
88 89 90 91 92 93

    setOutputParser(new ProjectExplorer::GnuMakeParser(buildDir));
    if (bc->genericProject()->toolChain())
        appendOutputParser(bc->genericProject()->toolChain()->outputParser());

    return AbstractProcessStep::init();
94 95
}

96
void GenericMakeStep::restoreFromLocalMap(const QMap<QString, QVariant> &map)
97
{
98 99 100
    m_buildTargets = map.value("buildTargets").toStringList();
    m_makeArguments = map.value("makeArguments").toStringList();
    m_makeCommand = map.value("makeCommand").toString();
Tobias Hunger's avatar
Tobias Hunger committed
101
    ProjectExplorer::AbstractProcessStep::restoreFromLocalMap(map);
102 103
}

104
void GenericMakeStep::storeIntoLocalMap(QMap<QString, QVariant> &map)
105
{
106 107 108
    map["buildTargets"] = m_buildTargets;
    map["makeArguments"] = m_makeArguments;
    map["makeCommand"] = m_makeCommand;
Tobias Hunger's avatar
Tobias Hunger committed
109
    ProjectExplorer::AbstractProcessStep::storeIntoLocalMap(map);
110 111
}

112
QStringList GenericMakeStep::replacedArguments() const
113 114
{
    Core::VariableManager *vm = Core::VariableManager::instance();
115 116
    const QStringList targets = m_buildTargets;
    QStringList arguments = m_makeArguments;
117 118 119 120 121 122 123
    QStringList replacedArguments;
    foreach (const QString &arg, arguments) {
      replacedArguments.append(vm->resolve(arg));
    }
    foreach (const QString &arg, targets) {
      replacedArguments.append(vm->resolve(arg));
    }
124 125
    return replacedArguments;
}
126

127
QString GenericMakeStep::makeCommand() const
128
{
129
    QString command = m_makeCommand;
130
    if (command.isEmpty()) {
dt's avatar
dt committed
131
        GenericProject *pro = genericBuildConfiguration()->genericProject();
dt's avatar
dt committed
132
        if (ProjectExplorer::ToolChain *toolChain = pro->toolChain())
133 134 135 136 137
            command = toolChain->makeCommand();
        else
            command = QLatin1String("make");
    }
    return command;
Roberto Raggi's avatar
Roberto Raggi committed
138 139
}

140
void GenericMakeStep::run(QFutureInterface<bool> &fi)
Roberto Raggi's avatar
Roberto Raggi committed
141 142 143 144
{
    AbstractProcessStep::run(fi);
}

145
QString GenericMakeStep::id()
Roberto Raggi's avatar
Roberto Raggi committed
146 147 148 149
{
    return Constants::MAKESTEP;
}

150
QString GenericMakeStep::displayName()
Roberto Raggi's avatar
Roberto Raggi committed
151 152 153 154
{
    return "Make";
}

155
ProjectExplorer::BuildStepConfigWidget *GenericMakeStep::createConfigWidget()
Roberto Raggi's avatar
Roberto Raggi committed
156
{
157
    return new GenericMakeStepConfigWidget(this);
Roberto Raggi's avatar
Roberto Raggi committed
158 159
}

160
bool GenericMakeStep::immutable() const
Roberto Raggi's avatar
Roberto Raggi committed
161 162 163 164
{
    return true;
}

165
bool GenericMakeStep::buildsTarget(const QString &target) const
Roberto Raggi's avatar
Roberto Raggi committed
166
{
167
    return m_buildTargets.contains(target);
Roberto Raggi's avatar
Roberto Raggi committed
168 169
}

170
void GenericMakeStep::setBuildTarget(const QString &target, bool on)
Roberto Raggi's avatar
Roberto Raggi committed
171
{
172
    QStringList old = m_buildTargets;
Roberto Raggi's avatar
Roberto Raggi committed
173
    if (on && !old.contains(target))
174
         old << target;
Roberto Raggi's avatar
Roberto Raggi committed
175
    else if(!on && old.contains(target))
176
        old.removeOne(target);
177

178
    m_buildTargets = old;
Roberto Raggi's avatar
Roberto Raggi committed
179 180 181
}

//
182
// GenericMakeStepConfigWidget
Roberto Raggi's avatar
Roberto Raggi committed
183
//
184 185

GenericMakeStepConfigWidget::GenericMakeStepConfigWidget(GenericMakeStep *makeStep)
Roberto Raggi's avatar
Roberto Raggi committed
186 187
    : m_makeStep(makeStep)
{
188 189
    m_ui = new Ui::GenericMakeStep;
    m_ui->setupUi(this);
Roberto Raggi's avatar
Roberto Raggi committed
190 191

    // TODO update this list also on rescans of the GenericLists.txt
dt's avatar
dt committed
192
    GenericProject *pro = m_makeStep->genericBuildConfiguration()->genericProject();
193 194
    foreach (const QString &target, pro->targets()) {
        QListWidgetItem *item = new QListWidgetItem(target, m_ui->targetsList);
Roberto Raggi's avatar
Roberto Raggi committed
195 196 197 198
        item->setFlags(item->flags() | Qt::ItemIsUserCheckable);
        item->setCheckState(Qt::Unchecked);
    }

199 200
    connect(m_ui->targetsList, SIGNAL(itemChanged(QListWidgetItem*)),
            this, SLOT(itemChanged(QListWidgetItem*)));
201
    connect(m_ui->makeLineEdit, SIGNAL(textEdited(QString)),
202
            this, SLOT(makeLineEditTextEdited()));
203
    connect(m_ui->makeArgumentsLineEdit, SIGNAL(textEdited(QString)),
204
            this, SLOT(makeArgumentsLineEditTextEdited()));
205 206 207 208 209

    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
210 211
}

212
QString GenericMakeStepConfigWidget::displayName() const
Roberto Raggi's avatar
Roberto Raggi committed
213 214 215 216
{
    return "Make";
}

217 218 219
// TODO: Label should update when tool chain is changed
void GenericMakeStepConfigWidget::updateMakeOverrrideLabel()
{
220
    m_ui->makeLabel->setText(tr("Override %1:").arg(m_makeStep->makeCommand()));
221 222
}

223
void GenericMakeStepConfigWidget::init()
Roberto Raggi's avatar
Roberto Raggi committed
224
{
225
    updateMakeOverrrideLabel();
226

227
    QString makeCommand = m_makeStep->m_makeCommand;
228 229
    m_ui->makeLineEdit->setText(makeCommand);

230
    const QStringList &makeArguments = m_makeStep->m_makeArguments;
231 232 233 234 235 236 237 238
    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);
239
        item->setCheckState(m_makeStep->buildsTarget(item->text()) ? Qt::Checked : Qt::Unchecked);
Roberto Raggi's avatar
Roberto Raggi committed
240
    }
241

242
    updateDetails();
Roberto Raggi's avatar
Roberto Raggi committed
243
    // and connect again
244 245 246
    connect(m_ui->targetsList, SIGNAL(itemChanged(QListWidgetItem*)), this, SLOT(itemChanged(QListWidgetItem*)));
}

247 248 249
void GenericMakeStepConfigWidget::updateDetails()
{
    m_summaryText = tr("<b>Make:</b> %1 %2")
250 251
                    .arg(m_makeStep->makeCommand(),
                         ProjectExplorer::Environment::joinArgumentList(m_makeStep->replacedArguments()));
252 253 254
    emit updateSummary();
}

dt's avatar
dt committed
255 256
QString GenericMakeStepConfigWidget::summaryText() const
{
257
    return m_summaryText;
dt's avatar
dt committed
258 259
}

260 261
void GenericMakeStepConfigWidget::itemChanged(QListWidgetItem *item)
{
262
    m_makeStep->setBuildTarget(item->text(), item->checkState() & Qt::Checked);
263
    updateDetails();
264 265 266 267
}

void GenericMakeStepConfigWidget::makeLineEditTextEdited()
{
268
    m_makeStep->m_makeCommand = m_ui->makeLineEdit->text();
269
    updateDetails();
270 271 272 273
}

void GenericMakeStepConfigWidget::makeArgumentsLineEditTextEdited()
{
274 275
    m_makeStep->m_makeArguments =
            ProjectExplorer::Environment::parseCombinedArgString(m_ui->makeArgumentsLineEdit->text());
276
    updateDetails();
Roberto Raggi's avatar
Roberto Raggi committed
277 278 279
}

//
280
// GenericMakeStepFactory
Roberto Raggi's avatar
Roberto Raggi committed
281 282
//

283
bool GenericMakeStepFactory::canCreate(const QString &id) const
Roberto Raggi's avatar
Roberto Raggi committed
284
{
285
    return (Constants::MAKESTEP == id);
Roberto Raggi's avatar
Roberto Raggi committed
286 287
}

dt's avatar
dt committed
288
ProjectExplorer::BuildStep *GenericMakeStepFactory::create(ProjectExplorer::BuildConfiguration *bc,
289
                                                           const QString &id) const
Roberto Raggi's avatar
Roberto Raggi committed
290
{
291
    Q_ASSERT(id == Constants::MAKESTEP);
dt's avatar
dt committed
292
    return new GenericMakeStep(bc);
293 294 295 296 297 298
}

ProjectExplorer::BuildStep *GenericMakeStepFactory::clone(ProjectExplorer::BuildStep *bs,
                                                          ProjectExplorer::BuildConfiguration *bc) const
{
    return new GenericMakeStep(static_cast<GenericMakeStep*>(bs), bc);
Roberto Raggi's avatar
Roberto Raggi committed
299 300
}

301
QStringList GenericMakeStepFactory::canCreateForBuildConfiguration(ProjectExplorer::BuildConfiguration *bc) const
Roberto Raggi's avatar
Roberto Raggi committed
302
{
303
    Q_UNUSED(bc);
Roberto Raggi's avatar
Roberto Raggi committed
304 305 306
    return QStringList();
}

307
QString GenericMakeStepFactory::displayNameForId(const QString &id) const
Roberto Raggi's avatar
Roberto Raggi committed
308
{
309
    QTC_ASSERT(id == Constants::MAKESTEP, return QString());
Roberto Raggi's avatar
Roberto Raggi committed
310 311
    return "Make";
}