genericmakestep.cpp 9.24 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 145 146 147 148 149 150
{
    QStringList old = value(buildConfiguration, "buildTargets").toStringList();
    if (on && !old.contains(target))
        setValue(buildConfiguration, "buildTargets", old << target);
    else if(!on && old.contains(target))
        setValue(buildConfiguration, "buildTargets", old.removeOne(target));
}

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

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

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

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

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

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

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

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

196
    updateMakeOverrrideLabel();
197

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

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

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

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

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

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

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

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

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

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

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