qmakestep.cpp 15.3 KB
Newer Older
1
/**************************************************************************
con's avatar
con committed
2
3
4
**
** This file is part of Qt Creator
**
hjk's avatar
hjk committed
5
** Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
con's avatar
con committed
6
**
7
** Contact: Nokia Corporation (qt-info@nokia.com)
con's avatar
con committed
8
**
9
** Commercial Usage
10
**
11
12
13
14
** 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.
15
**
16
** GNU Lesser General Public License Usage
17
**
18
19
20
21
22
23
** 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.
24
**
25
** 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.
con's avatar
con committed
27
**
28
**************************************************************************/
hjk's avatar
hjk committed
29

con's avatar
con committed
30
#include "qmakestep.h"
hjk's avatar
hjk committed
31

32
#include "projectexplorer/projectexplorerconstants.h"
Tobias Hunger's avatar
Tobias Hunger committed
33
34
#include "qmakeparser.h"
#include "qt4buildconfiguration.h"
con's avatar
con committed
35
36
37
#include "qt4project.h"
#include "qt4projectmanagerconstants.h"
#include "qt4projectmanager.h"
Tobias Hunger's avatar
Tobias Hunger committed
38
#include "qt4target.h"
39
#include "qtversionmanager.h"
con's avatar
con committed
40

Tobias Hunger's avatar
Tobias Hunger committed
41
42
#include <projectexplorer/buildsteplist.h>

con's avatar
con committed
43
#include <coreplugin/icore.h>
hjk's avatar
hjk committed
44
#include <utils/qtcassert.h>
con's avatar
con committed
45

Tobias Hunger's avatar
Tobias Hunger committed
46
47
#include <QtCore/QDir>
#include <QtCore/QFile>
con's avatar
con committed
48
49
50
51
52

using namespace Qt4ProjectManager;
using namespace Qt4ProjectManager::Internal;
using namespace ProjectExplorer;

53
54
55
56
namespace {
const char * const QMAKE_BS_ID("QtProjectManager.QMakeBuildStep");

const char * const QMAKE_ARGUMENTS_KEY("QtProjectManager.QMakeBuildStep.QMakeArguments");
57
const char * const QMAKE_FORCED_KEY("QtProjectManager.QMakeBuildStep.QMakeForced");
58
59
}

Tobias Hunger's avatar
Tobias Hunger committed
60
61
QMakeStep::QMakeStep(BuildStepList *bsl) :
    AbstractProcessStep(bsl, QLatin1String(QMAKE_BS_ID)),
62
    m_forced(false)
con's avatar
con committed
63
{
64
    ctor();
con's avatar
con committed
65
66
}

Tobias Hunger's avatar
Tobias Hunger committed
67
68
QMakeStep::QMakeStep(BuildStepList *bsl, const QString &id) :
    AbstractProcessStep(bsl, id),
69
70
71
72
73
    m_forced(false)
{
    ctor();
}

Tobias Hunger's avatar
Tobias Hunger committed
74
75
QMakeStep::QMakeStep(BuildStepList *bsl, QMakeStep *bs) :
    AbstractProcessStep(bsl, bs),
76
    m_forced(bs->m_forced),
dt's avatar
dt committed
77
    m_userArgs(bs->m_userArgs)
78
{
79
80
81
82
83
    ctor();
}

void QMakeStep::ctor()
{
84
85
    //: QMakeStep default display name
    setDefaultDisplayName(tr("qmake"));
86
87
}

con's avatar
con committed
88
89
90
91
QMakeStep::~QMakeStep()
{
}

dt's avatar
dt committed
92
93
94
95
96
Qt4BuildConfiguration *QMakeStep::qt4BuildConfiguration() const
{
    return static_cast<Qt4BuildConfiguration *>(buildConfiguration());
}

dt's avatar
dt committed
97
98
99
100
101
102
103
///
/// Returns all arguments
/// That is: possbile subpath
/// spec
/// config arguemnts
/// moreArguments
/// user arguments
dt's avatar
dt committed
104
QStringList QMakeStep::allArguments()
con's avatar
con committed
105
{
dt's avatar
dt committed
106
    QStringList additonalArguments = m_userArgs;
dt's avatar
dt committed
107
    Qt4BuildConfiguration *bc = qt4BuildConfiguration();
con's avatar
con committed
108
    QStringList arguments;
109
    if (bc->subNodeBuild())
110
        arguments << QDir::toNativeSeparators(bc->subNodeBuild()->path());
111
    else
112
        arguments << QDir::toNativeSeparators(buildConfiguration()->target()->project()->file()->fileName());
con's avatar
con committed
113
114
    arguments << "-r";

115
    if (!additonalArguments.contains("-spec"))
116
        arguments << "-spec" << bc->qtVersion()->mkspec();
117

dt's avatar
dt committed
118
    // Find out what flags we pass on to qmake
119
    arguments << bc->configCommandLineArguments();
dt's avatar
dt committed
120
121
122
123

    if (!additonalArguments.isEmpty())
        arguments << additonalArguments;

124
125
    arguments << moreArguments();

dt's avatar
dt committed
126
127
128
    return arguments;
}

dt's avatar
dt committed
129
130
131
132
///
/// moreArguments,
/// -unix for Maemo
/// -after OBJECTS_DIR, MOC_DIR, UI_DIR, RCC_DIR
133
/// QMAKE_VAR_QMLJSDEBUGGER_PATH
dt's avatar
dt committed
134
135
136
137
QStringList QMakeStep::moreArguments()
{
    Qt4BuildConfiguration *bc = qt4BuildConfiguration();
    QStringList arguments;
138
#if defined(Q_OS_WIN) || defined(Q_OS_MAC)
dt's avatar
dt committed
139
    ToolChain::ToolChainType type = bc->toolChainType();
ck's avatar
ck committed
140
141
142
    if (type == ToolChain::GCC_MAEMO)
        arguments << QLatin1String("-unix");
#endif
143
144
145
146
147
148
149
150
    if (bc->target()->id() == Constants::S60_DEVICE_TARGET_ID
        || bc->target()->id() == Constants::S60_EMULATOR_TARGET_ID) {
        // We have a target which does not allow shadow building.
        // But we really don't want to have the build artefacts in the source dir
        // so we try to hack around it, to make the common cases work.
        // This is a HACK, remove once the symbian make generator supports
        // shadow building
        arguments << QLatin1String("-after")
151
152
153
154
                  << QLatin1String("OBJECTS_DIR=obj")
                  << QLatin1String("MOC_DIR=moc")
                  << QLatin1String("UI_DIR=ui")
                  << QLatin1String("RCC_DIR=rcc");
155
    }
ck's avatar
ck committed
156

157
    // Do not turn debugger path into native path separators: Qmake does not like that!
158
    arguments << QLatin1String(Constants::QMAKEVAR_QMLJSDEBUGGER_PATH) + QLatin1Char('=') +
159
            Core::ICore::instance()->resourcePath() + QLatin1String("/qml/qmljsdebugger");
con's avatar
con committed
160
161
162
    return arguments;
}

163
bool QMakeStep::init()
con's avatar
con committed
164
{
dt's avatar
dt committed
165
    Qt4BuildConfiguration *qt4bc = qt4BuildConfiguration();
166
    const QtVersion *qtVersion = qt4bc->qtVersion();
con's avatar
con committed
167

dt's avatar
dt committed
168
    QStringList args = allArguments();
169
170
171
172
173
    QString workingDirectory;
    if (qt4bc->subNodeBuild())
        workingDirectory = qt4bc->subNodeBuild()->buildDir();
    else
        workingDirectory = qt4bc->buildDirectory();
con's avatar
con committed
174
175
176

    QString program = qtVersion->qmakeCommand();

Tobias Hunger's avatar
Tobias Hunger committed
177
    // Check whether we need to run qmake
178
    m_needToRunQMake = true;
dt's avatar
dt committed
179
    if (QDir(workingDirectory).exists(QLatin1String("Makefile"))) {
180
181
        QString qmakePath = QtVersionManager::findQMakeBinaryFromMakefile(workingDirectory);
        if (qtVersion->qmakeCommand() == qmakePath) {
dt's avatar
dt committed
182
            m_needToRunQMake = !qt4bc->compareToImportFrom(workingDirectory);
dt's avatar
dt committed
183
        }
con's avatar
con committed
184
185
186
187
    }

    if (m_forced) {
        m_forced = false;
188
        m_needToRunQMake = true;
con's avatar
con committed
189
190
    }

191
192
193
194
    setEnabled(m_needToRunQMake);
    setWorkingDirectory(workingDirectory);
    setCommand(program);
    setArguments(args);
195
    setEnvironment(qt4bc->environment());
196

Tobias Hunger's avatar
Tobias Hunger committed
197
    setOutputParser(new QMakeParser);
dt's avatar
dt committed
198

dt's avatar
dt committed
199
200
201
202
203
    Qt4ProFileNode *node = qt4bc->qt4Target()->qt4Project()->rootProjectNode();
    if (qt4bc->subNodeBuild())
        node = qt4bc->subNodeBuild();
    QString proFile = node->path();

204
    m_tasks = qt4BuildConfiguration()->qtVersion()->reportIssues(proFile, workingDirectory);
dt's avatar
dt committed
205
    m_scriptTemplate = node->projectType() == ScriptTemplate;
dt's avatar
dt committed
206

Tobias Hunger's avatar
Tobias Hunger committed
207
    return AbstractProcessStep::init();
con's avatar
con committed
208
209
210
211
}

void QMakeStep::run(QFutureInterface<bool> &fi)
{
dt's avatar
dt committed
212
    if (m_scriptTemplate) {
con's avatar
con committed
213
214
215
        fi.reportResult(true);
        return;
    }
216

217
    // Warn on common error conditions:
dt's avatar
dt committed
218

219
    bool canContinue = true;
dt's avatar
dt committed
220
    foreach (const ProjectExplorer::Task &t, m_tasks) {
221
222
223
224
225
        addTask(t);
        if (t.type == Task::Error)
            canContinue = false;
    }
    if (!canContinue) {
226
        emit addOutput(tr("Configuration is faulty, please check the Build Issues view for details."), BuildStep::MessageOutput);
227
228
        fi.reportResult(false);
        return;
229
230
    }

231
    if (!m_needToRunQMake) {
232
        emit addOutput(tr("Configuration unchanged, skipping qmake step."), BuildStep::MessageOutput);
con's avatar
con committed
233
234
235
        fi.reportResult(true);
        return;
    }
236

Tobias Hunger's avatar
Tobias Hunger committed
237
    AbstractProcessStep::run(fi);
con's avatar
con committed
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
}

void QMakeStep::setForced(bool b)
{
    m_forced = b;
}

bool QMakeStep::forced()
{
    return m_forced;
}

ProjectExplorer::BuildStepConfigWidget *QMakeStep::createConfigWidget()
{
    return new QMakeStepConfigWidget(this);
}

bool QMakeStep::immutable() const
{
dt's avatar
dt committed
257
    return false;
con's avatar
con committed
258
259
260
261
262
263
264
265
}

void QMakeStep::processStartupFailed()
{
    m_forced = true;
    AbstractProcessStep::processStartupFailed();
}

266
bool QMakeStep::processSucceeded(int exitCode, QProcess::ExitStatus status)
con's avatar
con committed
267
{
268
    bool result = AbstractProcessStep::processSucceeded(exitCode, status);
con's avatar
con committed
269
270
    if (!result)
        m_forced = true;
271
    qt4BuildConfiguration()->emitBuildDirectoryInitialized();
con's avatar
con committed
272
273
274
    return result;
}

275
void QMakeStep::setUserArguments(const QStringList &arguments)
276
{
277
278
    if (m_userArgs == arguments)
        return;
dt's avatar
dt committed
279
    m_userArgs = arguments;
280

281
    emit userArgumentsChanged();
282
283

    qt4BuildConfiguration()->emitQMakeBuildConfigurationChanged();
284
285
286
287
288
289
290
291
292
293
294
    qt4BuildConfiguration()->emitProFileEvaluteNeeded();
}

QStringList QMakeStep::parserArguments()
{
    QStringList result;
    foreach (const QString &str, allArguments()) {
        if (str.contains("="))
            result << str;
    }
    return result;
295
296
}

dt's avatar
dt committed
297
QStringList QMakeStep::userArguments()
298
{
dt's avatar
dt committed
299
    return m_userArgs;
300
301
}

302
QVariantMap QMakeStep::toMap() const
303
{
304
305
    QVariantMap map(AbstractProcessStep::toMap());
    map.insert(QLatin1String(QMAKE_ARGUMENTS_KEY), m_userArgs);
306
    map.insert(QLatin1String(QMAKE_FORCED_KEY), m_forced);
307
    return map;
308
309
}

310
bool QMakeStep::fromMap(const QVariantMap &map)
311
{
312
    m_userArgs = map.value(QLatin1String(QMAKE_ARGUMENTS_KEY)).toStringList();
313
    m_forced = map.value(QLatin1String(QMAKE_FORCED_KEY), false).toBool();
314
    return BuildStep::fromMap(map);
315
316
}

317
318
319
320
////
// QMakeStepConfigWidget
////

con's avatar
con committed
321
QMakeStepConfigWidget::QMakeStepConfigWidget(QMakeStep *step)
322
    : BuildStepConfigWidget(), m_step(step), m_ignoreChange(false)
con's avatar
con committed
323
324
325
{
    m_ui.setupUi(this);
    connect(m_ui.qmakeAdditonalArgumentsLineEdit, SIGNAL(textEdited(const QString&)),
326
327
328
            this, SLOT(qmakeArgumentsLineEdited()));
    connect(m_ui.buildConfigurationComboBox, SIGNAL(currentIndexChanged(int)),
            this, SLOT(buildConfigurationSelected()));
329
330
    connect(step, SIGNAL(userArgumentsChanged()),
            this, SLOT(userArgumentsChanged()));
331
    connect(step->qt4BuildConfiguration(), SIGNAL(qtVersionChanged()),
332
            this, SLOT(qtVersionChanged()));
333
334
335
336
337
338
    connect(step->qt4BuildConfiguration(), SIGNAL(qmakeBuildConfigurationChanged()),
            this, SLOT(qmakeBuildConfigChanged()));
}

void QMakeStepConfigWidget::init()
{
339
    QString qmakeArgs = Utils::Environment::joinArgumentList(m_step->userArguments());
340
341
342
343
344
345
    m_ui.qmakeAdditonalArgumentsLineEdit->setText(qmakeArgs);

    qmakeBuildConfigChanged();

    updateSummaryLabel();
    updateEffectiveQMakeCall();
con's avatar
con committed
346
347
}

dt's avatar
dt committed
348
349
350
351
352
QString QMakeStepConfigWidget::summaryText() const
{
    return m_summaryText;
}

353
354
355
356
357
QString QMakeStepConfigWidget::displayName() const
{
    return m_step->displayName();
}

358
void QMakeStepConfigWidget::qtVersionChanged()
359
{
360
    updateSummaryLabel();
dt's avatar
dt committed
361
    updateEffectiveQMakeCall();
362
363
}

364
void QMakeStepConfigWidget::qmakeBuildConfigChanged()
dt's avatar
dt committed
365
{
366
367
    Qt4BuildConfiguration *bc = m_step->qt4BuildConfiguration();
    bool debug = bc->qmakeBuildConfiguration() & QtVersion::DebugBuild;
Tobias Hunger's avatar
Tobias Hunger committed
368
369
370
    int index = debug ? 0 : 1;
    if (bc->qmakeBuildConfiguration() & QtVersion::BuildAll)
        index = 2;
371
    m_ignoreChange = true;
Tobias Hunger's avatar
Tobias Hunger committed
372
373
    m_ui.buildConfigurationComboBox->setCurrentIndex(index);

374
375
376
377
    m_ignoreChange = false;
    updateSummaryLabel();
    updateEffectiveQMakeCall();
}
dt's avatar
dt committed
378

379
380
381
382
void QMakeStepConfigWidget::userArgumentsChanged()
{
    if (m_ignoreChange)
        return;
383
    QString qmakeArgs = Utils::Environment::joinArgumentList(m_step->userArguments());
384
385
386
    m_ui.qmakeAdditonalArgumentsLineEdit->setText(qmakeArgs);
    updateSummaryLabel();
    updateEffectiveQMakeCall();
dt's avatar
dt committed
387
388
}

389
void QMakeStepConfigWidget::qmakeArgumentsLineEdited()
con's avatar
con committed
390
{
391
392
    m_ignoreChange = true;
    m_step->setUserArguments(
393
            Utils::Environment::parseCombinedArgString(m_ui.qmakeAdditonalArgumentsLineEdit->text()));
394
    m_ignoreChange = false;
395

396
    updateSummaryLabel();
397
    updateEffectiveQMakeCall();
con's avatar
con committed
398
399
}

400
void QMakeStepConfigWidget::buildConfigurationSelected()
con's avatar
con committed
401
{
402
403
404
405
    if (m_ignoreChange)
        return;
    Qt4BuildConfiguration *bc = m_step->qt4BuildConfiguration();
    QtVersion::QmakeBuildConfigs buildConfiguration = bc->qmakeBuildConfiguration();
Tobias Hunger's avatar
Tobias Hunger committed
406
407
408
409
410
411
412
413
414
415
    switch (m_ui.buildConfigurationComboBox->currentIndex()) {
    case 0:
        buildConfiguration = QtVersion::DebugBuild;
        break;
    case 1:
        buildConfiguration = 0;
        break;
    case 2:
        buildConfiguration = QtVersion::BuildAll;
        break;
con's avatar
con committed
416
    }
Tobias Hunger's avatar
Tobias Hunger committed
417

418
419
420
    m_ignoreChange = true;
    bc->setQMakeBuildConfiguration(buildConfiguration);
    m_ignoreChange = false;
con's avatar
con committed
421

422
423
    updateSummaryLabel();
    updateEffectiveQMakeCall();
con's avatar
con committed
424
425
}

426
void QMakeStepConfigWidget::updateSummaryLabel()
427
{
428
429
430
    Qt4BuildConfiguration *qt4bc = m_step->qt4BuildConfiguration();
    const QtVersion *qtVersion = qt4bc->qtVersion();
    if (!qtVersion) {
Friedemann Kleint's avatar
Friedemann Kleint committed
431
        m_summaryText = tr("<b>qmake:</b> No Qt version set. Cannot run qmake.");
432
        emit updateSummary();
433
        return;
434
435
436
437
    }

    QStringList args = m_step->allArguments();
    // We don't want the full path to the .pro file
Tobias Hunger's avatar
Tobias Hunger committed
438
    const QString projectFileName = m_step->buildConfiguration()->target()->project()->file()->fileName();
439
440
441
442
443
444
    int index = args.indexOf(projectFileName);
    if (index != -1)
        args[index] = QFileInfo(projectFileName).fileName();

    // And we only use the .pro filename not the full path
    QString program = QFileInfo(qtVersion->qmakeCommand()).fileName();
445
    m_summaryText = tr("<b>qmake:</b> %1 %2").arg(program, args.join(QString(QLatin1Char(' '))));
446
    emit updateSummary();
447

448
449
450
451
}

void QMakeStepConfigWidget::updateEffectiveQMakeCall()
{
dt's avatar
dt committed
452
    Qt4BuildConfiguration *qt4bc = m_step->qt4BuildConfiguration();
453
    const QtVersion *qtVersion = qt4bc->qtVersion();
Tobias Hunger's avatar
Tobias Hunger committed
454
    QString program = QFileInfo(qtVersion->qmakeCommand()).fileName();
455
    m_ui.qmakeArgumentsEdit->setPlainText(program + QLatin1Char(' ') + Utils::Environment::joinArgumentList(m_step->allArguments()));
con's avatar
con committed
456
457
}

dt's avatar
dt committed
458
459
460
461
////
// QMakeStepFactory
////

462
463
QMakeStepFactory::QMakeStepFactory(QObject *parent) :
    ProjectExplorer::IBuildStepFactory(parent)
dt's avatar
dt committed
464
465
466
467
468
469
470
{
}

QMakeStepFactory::~QMakeStepFactory()
{
}

Tobias Hunger's avatar
Tobias Hunger committed
471
bool QMakeStepFactory::canCreate(BuildStepList *parent, const QString &id) const
dt's avatar
dt committed
472
{
Tobias Hunger's avatar
Tobias Hunger committed
473
    if (parent->id() != QLatin1String(ProjectExplorer::Constants::BUILDSTEPS_BUILD))
474
        return false;
Tobias Hunger's avatar
Tobias Hunger committed
475
    if (!qobject_cast<Qt4BuildConfiguration *>(parent->parent()))
476
477
        return false;
    return (id == QLatin1String(QMAKE_BS_ID));
dt's avatar
dt committed
478
479
}

Tobias Hunger's avatar
Tobias Hunger committed
480
ProjectExplorer::BuildStep *QMakeStepFactory::create(BuildStepList *parent, const QString &id)
dt's avatar
dt committed
481
{
Tobias Hunger's avatar
Tobias Hunger committed
482
    if (!canCreate(parent, id))
483
        return 0;
Tobias Hunger's avatar
Tobias Hunger committed
484
    return new QMakeStep(parent);
485
486
}

Tobias Hunger's avatar
Tobias Hunger committed
487
bool QMakeStepFactory::canClone(BuildStepList *parent, BuildStep *source) const
488
{
Tobias Hunger's avatar
Tobias Hunger committed
489
    return canCreate(parent, source->id());
dt's avatar
dt committed
490
491
}

Tobias Hunger's avatar
Tobias Hunger committed
492
ProjectExplorer::BuildStep *QMakeStepFactory::clone(BuildStepList *parent, ProjectExplorer::BuildStep *source)
dt's avatar
dt committed
493
{
Tobias Hunger's avatar
Tobias Hunger committed
494
    if (!canClone(parent, source))
495
        return 0;
Tobias Hunger's avatar
Tobias Hunger committed
496
    return new QMakeStep(parent, qobject_cast<QMakeStep *>(source));
dt's avatar
dt committed
497
498
}

Tobias Hunger's avatar
Tobias Hunger committed
499
bool QMakeStepFactory::canRestore(BuildStepList *parent, const QVariantMap &map) const
500
501
{
    QString id(ProjectExplorer::idFromMap(map));
Tobias Hunger's avatar
Tobias Hunger committed
502
    return canCreate(parent, id);
503
504
}

Tobias Hunger's avatar
Tobias Hunger committed
505
ProjectExplorer::BuildStep *QMakeStepFactory::restore(BuildStepList *parent, const QVariantMap &map)
dt's avatar
dt committed
506
{
Tobias Hunger's avatar
Tobias Hunger committed
507
    if (!canRestore(parent, map))
508
        return 0;
Tobias Hunger's avatar
Tobias Hunger committed
509
    QMakeStep *bs = new QMakeStep(parent);
510
511
512
513
    if (bs->fromMap(map))
        return bs;
    delete bs;
    return 0;
dt's avatar
dt committed
514
515
}

Tobias Hunger's avatar
Tobias Hunger committed
516
QStringList QMakeStepFactory::availableCreationIds(ProjectExplorer::BuildStepList *parent) const
517
{
Tobias Hunger's avatar
Tobias Hunger committed
518
519
    if (parent->id() == QLatin1String(ProjectExplorer::Constants::BUILDSTEPS_BUILD))
        if (Qt4BuildConfiguration *bc = qobject_cast<Qt4BuildConfiguration *>(parent->parent()))
520
521
            if (!bc->qmakeStep())
                return QStringList() << QLatin1String(QMAKE_BS_ID);
522
523
    return QStringList();
}
dt's avatar
dt committed
524

525
526
527
QString QMakeStepFactory::displayNameForId(const QString &id) const
{
    if (id == QLatin1String(QMAKE_BS_ID))
528
        return tr("qmake");
529
530
    return QString();
}