genericmakestep.cpp 9.36 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>
37
#include <projectexplorer/projectexplorer.h>
Roberto Raggi's avatar
Roberto Raggi committed
38
#include <utils/qtcassert.h>
39
#include <coreplugin/variablemanager.h>
40

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

using namespace GenericProjectManager;
using namespace GenericProjectManager::Internal;

dt's avatar
dt committed
50 51
GenericMakeStep::GenericMakeStep(ProjectExplorer::BuildConfiguration *bc)
    : AbstractMakeStep(bc)
Roberto Raggi's avatar
Roberto Raggi committed
52 53 54
{
}

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

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

67
bool GenericMakeStep::init()
Roberto Raggi's avatar
Roberto Raggi committed
68
{
69
    ProjectExplorer::BuildConfiguration *bc = buildConfiguration();
dt's avatar
dt committed
70 71 72
    //TODO
    GenericProject *pro = static_cast<GenericProject *>(buildConfiguration()->project());
    const QString buildParser = pro->buildParser(bc);
73
    setBuildParser(buildParser);
Roberto Raggi's avatar
Roberto Raggi committed
74

75
    setEnabled(true);
76
    Core::VariableManager *vm = Core::VariableManager::instance();
dt's avatar
dt committed
77
    const QString rawBuildDir = buildConfiguration()->project()->buildDirectory(bc);
78
    const QString buildDir = vm->resolve(rawBuildDir);
79
    setWorkingDirectory(buildDir);
80

81 82
    setCommand(makeCommand());
    setArguments(replacedArguments());
83

dt's avatar
dt committed
84
    setEnvironment(buildConfiguration()->project()->environment(bc));
85
    return AbstractMakeStep::init();
86 87
}

88
void GenericMakeStep::restoreFromLocalMap(const QMap<QString, QVariant> &map)
89
{
90 91 92 93
    m_buildTargets = map.value("buildTargets").toStringList();
    m_makeArguments = map.value("makeArguments").toStringList();
    m_makeCommand = map.value("makeCommand").toString();
    ProjectExplorer::AbstractMakeStep::restoreFromLocalMap(map);
94 95
}

96
void GenericMakeStep::storeIntoLocalMap(QMap<QString, QVariant> &map)
97
{
98 99 100 101
    map["buildTargets"] = m_buildTargets;
    map["makeArguments"] = m_makeArguments;
    map["makeCommand"] = m_makeCommand;
    ProjectExplorer::AbstractMakeStep::storeIntoLocalMap(map);
102 103
}

104
QStringList GenericMakeStep::replacedArguments() const
105 106
{
    Core::VariableManager *vm = Core::VariableManager::instance();
107 108
    const QStringList targets = m_buildTargets;
    QStringList arguments = m_makeArguments;
109 110 111 112 113 114 115
    QStringList replacedArguments;
    foreach (const QString &arg, arguments) {
      replacedArguments.append(vm->resolve(arg));
    }
    foreach (const QString &arg, targets) {
      replacedArguments.append(vm->resolve(arg));
    }
116 117
    return replacedArguments;
}
118

119
QString GenericMakeStep::makeCommand() const
120
{
121
    QString command = m_makeCommand;
122
    if (command.isEmpty()) {
dt's avatar
dt committed
123 124 125
        // TODO
        GenericProject *pro = static_cast<GenericProject *>(buildConfiguration()->project());
        if (ProjectExplorer::ToolChain *toolChain = pro->toolChain())
126 127 128 129 130
            command = toolChain->makeCommand();
        else
            command = QLatin1String("make");
    }
    return command;
Roberto Raggi's avatar
Roberto Raggi committed
131 132
}

133
void GenericMakeStep::run(QFutureInterface<bool> &fi)
Roberto Raggi's avatar
Roberto Raggi committed
134 135 136 137
{
    AbstractProcessStep::run(fi);
}

138
QString GenericMakeStep::name()
Roberto Raggi's avatar
Roberto Raggi committed
139 140 141 142
{
    return Constants::MAKESTEP;
}

143
QString GenericMakeStep::displayName()
Roberto Raggi's avatar
Roberto Raggi committed
144 145 146 147
{
    return "Make";
}

148
ProjectExplorer::BuildStepConfigWidget *GenericMakeStep::createConfigWidget()
Roberto Raggi's avatar
Roberto Raggi committed
149
{
150
    return new GenericMakeStepConfigWidget(this);
Roberto Raggi's avatar
Roberto Raggi committed
151 152
}

153
bool GenericMakeStep::immutable() const
Roberto Raggi's avatar
Roberto Raggi committed
154 155 156 157
{
    return true;
}

158
bool GenericMakeStep::buildsTarget(const QString &target) const
Roberto Raggi's avatar
Roberto Raggi committed
159
{
160
    return m_buildTargets.contains(target);
Roberto Raggi's avatar
Roberto Raggi committed
161 162
}

163
void GenericMakeStep::setBuildTarget(const QString &target, bool on)
Roberto Raggi's avatar
Roberto Raggi committed
164
{
165
    QStringList old = m_buildTargets;
Roberto Raggi's avatar
Roberto Raggi committed
166
    if (on && !old.contains(target))
167
         old << target;
Roberto Raggi's avatar
Roberto Raggi committed
168
    else if(!on && old.contains(target))
169
        old.removeOne(target);
170

171
    m_buildTargets = old;
Roberto Raggi's avatar
Roberto Raggi committed
172 173 174
}

//
175
// GenericMakeStepConfigWidget
Roberto Raggi's avatar
Roberto Raggi committed
176
//
177 178

GenericMakeStepConfigWidget::GenericMakeStepConfigWidget(GenericMakeStep *makeStep)
Roberto Raggi's avatar
Roberto Raggi committed
179 180
    : m_makeStep(makeStep)
{
181 182
    m_ui = new Ui::GenericMakeStep;
    m_ui->setupUi(this);
Roberto Raggi's avatar
Roberto Raggi committed
183 184

    // TODO update this list also on rescans of the GenericLists.txt
dt's avatar
dt committed
185 186
    //TODO
    GenericProject *pro = static_cast<GenericProject *>(m_makeStep->buildConfiguration()->project());
187 188
    foreach (const QString &target, pro->targets()) {
        QListWidgetItem *item = new QListWidgetItem(target, m_ui->targetsList);
Roberto Raggi's avatar
Roberto Raggi committed
189 190 191 192
        item->setFlags(item->flags() | Qt::ItemIsUserCheckable);
        item->setCheckState(Qt::Unchecked);
    }

193 194
    connect(m_ui->targetsList, SIGNAL(itemChanged(QListWidgetItem*)),
            this, SLOT(itemChanged(QListWidgetItem*)));
195
    connect(m_ui->makeLineEdit, SIGNAL(textEdited(QString)),
196
            this, SLOT(makeLineEditTextEdited()));
197
    connect(m_ui->makeArgumentsLineEdit, SIGNAL(textEdited(QString)),
198
            this, SLOT(makeArgumentsLineEditTextEdited()));
199 200 201 202 203

    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
204 205
}

206
QString GenericMakeStepConfigWidget::displayName() const
Roberto Raggi's avatar
Roberto Raggi committed
207 208 209 210
{
    return "Make";
}

211 212 213
// TODO: Label should update when tool chain is changed
void GenericMakeStepConfigWidget::updateMakeOverrrideLabel()
{
214
    m_ui->makeLabel->setText(tr("Override %1:").arg(m_makeStep->makeCommand()));
215 216
}

217
void GenericMakeStepConfigWidget::init()
Roberto Raggi's avatar
Roberto Raggi committed
218
{
219
    updateMakeOverrrideLabel();
220

221
    QString makeCommand = m_makeStep->m_makeCommand;
222 223
    m_ui->makeLineEdit->setText(makeCommand);

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

236
    updateDetails();
Roberto Raggi's avatar
Roberto Raggi committed
237
    // and connect again
238 239 240
    connect(m_ui->targetsList, SIGNAL(itemChanged(QListWidgetItem*)), this, SLOT(itemChanged(QListWidgetItem*)));
}

241 242 243
void GenericMakeStepConfigWidget::updateDetails()
{
    m_summaryText = tr("<b>Make:</b> %1 %2")
244 245
                    .arg(m_makeStep->makeCommand(),
                         ProjectExplorer::Environment::joinArgumentList(m_makeStep->replacedArguments()));
246 247 248
    emit updateSummary();
}

dt's avatar
dt committed
249 250
QString GenericMakeStepConfigWidget::summaryText() const
{
251
    return m_summaryText;
dt's avatar
dt committed
252 253
}

254 255
void GenericMakeStepConfigWidget::itemChanged(QListWidgetItem *item)
{
256
    m_makeStep->setBuildTarget(item->text(), item->checkState() & Qt::Checked);
257
    updateDetails();
258 259 260 261
}

void GenericMakeStepConfigWidget::makeLineEditTextEdited()
{
262
    m_makeStep->m_makeCommand = m_ui->makeLineEdit->text();
263
    updateDetails();
264 265 266 267
}

void GenericMakeStepConfigWidget::makeArgumentsLineEditTextEdited()
{
268 269
    m_makeStep->m_makeArguments =
            ProjectExplorer::Environment::parseCombinedArgString(m_ui->makeArgumentsLineEdit->text());
270
    updateDetails();
Roberto Raggi's avatar
Roberto Raggi committed
271 272 273
}

//
274
// GenericMakeStepFactory
Roberto Raggi's avatar
Roberto Raggi committed
275 276
//

277
bool GenericMakeStepFactory::canCreate(const QString &name) const
Roberto Raggi's avatar
Roberto Raggi committed
278 279 280 281
{
    return (Constants::MAKESTEP == name);
}

dt's avatar
dt committed
282
ProjectExplorer::BuildStep *GenericMakeStepFactory::create(ProjectExplorer::BuildConfiguration *bc,
283
                                                           const QString &name) const
Roberto Raggi's avatar
Roberto Raggi committed
284 285
{
    Q_ASSERT(name == Constants::MAKESTEP);
dt's avatar
dt committed
286
    return new GenericMakeStep(bc);
287 288 289 290 291 292
}

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
293 294
}

295
QStringList GenericMakeStepFactory::canCreateForProject(ProjectExplorer::Project * /* pro */) const
Roberto Raggi's avatar
Roberto Raggi committed
296 297 298 299
{
    return QStringList();
}

300
QString GenericMakeStepFactory::displayNameForName(const QString & /* name */) const
Roberto Raggi's avatar
Roberto Raggi committed
301 302 303
{
    return "Make";
}