genericmakestep.cpp 10.2 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;

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

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

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

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

72 73
    setCommand(makeCommand(buildConfigurationName));
    setArguments(replacedArguments(buildConfigurationName));
74

75
    setEnvironment(m_pro->environment(bc));
76
    return AbstractMakeStep::init(buildConfigurationName);
77 78
}

79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110
void GenericMakeStep::restoreFromMap(const QString &buildConfiguration, const QMap<QString, QVariant> &map)
{
    m_values[buildConfiguration].buildTargets = map.value("buildTargets").toStringList();
    m_values[buildConfiguration].makeArguments = map.value("makeArguments").toStringList();
    m_values[buildConfiguration].makeCommand = map.value("makeCommand").toString();
    ProjectExplorer::AbstractMakeStep::restoreFromMap(buildConfiguration, map);
}

void GenericMakeStep::storeIntoMap(const QString &buildConfiguration, QMap<QString, QVariant> &map)
{
    map["buildTargets"] = m_values.value(buildConfiguration).buildTargets;
    map["makeArguments"] = m_values.value(buildConfiguration).makeArguments;
    map["makeCommand"] = m_values.value(buildConfiguration).makeCommand;
    ProjectExplorer::AbstractMakeStep::storeIntoMap(buildConfiguration, map);
}

void GenericMakeStep::addBuildConfiguration(const QString & name)
{
    m_values.insert(name, GenericMakeStepSettings());
}

void GenericMakeStep::removeBuildConfiguration(const QString & name)
{
    m_values.remove(name);
}

void GenericMakeStep::copyBuildConfiguration(const QString &source, const QString &dest)
{
    m_values.insert(dest, m_values.value(source));
}


111 112 113
QStringList GenericMakeStep::replacedArguments(const QString &buildConfiguration) const
{
    Core::VariableManager *vm = Core::VariableManager::instance();
114 115
    const QStringList targets = m_values.value(buildConfiguration).buildTargets;
    QStringList arguments = m_values.value(buildConfiguration).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 127
QString GenericMakeStep::makeCommand(const QString &buildConfiguration) const
{
128
    QString command = m_values.value(buildConfiguration).makeCommand;
129 130 131 132 133 134 135
    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
136 137
}

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

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

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

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

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

163
GenericProject *GenericMakeStep::project() const
Roberto Raggi's avatar
Roberto Raggi committed
164 165 166 167
{
    return m_pro;
}

168
bool GenericMakeStep::buildsTarget(const QString &buildConfiguration, const QString &target) const
Roberto Raggi's avatar
Roberto Raggi committed
169
{
170
    return m_values.value(buildConfiguration).buildTargets.contains(target);
Roberto Raggi's avatar
Roberto Raggi committed
171 172
}

173
void GenericMakeStep::setBuildTarget(const QString &buildConfiguration, const QString &target, bool on)
Roberto Raggi's avatar
Roberto Raggi committed
174
{
175
    QStringList old = m_values.value(buildConfiguration).buildTargets;
Roberto Raggi's avatar
Roberto Raggi committed
176
    if (on && !old.contains(target))
177
         old << target;
Roberto Raggi's avatar
Roberto Raggi committed
178
    else if(!on && old.contains(target))
179
        old.removeOne(target);
180 181

    m_values[buildConfiguration].buildTargets = old;
Roberto Raggi's avatar
Roberto Raggi committed
182 183 184
}

//
185
// GenericMakeStepConfigWidget
Roberto Raggi's avatar
Roberto Raggi committed
186
//
187 188

GenericMakeStepConfigWidget::GenericMakeStepConfigWidget(GenericMakeStep *makeStep)
Roberto Raggi's avatar
Roberto Raggi committed
189 190
    : m_makeStep(makeStep)
{
191 192
    m_ui = new Ui::GenericMakeStep;
    m_ui->setupUi(this);
Roberto Raggi's avatar
Roberto Raggi committed
193 194 195

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

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

    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
213 214
}

215
QString GenericMakeStepConfigWidget::displayName() const
Roberto Raggi's avatar
Roberto Raggi committed
216 217 218 219
{
    return "Make";
}

220 221 222 223 224 225
// 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)));
}

226
void GenericMakeStepConfigWidget::init(const QString &buildConfiguration)
Roberto Raggi's avatar
Roberto Raggi committed
227 228
{
    m_buildConfiguration = buildConfiguration;
229

230
    updateMakeOverrrideLabel();
231

232
    QString makeCommand = m_makeStep->m_values.value(buildConfiguration).makeCommand;
233 234
    m_ui->makeLineEdit->setText(makeCommand);

235
    const QStringList &makeArguments = m_makeStep->m_values.value(buildConfiguration).makeArguments;
236 237 238 239 240 241 242 243
    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
244 245
        item->setCheckState(m_makeStep->buildsTarget(buildConfiguration, item->text()) ? Qt::Checked : Qt::Unchecked);
    }
246

247
    updateDetails();
Roberto Raggi's avatar
Roberto Raggi committed
248
    // and connect again
249 250 251
    connect(m_ui->targetsList, SIGNAL(itemChanged(QListWidgetItem*)), this, SLOT(itemChanged(QListWidgetItem*)));
}

252 253 254 255 256 257 258 259
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
260 261
QString GenericMakeStepConfigWidget::summaryText() const
{
262
    return m_summaryText;
dt's avatar
dt committed
263 264
}

265 266 267 268
void GenericMakeStepConfigWidget::itemChanged(QListWidgetItem *item)
{
    QTC_ASSERT(!m_buildConfiguration.isNull(), return);
    m_makeStep->setBuildTarget(m_buildConfiguration, item->text(), item->checkState() & Qt::Checked);
269
    updateDetails();
270 271 272 273 274
}

void GenericMakeStepConfigWidget::makeLineEditTextEdited()
{
    QTC_ASSERT(!m_buildConfiguration.isNull(), return);
275
    m_makeStep->m_values[m_buildConfiguration].makeCommand = m_ui->makeLineEdit->text();
276
    updateDetails();
277 278 279 280 281
}

void GenericMakeStepConfigWidget::makeArgumentsLineEditTextEdited()
{
    QTC_ASSERT(!m_buildConfiguration.isNull(), return);
282 283
    m_makeStep->m_values[m_buildConfiguration].makeArguments =
                         ProjectExplorer::Environment::parseCombinedArgString(m_ui->makeArgumentsLineEdit->text());
284
    updateDetails();
Roberto Raggi's avatar
Roberto Raggi committed
285 286 287
}

//
288
// GenericMakeStepFactory
Roberto Raggi's avatar
Roberto Raggi committed
289 290
//

291
bool GenericMakeStepFactory::canCreate(const QString &name) const
Roberto Raggi's avatar
Roberto Raggi committed
292 293 294 295
{
    return (Constants::MAKESTEP == name);
}

296
ProjectExplorer::BuildStep *GenericMakeStepFactory::create(ProjectExplorer::Project *project, const QString &name) const
Roberto Raggi's avatar
Roberto Raggi committed
297 298 299 300
{
    Q_ASSERT(name == Constants::MAKESTEP);
    GenericProject *pro = qobject_cast<GenericProject *>(project);
    Q_ASSERT(pro);
301
    return new GenericMakeStep(pro);
Roberto Raggi's avatar
Roberto Raggi committed
302 303
}

304
QStringList GenericMakeStepFactory::canCreateForProject(ProjectExplorer::Project * /* pro */) const
Roberto Raggi's avatar
Roberto Raggi committed
305 306 307 308
{
    return QStringList();
}

309
QString GenericMakeStepFactory::displayNameForName(const QString & /* name */) const
Roberto Raggi's avatar
Roberto Raggi committed
310 311 312
{
    return "Make";
}