genericmakestep.cpp 9.49 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

Roberto Raggi's avatar
Roberto Raggi committed
42 43 44 45 46 47 48 49 50
#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
51 52
GenericMakeStep::GenericMakeStep(ProjectExplorer::BuildConfiguration *bc) :
    AbstractProcessStep(bc)
Roberto Raggi's avatar
Roberto Raggi committed
53 54 55
{
}

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

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

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

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

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

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

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

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

    return AbstractProcessStep::init();
93 94
}

95
void GenericMakeStep::restoreFromLocalMap(const QMap<QString, QVariant> &map)
96
{
97 98 99
    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
100
    ProjectExplorer::AbstractProcessStep::restoreFromLocalMap(map);
101 102
}

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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
298 299
}

300
QStringList GenericMakeStepFactory::canCreateForBuildConfiguration(ProjectExplorer::BuildConfiguration * /* pro */) const
Roberto Raggi's avatar
Roberto Raggi committed
301 302 303 304
{
    return QStringList();
}

305
QString GenericMakeStepFactory::displayNameForName(const QString & /* name */) const
Roberto Raggi's avatar
Roberto Raggi committed
306 307 308
{
    return "Make";
}