genericmakestep.cpp 9.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(buildConfigurationName, 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(buildConfigurationName, buildDir);
71

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

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

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

94 95 96 97 98 99 100 101 102 103
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
104 105
}

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

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

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

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

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

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

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

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

//
152
// GenericMakeStepConfigWidget
Roberto Raggi's avatar
Roberto Raggi committed
153
//
154 155

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

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

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

    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
180 181
}

182
QString GenericMakeStepConfigWidget::displayName() const
Roberto Raggi's avatar
Roberto Raggi committed
183 184 185 186
{
    return "Make";
}

187 188 189 190 191 192
// 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)));
}

193
void GenericMakeStepConfigWidget::init(const QString &buildConfiguration)
Roberto Raggi's avatar
Roberto Raggi committed
194 195
{
    m_buildConfiguration = buildConfiguration;
196

197
    updateMakeOverrrideLabel();
198

199
    QString makeCommand = m_makeStep->value(buildConfiguration, "makeCommand").toString();
200 201 202 203 204 205 206 207 208 209 210 211
    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
212 213
        item->setCheckState(m_makeStep->buildsTarget(buildConfiguration, item->text()) ? Qt::Checked : Qt::Unchecked);
    }
214

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

220 221 222 223 224 225 226 227
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
228 229
QString GenericMakeStepConfigWidget::summaryText() const
{
230
    return m_summaryText;
dt's avatar
dt committed
231 232
}

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

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

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

//
256
// GenericMakeStepFactory
Roberto Raggi's avatar
Roberto Raggi committed
257 258
//

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

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

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

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