qmakestep.cpp 26.9 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) 2012 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
**
10
** GNU Lesser General Public License Usage
11
**
hjk's avatar
hjk committed
12
13
14
15
16
17
** 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.
18
**
con's avatar
con committed
19
** In addition, as a special exception, Nokia gives you certain additional
hjk's avatar
hjk committed
20
** rights. These rights are described in the Nokia Qt LGPL Exception
con's avatar
con committed
21
22
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
hjk's avatar
hjk committed
23
24
25
26
27
** Other Usage
**
** Alternatively, this file may be used in accordance with the terms and
** conditions contained in a signed written agreement between you and Nokia.
**
con's avatar
con committed
28
** If you have questions regarding the use of this file, please contact
29
** Nokia at qt-info@nokia.com.
con's avatar
con committed
30
**
31
**************************************************************************/
hjk's avatar
hjk committed
32

con's avatar
con committed
33
#include "qmakestep.h"
34
#include "ui_qmakestep.h"
hjk's avatar
hjk committed
35

36
#include <projectexplorer/projectexplorerconstants.h>
Tobias Hunger's avatar
Tobias Hunger committed
37
38
#include "qmakeparser.h"
#include "qt4buildconfiguration.h"
con's avatar
con committed
39
40
41
#include "qt4project.h"
#include "qt4projectmanagerconstants.h"
#include "qt4projectmanager.h"
Tobias Hunger's avatar
Tobias Hunger committed
42
#include "qt4target.h"
43
#include "qt4nodes.h"
44
#include "qt4basetargetfactory.h"
con's avatar
con committed
45

46
#include <projectexplorer/buildmanager.h>
Tobias Hunger's avatar
Tobias Hunger committed
47
#include <projectexplorer/buildsteplist.h>
48
#include <projectexplorer/projectexplorer.h>
49
#include <projectexplorer/toolchain.h>
Tobias Hunger's avatar
Tobias Hunger committed
50

con's avatar
con committed
51
#include <coreplugin/icore.h>
52
#include <coreplugin/mainwindow.h>
53
#include <coreplugin/progressmanager/progressmanager.h>
54
#include <coreplugin/messagemanager.h>
55
56
#include <qtsupport/qtversionmanager.h>
#include <qtsupport/debugginghelperbuildtask.h>
hjk's avatar
hjk committed
57
#include <utils/qtcassert.h>
58
#include <utils/qtcprocess.h>
con's avatar
con committed
59

Tobias Hunger's avatar
Tobias Hunger committed
60
61
#include <QtCore/QDir>
#include <QtCore/QFile>
62
#include <utils/runextensions.h>
63
#include <QtCore/QtConcurrentRun>
64
#include <QtGui/QMessageBox>
con's avatar
con committed
65
66
67
68
69

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

70
71
72
73
namespace {
const char * const QMAKE_BS_ID("QtProjectManager.QMakeBuildStep");

const char * const QMAKE_ARGUMENTS_KEY("QtProjectManager.QMakeBuildStep.QMakeArguments");
74
const char * const QMAKE_FORCED_KEY("QtProjectManager.QMakeBuildStep.QMakeForced");
75
const char * const QMAKE_QMLDEBUGLIBAUTO_KEY("QtProjectManager.QMakeBuildStep.LinkQmlDebuggingLibraryAuto");
76
const char * const QMAKE_QMLDEBUGLIB_KEY("QtProjectManager.QMakeBuildStep.LinkQmlDebuggingLibrary");
77
78
}

Tobias Hunger's avatar
Tobias Hunger committed
79
80
QMakeStep::QMakeStep(BuildStepList *bsl) :
    AbstractProcessStep(bsl, QLatin1String(QMAKE_BS_ID)),
81
    m_forced(false),
82
    m_needToRunQMake(false),
83
    m_linkQmlDebuggingLibrary(DebugLink)
con's avatar
con committed
84
{
85
    ctor();
con's avatar
con committed
86
87
}

Tobias Hunger's avatar
Tobias Hunger committed
88
89
QMakeStep::QMakeStep(BuildStepList *bsl, const QString &id) :
    AbstractProcessStep(bsl, id),
90
    m_forced(false),
91
    m_linkQmlDebuggingLibrary(DebugLink)
92
93
94
95
{
    ctor();
}

Tobias Hunger's avatar
Tobias Hunger committed
96
97
QMakeStep::QMakeStep(BuildStepList *bsl, QMakeStep *bs) :
    AbstractProcessStep(bsl, bs),
98
    m_forced(bs->m_forced),
99
100
    m_userArgs(bs->m_userArgs),
    m_linkQmlDebuggingLibrary(bs->m_linkQmlDebuggingLibrary)
101
{
102
103
104
105
106
    ctor();
}

void QMakeStep::ctor()
{
107
108
    //: QMakeStep default display name
    setDefaultDisplayName(tr("qmake"));
109
110
}

con's avatar
con committed
111
112
113
114
QMakeStep::~QMakeStep()
{
}

dt's avatar
dt committed
115
116
117
118
119
Qt4BuildConfiguration *QMakeStep::qt4BuildConfiguration() const
{
    return static_cast<Qt4BuildConfiguration *>(buildConfiguration());
}

dt's avatar
dt committed
120
121
122
123
124
125
126
///
/// Returns all arguments
/// That is: possbile subpath
/// spec
/// config arguemnts
/// moreArguments
/// user arguments
127
QString QMakeStep::allArguments(bool shorted)
con's avatar
con committed
128
{
dt's avatar
dt committed
129
    Qt4BuildConfiguration *bc = qt4BuildConfiguration();
con's avatar
con committed
130
    QStringList arguments;
131
    if (bc->subNodeBuild())
132
        arguments << QDir::toNativeSeparators(bc->subNodeBuild()->path());
133
    else if (shorted)
134
        arguments << QDir::toNativeSeparators(QFileInfo(project()->file()->fileName()).fileName());
135
    else
136
        arguments << QDir::toNativeSeparators(project()->file()->fileName());
con's avatar
con committed
137

138
    arguments << QLatin1String("-r");
139
    bool userProvidedMkspec = false;
Tobias Hunger's avatar
Tobias Hunger committed
140
    for (Utils::QtcProcess::ConstArgIterator ait(m_userArgs); ait.next(); ) {
141
142
143
144
145
        if (ait.value() == QLatin1String("-spec")) {
            if (ait.next()) {
                userProvidedMkspec = true;
                break;
            }
dt's avatar
dt committed
146
        }
147
    }
148
    Utils::FileName specArg = mkspec();
149
    if (!userProvidedMkspec && !specArg.isEmpty())
150
        arguments << QLatin1String("-spec") << specArg.toUserOutput();
151

dt's avatar
dt committed
152
    // Find out what flags we pass on to qmake
153
    arguments << bc->configCommandLineArguments();
dt's avatar
dt committed
154

155
156
    arguments << moreArguments();

157
    QString args = Utils::QtcProcess::joinArgs(arguments);
158
    // User arguments
159
    Utils::QtcProcess::addArgs(&args, m_userArgs);
160
161
162
    // moreArgumentsAfter
    foreach (const QString &arg, moreArgumentsAfter())
        Utils::QtcProcess::addArg(&args, arg);
163
    return args;
dt's avatar
dt committed
164
165
}

dt's avatar
dt committed
166
167
168
///
/// moreArguments,
/// -unix for Maemo
169
/// QMAKE_VAR_QMLJSDEBUGGER_PATH
dt's avatar
dt committed
170
171
172
173
QStringList QMakeStep::moreArguments()
{
    Qt4BuildConfiguration *bc = qt4BuildConfiguration();
    QStringList arguments;
174
    ProjectExplorer::ToolChain *tc = bc->toolChain();
175
176
177
178
179
180
    ProjectExplorer::Abi targetAbi;
    if (tc)
        targetAbi = tc->targetAbi();
#if defined(Q_OS_WIN) || defined(Q_OS_MAC)
    if ((targetAbi.osFlavor() == ProjectExplorer::Abi::HarmattanLinuxFlavor
               || targetAbi.osFlavor() == ProjectExplorer::Abi::MaemoLinuxFlavor))
ck's avatar
ck committed
181
182
        arguments << QLatin1String("-unix");
#endif
183

184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
    // explicitly add architecture to CONFIG
    if ((targetAbi.os() == ProjectExplorer::Abi::MacOS)
            && (targetAbi.binaryFormat() == ProjectExplorer::Abi::MachOFormat)) {
        if (targetAbi.architecture() == ProjectExplorer::Abi::X86Architecture) {
            if (targetAbi.wordWidth() == 32)
                arguments << QLatin1String("CONFIG+=x86");
            else if (targetAbi.wordWidth() == 64)
                arguments << QLatin1String("CONFIG+=x86_64");
        } else if (targetAbi.architecture() == ProjectExplorer::Abi::PowerPCArchitecture) {
            if (targetAbi.wordWidth() == 32)
                arguments << QLatin1String("CONFIG+=ppc");
            else if (targetAbi.wordWidth() == 64)
                arguments << QLatin1String("CONFIG+=ppc64");
        }
    }

200
    if (linkQmlDebuggingLibrary() && bc->qtVersion()) {
201
202
203
        if (!bc->qtVersion()->needsQmlDebuggingLibrary()) {
            // This Qt version has the QML debugging services built in, however
            // they still need to be enabled at compile time
204
            arguments << QLatin1String(Constants::QMAKEVAR_DECLARATIVE_DEBUG);
205
206
207
208
209
210
211
212
213
214
215
        } else {
            QString qmlDebuggingHelperLibrary = bc->qtVersion()->qmlDebuggingHelperLibrary(true);
            if (!qmlDebuggingHelperLibrary.isEmpty()) {
                // Do not turn debugger path into native path separators: Qmake does not like that!
                const QString debuggingHelperPath
                        = QFileInfo(qmlDebuggingHelperLibrary).dir().path();

                arguments << QLatin1String(Constants::QMAKEVAR_QMLJSDEBUGGER_PATH)
                             + QLatin1Char('=') + debuggingHelperPath;
            }
        }
216
217
    }

218
219
220
221

    return arguments;
}

222
/// -after OBJECTS_DIR, MOC_DIR, UI_DIR, RCC_DIR
223
224
225
QStringList QMakeStep::moreArgumentsAfter()
{
    Qt4BuildConfiguration *bc = qt4BuildConfiguration();
dt's avatar
dt committed
226
    if (bc->qtVersion() && !bc->qtVersion()->supportsShadowBuilds()) {
227
228
229
230
231
        // 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
232
233
234
235
236
        return QStringList() << QLatin1String("-after")
                             << QLatin1String("OBJECTS_DIR=obj")
                             << QLatin1String("MOC_DIR=moc")
                             << QLatin1String("UI_DIR=ui")
                             << QLatin1String("RCC_DIR=rcc");
237
    }
238
    return QStringList();
con's avatar
con committed
239
240
}

241
bool QMakeStep::init()
con's avatar
con committed
242
{
dt's avatar
dt committed
243
    Qt4BuildConfiguration *qt4bc = qt4BuildConfiguration();
244
    const QtSupport::BaseQtVersion *qtVersion = qt4bc->qtVersion();
dt's avatar
dt committed
245
246
247

    if (!qtVersion)
        return false;
con's avatar
con committed
248

249
    QString args = allArguments();
250
    QString workingDirectory;
251

252
253
254
255
    if (qt4bc->subNodeBuild())
        workingDirectory = qt4bc->subNodeBuild()->buildDir();
    else
        workingDirectory = qt4bc->buildDirectory();
con's avatar
con committed
256

257
    Utils::FileName program = qtVersion->qmakeCommand();
con's avatar
con committed
258

259
260
261
262
263
264
    QString makefile = workingDirectory;

    if (qt4bc->subNodeBuild()) {
        if (!qt4bc->subNodeBuild()->makefile().isEmpty()) {
            makefile.append(qt4bc->subNodeBuild()->makefile());
        } else {
265
            makefile.append(QLatin1String("/Makefile"));
266
267
        }
    } else if (!qt4bc->makefile().isEmpty()) {
268
        makefile.append(QLatin1Char('/'));
269
270
        makefile.append(qt4bc->makefile());
    } else {
271
        makefile.append(QLatin1String("/Makefile"));
272
273
    }

274
275
    // Check whether we need to run qmake
    bool makefileOutDated = true;
276
    if (QFileInfo(makefile).exists()) {
277
        Utils::FileName qmakePath = QtSupport::QtVersionManager::findQMakeBinaryFromMakefile(makefile);
278
        if (qtVersion->qmakeCommand() == qmakePath) {
279
            makefileOutDated = !qt4bc->compareToImportFrom(makefile);
dt's avatar
dt committed
280
        }
con's avatar
con committed
281
282
    }

283
    if (m_forced || makefileOutDated)
284
        m_needToRunQMake = true;
285
    m_forced = false;
con's avatar
con committed
286

287
288
289
    ProcessParameters *pp = processParameters();
    pp->setMacroExpander(qt4bc->macroExpander());
    pp->setWorkingDirectory(workingDirectory);
290
    pp->setCommand(program.toString());
291
292
    pp->setArguments(args);
    pp->setEnvironment(qt4bc->environment());
293

Tobias Hunger's avatar
Tobias Hunger committed
294
    setOutputParser(new QMakeParser);
dt's avatar
dt committed
295

296
    Qt4ProFileNode *node = qt4bc->qt4Target()->qt4Project()->rootQt4ProjectNode();
dt's avatar
dt committed
297
298
299
300
    if (qt4bc->subNodeBuild())
        node = qt4bc->subNodeBuild();
    QString proFile = node->path();

301
302
303
304
305
306
307
    QtSupport::BaseQtVersion *version = qt4BuildConfiguration()->qtVersion();
    m_tasks = version->reportIssues(proFile, workingDirectory);

    foreach (Qt4BaseTargetFactory *factory, Qt4BaseTargetFactory::qt4BaseTargetFactoriesForIds(version->supportedTargetIds().toList()))
        m_tasks.append(factory->reportIssues(proFile));
    qSort(m_tasks);

dt's avatar
dt committed
308
    m_scriptTemplate = node->projectType() == ScriptTemplate;
dt's avatar
dt committed
309

Tobias Hunger's avatar
Tobias Hunger committed
310
    return AbstractProcessStep::init();
con's avatar
con committed
311
312
313
314
}

void QMakeStep::run(QFutureInterface<bool> &fi)
{
dt's avatar
dt committed
315
    if (m_scriptTemplate) {
con's avatar
con committed
316
317
318
        fi.reportResult(true);
        return;
    }
319

320
    // Warn on common error conditions:
321
    bool canContinue = true;
dt's avatar
dt committed
322
    foreach (const ProjectExplorer::Task &t, m_tasks) {
323
324
325
326
327
        addTask(t);
        if (t.type == Task::Error)
            canContinue = false;
    }
    if (!canContinue) {
328
        emit addOutput(tr("Configuration is faulty, please check the Issues view for details."), BuildStep::MessageOutput);
329
330
        fi.reportResult(false);
        return;
331
332
    }

333
    if (!m_needToRunQMake) {
334
        emit addOutput(tr("Configuration unchanged, skipping qmake step."), BuildStep::MessageOutput);
con's avatar
con committed
335
336
337
        fi.reportResult(true);
        return;
    }
338

339
    m_needToRunQMake = false;
Tobias Hunger's avatar
Tobias Hunger committed
340
    AbstractProcessStep::run(fi);
con's avatar
con committed
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
}

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
360
    return false;
con's avatar
con committed
361
362
363
364
}

void QMakeStep::processStartupFailed()
{
365
    m_needToRunQMake = true;
con's avatar
con committed
366
367
368
    AbstractProcessStep::processStartupFailed();
}

369
bool QMakeStep::processSucceeded(int exitCode, QProcess::ExitStatus status)
con's avatar
con committed
370
{
371
    bool result = AbstractProcessStep::processSucceeded(exitCode, status);
con's avatar
con committed
372
    if (!result)
373
        m_needToRunQMake = true;
374
    qt4BuildConfiguration()->emitBuildDirectoryInitialized();
con's avatar
con committed
375
376
377
    return result;
}

378
void QMakeStep::setUserArguments(const QString &arguments)
379
{
380
381
    if (m_userArgs == arguments)
        return;
dt's avatar
dt committed
382
    m_userArgs = arguments;
383

384
    emit userArgumentsChanged();
385
386

    qt4BuildConfiguration()->emitQMakeBuildConfigurationChanged();
387
    qt4BuildConfiguration()->emitProFileEvaluateNeeded();
388
389
}

390
391
bool QMakeStep::isQmlDebuggingLibrarySupported(QString *reason) const
{
392
    QtSupport::BaseQtVersion *version = qt4BuildConfiguration()->qtVersion();
dt's avatar
dt committed
393
394
395
396
397
    if (!version) {
        if (reason)
            *reason = tr("No Qt version.");
        return false;
    }
398
399

    if (!version->needsQmlDebuggingLibrary() || version->hasQmlDebuggingLibrary())
400
401
        return true;

dt's avatar
dt committed
402
    if (!version->qtAbis().isEmpty()) {
403
        ProjectExplorer::Abi abi = qt4BuildConfiguration()->qtVersion()->qtAbis().first();
404
        if (abi.osFlavor() == ProjectExplorer::Abi::MaemoLinuxFlavor) {
405
            if (reason)
Friedemann Kleint's avatar
Friedemann Kleint committed
406
                reason->clear();
407
408
409
410
411
//               *reason = tr("Qml debugging on device not yet supported.");
            return false;
        }
    }

dt's avatar
dt committed
412
    if (!version->isValid()) {
413
414
415
416
417
        if (reason)
            *reason = tr("Invalid Qt version.");
        return false;
    }

418
    if (version->qtVersion() < QtSupport::QtVersionNumber(4, 7, 1)) {
419
420
421
422
423
424
        if (reason)
            *reason = tr("Requires Qt 4.7.1 or newer.");
        return false;
    }

    if (reason)
425
        *reason = tr("Library not available. <a href='compile'>Compile...</a>");
426
427
428
429
430
431

    return false;
}

bool QMakeStep::linkQmlDebuggingLibrary() const
{
432
433
434
435
436
    if (m_linkQmlDebuggingLibrary == DoLink)
        return true;
    if (m_linkQmlDebuggingLibrary == DoNotLink)
        return false;
    return (qt4BuildConfiguration()->buildType() & BuildConfiguration::Debug);
437
438
439
440
}

void QMakeStep::setLinkQmlDebuggingLibrary(bool enable)
{
441
442
    if ((enable && (m_linkQmlDebuggingLibrary == DoLink))
            || (!enable && (m_linkQmlDebuggingLibrary == DoNotLink)))
443
        return;
444
    m_linkQmlDebuggingLibrary = enable ? DoLink : DoNotLink;
445
446
447
448

    emit linkQmlDebuggingLibraryChanged();

    qt4BuildConfiguration()->emitQMakeBuildConfigurationChanged();
449
    qt4BuildConfiguration()->emitProFileEvaluateNeeded();
450
451
}

452
453
454
QStringList QMakeStep::parserArguments()
{
    QStringList result;
455
456
457
    for (Utils::QtcProcess::ConstArgIterator ait(allArguments()); ait.next(); )
        if (ait.isSimple())
            result << ait.value();
458
    return result;
459
460
}

461
QString QMakeStep::userArguments()
462
{
dt's avatar
dt committed
463
    return m_userArgs;
464
465
}

466
Utils::FileName QMakeStep::mkspec()
467
468
469
470
471
472
{
    Qt4BuildConfiguration *bc = qt4BuildConfiguration();
    QString additionalArguments = m_userArgs;
    for (Utils::QtcProcess::ArgIterator ait(&additionalArguments); ait.next(); ) {
        if (ait.value() == QLatin1String("-spec")) {
            if (ait.next())
473
                return Utils::FileName::fromUserInput(ait.value());
474
475
476
        }
    }

477
    return static_cast<Qt4BaseTarget *>(target())->mkspec(bc);
478
479
}

480
QVariantMap QMakeStep::toMap() const
481
{
482
483
    QVariantMap map(AbstractProcessStep::toMap());
    map.insert(QLatin1String(QMAKE_ARGUMENTS_KEY), m_userArgs);
484
485
    map.insert(QLatin1String(QMAKE_QMLDEBUGLIBAUTO_KEY), m_linkQmlDebuggingLibrary == DebugLink);
    map.insert(QLatin1String(QMAKE_QMLDEBUGLIB_KEY), m_linkQmlDebuggingLibrary == DoLink);
486
    map.insert(QLatin1String(QMAKE_FORCED_KEY), m_forced);
487
    return map;
488
489
}

490
bool QMakeStep::fromMap(const QVariantMap &map)
491
{
492
    m_userArgs = map.value(QLatin1String(QMAKE_ARGUMENTS_KEY)).toString();
493
    m_forced = map.value(QLatin1String(QMAKE_FORCED_KEY), false).toBool();
494
495
496
497
498
499
500
501
502
503
    if (map.value(QLatin1String(QMAKE_QMLDEBUGLIBAUTO_KEY), false).toBool()) {
        m_linkQmlDebuggingLibrary = DebugLink;
    } else {
        if (map.value(QLatin1String(QMAKE_QMLDEBUGLIB_KEY), false).toBool()) {
            m_linkQmlDebuggingLibrary = DoLink;
        } else {
            m_linkQmlDebuggingLibrary = DoNotLink;
        }
    }

504
    return BuildStep::fromMap(map);
505
506
}

507
508
509
510
////
// QMakeStepConfigWidget
////

con's avatar
con committed
511
QMakeStepConfigWidget::QMakeStepConfigWidget(QMakeStep *step)
512
    : BuildStepConfigWidget(), m_ui(new Internal::Ui::QMakeStep), m_step(step),
513
      m_ignoreChange(false)
con's avatar
con committed
514
{
515
    m_ui->setupUi(this);
dt_'s avatar
dt_ committed
516
517
518
519
520
521
522
523
524
525

    m_ui->qmakeAdditonalArgumentsLineEdit->setText(m_step->userArguments());
    m_ui->qmlDebuggingLibraryCheckBox->setChecked(m_step->linkQmlDebuggingLibrary());

    qmakeBuildConfigChanged();

    updateSummaryLabel();
    updateEffectiveQMakeCall();
    updateQmlDebuggingOption();

526
    connect(m_ui->qmakeAdditonalArgumentsLineEdit, SIGNAL(textEdited(const QString&)),
527
            this, SLOT(qmakeArgumentsLineEdited()));
528
    connect(m_ui->buildConfigurationComboBox, SIGNAL(currentIndexChanged(int)),
529
            this, SLOT(buildConfigurationSelected()));
530
    connect(m_ui->qmlDebuggingLibraryCheckBox, SIGNAL(toggled(bool)),
531
            this, SLOT(linkQmlDebuggingLibraryChecked(bool)));
532
    connect(m_ui->qmlDebuggingWarningText, SIGNAL(linkActivated(QString)),
533
            this, SLOT(buildQmlDebuggingHelper()));
534
535
    connect(step, SIGNAL(userArgumentsChanged()),
            this, SLOT(userArgumentsChanged()));
536
537
    connect(step, SIGNAL(linkQmlDebuggingLibraryChanged()),
            this, SLOT(linkQmlDebuggingLibraryChanged()));
538
    connect(step->qt4BuildConfiguration(), SIGNAL(qtVersionChanged()),
539
            this, SLOT(qtVersionChanged()));
Tobias Hunger's avatar
Tobias Hunger committed
540
541
    connect(step->qt4BuildConfiguration(), SIGNAL(toolChainChanged()),
            this, SLOT(qtVersionChanged()));
542
543
    connect(step->qt4BuildConfiguration(), SIGNAL(qmakeBuildConfigurationChanged()),
            this, SLOT(qmakeBuildConfigChanged()));
544
545
    connect(QtSupport::QtVersionManager::instance(), SIGNAL(dumpUpdatedFor(Utils::FileName)),
            this, SLOT(qtVersionsDumpUpdated(Utils::FileName)));
546
547
}

548
549
550
551
552
QMakeStepConfigWidget::~QMakeStepConfigWidget()
{
    delete m_ui;
}

dt's avatar
dt committed
553
554
555
556
557
QString QMakeStepConfigWidget::summaryText() const
{
    return m_summaryText;
}

558
559
560
561
562
QString QMakeStepConfigWidget::additionalSummaryText() const
{
    return m_additionalSummaryText;
}

563
564
565
566
567
QString QMakeStepConfigWidget::displayName() const
{
    return m_step->displayName();
}

568
void QMakeStepConfigWidget::qtVersionChanged()
569
{
570
    updateSummaryLabel();
dt's avatar
dt committed
571
    updateEffectiveQMakeCall();
572
    updateQmlDebuggingOption();
573
574
}

575
void QMakeStepConfigWidget::qtVersionsDumpUpdated(const Utils::FileName &qmakeCommand)
576
{
577
    QtSupport::BaseQtVersion *version = m_step->qt4BuildConfiguration()->qtVersion();
578
579
    if (version && version->qmakeCommand() == qmakeCommand)
        qtVersionChanged();
580
581
}

582
void QMakeStepConfigWidget::qmakeBuildConfigChanged()
dt's avatar
dt committed
583
{
584
    Qt4BuildConfiguration *bc = m_step->qt4BuildConfiguration();
585
    bool debug = bc->qmakeBuildConfiguration() & QtSupport::BaseQtVersion::DebugBuild;
586
    m_ignoreChange = true;
587
    m_ui->buildConfigurationComboBox->setCurrentIndex(debug? 0 : 1);
588
589
590
591
    m_ignoreChange = false;
    updateSummaryLabel();
    updateEffectiveQMakeCall();
}
dt's avatar
dt committed
592

593
594
595
596
void QMakeStepConfigWidget::userArgumentsChanged()
{
    if (m_ignoreChange)
        return;
597
    m_ui->qmakeAdditonalArgumentsLineEdit->setText(m_step->userArguments());
598
599
    updateSummaryLabel();
    updateEffectiveQMakeCall();
dt's avatar
dt committed
600
601
}

602
603
604
605
void QMakeStepConfigWidget::linkQmlDebuggingLibraryChanged()
{
    if (m_ignoreChange)
        return;
606
    m_ui->qmlDebuggingLibraryCheckBox->setChecked(m_step->linkQmlDebuggingLibrary());
607
608
609

    updateSummaryLabel();
    updateEffectiveQMakeCall();
610
    updateQmlDebuggingOption();
611
612
}

613
void QMakeStepConfigWidget::qmakeArgumentsLineEdited()
con's avatar
con committed
614
{
615
    m_ignoreChange = true;
616
    m_step->setUserArguments(m_ui->qmakeAdditonalArgumentsLineEdit->text());
617
    m_ignoreChange = false;
618

619
    updateSummaryLabel();
620
    updateEffectiveQMakeCall();
con's avatar
con committed
621
622
}

623
void QMakeStepConfigWidget::buildConfigurationSelected()
con's avatar
con committed
624
{
625
626
627
    if (m_ignoreChange)
        return;
    Qt4BuildConfiguration *bc = m_step->qt4BuildConfiguration();
628
    QtSupport::BaseQtVersion::QmakeBuildConfigs buildConfiguration = bc->qmakeBuildConfiguration();
629
    if (m_ui->buildConfigurationComboBox->currentIndex() == 0) { // debug
dt_'s avatar
dt_ committed
630
631
632
        buildConfiguration = buildConfiguration | QtSupport::BaseQtVersion::DebugBuild;
    } else {
        buildConfiguration = buildConfiguration & ~QtSupport::BaseQtVersion::DebugBuild;
con's avatar
con committed
633
    }
634
635
636
    m_ignoreChange = true;
    bc->setQMakeBuildConfiguration(buildConfiguration);
    m_ignoreChange = false;
con's avatar
con committed
637

638
639
    updateSummaryLabel();
    updateEffectiveQMakeCall();
con's avatar
con committed
640
641
}

642
643
644
645
646
647
648
649
650
651
652
void QMakeStepConfigWidget::linkQmlDebuggingLibraryChecked(bool checked)
{
    if (m_ignoreChange)
        return;

    m_ignoreChange = true;
    m_step->setLinkQmlDebuggingLibrary(checked);
    m_ignoreChange = false;

    updateSummaryLabel();
    updateEffectiveQMakeCall();
653
    updateQmlDebuggingOption();
654

hjk's avatar
hjk committed
655
    QMessageBox *question = new QMessageBox(Core::ICore::mainWindow());
656
657
658
659
660
661
    question->setWindowTitle(tr("QML Debugging"));
    question->setText(tr("The option will only take effect if the project is recompiled. Do you want to recompile now?"));
    question->setStandardButtons(QMessageBox::Yes | QMessageBox::No);
    question->setModal(true);
    connect(question, SIGNAL(finished(int)), this, SLOT(recompileMessageBoxFinished(int)));
    question->show();
662
663
664
665
}

void QMakeStepConfigWidget::buildQmlDebuggingHelper()
{
666
    QtSupport::BaseQtVersion *version = m_step->qt4BuildConfiguration()->qtVersion();
dt's avatar
dt committed
667
668
    if (!version)
        return;
669

670
    QtSupport::DebuggingHelperBuildTask *buildTask =
671
672
            new QtSupport::DebuggingHelperBuildTask(version, m_step->qt4BuildConfiguration()->toolChain(),
                                                    QtSupport::DebuggingHelperBuildTask::QmlDebugging);
673

674
675
676
    // pop up Application Output on error
    buildTask->showOutputOnError(true);

677
    QFuture<void> task = QtConcurrent::run(&QtSupport::DebuggingHelperBuildTask::run, buildTask);
678
    const QString taskName = tr("Building helpers");
hjk's avatar
hjk committed
679
    Core::ICore::progressManager()->addTask(task, taskName,
680
681
682
                                                        QLatin1String("Qt4ProjectManager::BuildHelpers"));
}

683
void QMakeStepConfigWidget::updateSummaryLabel()
684
{
685
    Qt4BuildConfiguration *qt4bc = m_step->qt4BuildConfiguration();
686
    QtSupport::BaseQtVersion *qtVersion = qt4bc->qtVersion();
687
    if (!qtVersion) {
688
        setSummaryText(tr("<b>qmake:</b> No Qt version set. Cannot run qmake."));
689
        return;
690
691
    }
    // We don't want the full path to the .pro file
692
    QString args = m_step->allArguments(true);
693
    // And we only use the .pro filename not the full path
694
    QString program = qtVersion->qmakeCommand().toFileInfo().fileName();
695
    setSummaryText(tr("<b>qmake:</b> %1 %2").arg(program, args));
696

697
698
699
    ToolChain *tc = qt4bc->toolChain();
    if (!tc)
        return;
700
    QList<Utils::FileName> tcSpecList = tc->mkspecList();
701
    if (!tcSpecList.isEmpty() && !tcSpecList.contains(m_step->mkspec()))
702
        setAdditionalSummaryText(tr("<b>Warning:</b> The tool chain suggests using another mkspec."));
703
704
    else
        setAdditionalSummaryText(QString());
705
706
}

707
void QMakeStepConfigWidget::updateQmlDebuggingOption()
708
{
709
    m_ui->qmlDebuggingLibraryCheckBox->setEnabled(m_step->isQmlDebuggingLibrarySupported());
710
    m_ui->debuggingLibraryLabel->setText(tr("Enable QML debugging:"));
711
712
713
714
715
716

    QString warningText;

    if (!m_step->isQmlDebuggingLibrarySupported(&warningText))
        ;
    else if (m_step->linkQmlDebuggingLibrary())
717
        warningText = tr("Might make your application vulnerable. Only use in a safe environment.");
718

719
720
    m_ui->qmlDebuggingWarningText->setText(warningText);
    m_ui->qmlDebuggingWarningIcon->setVisible(!warningText.isEmpty());
721
722
}

723
724
void QMakeStepConfigWidget::updateEffectiveQMakeCall()
{
dt's avatar
dt committed
725
    Qt4BuildConfiguration *qt4bc = m_step->qt4BuildConfiguration();
726
    QtSupport::BaseQtVersion *qtVersion = qt4bc->qtVersion();
727
    QString program = tr("<No Qt version>");
dt's avatar
dt committed
728
    if (qtVersion)
729
        program = qtVersion->qmakeCommand().toFileInfo().fileName();
730
    m_ui->qmakeArgumentsEdit->setPlainText(program + QLatin1Char(' ') + m_step->allArguments());
con's avatar
con committed
731
732
}

733
734
735
736
737
738
739
740
void QMakeStepConfigWidget::recompileMessageBoxFinished(int button)
{
    if (button == QMessageBox::Yes) {
        Qt4BuildConfiguration *bc = m_step->qt4BuildConfiguration();
        if (!bc)
            return;

        QList<ProjectExplorer::BuildStepList *> stepLists;
741
742
743
        const QString clean = QLatin1String(ProjectExplorer::Constants::BUILDSTEPS_CLEAN);
        const QString build = QLatin1String(ProjectExplorer::Constants::BUILDSTEPS_BUILD);
        stepLists << bc->stepList(clean) << bc->stepList(build);
744
        ProjectExplorer::BuildManager *bm = ProjectExplorerPlugin::instance()->buildManager();
745
746
        bm->buildLists(stepLists, QStringList() << ProjectExplorerPlugin::displayNameForStepId(clean)
                       << ProjectExplorerPlugin::displayNameForStepId(build));
747
748
749
    }
}

750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
void QMakeStepConfigWidget::setSummaryText(const QString &text)
{
    if (text == m_summaryText)
        return;
    m_summaryText = text;
    emit updateSummary();
}

void QMakeStepConfigWidget::setAdditionalSummaryText(const QString &text)
{
    if (text == m_additionalSummaryText)
        return;
    m_additionalSummaryText = text;
    emit updateAdditionalSummary();
}

dt's avatar
dt committed
766
767
768
769
////
// QMakeStepFactory
////

770
771
QMakeStepFactory::QMakeStepFactory(QObject *parent) :
    ProjectExplorer::IBuildStepFactory(parent)
dt's avatar
dt committed
772
773
774
775
776
777
778
{
}

QMakeStepFactory::~QMakeStepFactory()
{
}

Tobias Hunger's avatar
Tobias Hunger committed
779
bool QMakeStepFactory::canCreate(BuildStepList *parent, const QString &id) const
dt's avatar
dt committed
780
{
Tobias Hunger's avatar
Tobias Hunger committed
781
    if (parent->id() != QLatin1String(ProjectExplorer::Constants::BUILDSTEPS_BUILD))
782
        return false;
Tobias Hunger's avatar
Tobias Hunger committed
783
    if (!qobject_cast<Qt4BuildConfiguration *>(parent->parent()))
784
785
        return false;
    return (id == QLatin1String(QMAKE_BS_ID));
dt's avatar
dt committed
786
787
}

Tobias Hunger's avatar
Tobias Hunger committed
788
ProjectExplorer::BuildStep *QMakeStepFactory::create(BuildStepList *parent, const QString &id)
dt's avatar
dt committed
789
{
Tobias Hunger's avatar
Tobias Hunger committed
790
    if (!canCreate(parent, id))
791
        return 0;
Tobias Hunger's avatar
Tobias Hunger committed
792
    return new QMakeStep(parent);
793
794
}

Tobias Hunger's avatar
Tobias Hunger committed
795
bool QMakeStepFactory::canClone(BuildStepList *parent, BuildStep *source) const
796
{
Tobias Hunger's avatar
Tobias Hunger committed
797
    return canCreate(parent, source->id());
dt's avatar
dt committed
798
799
}

Tobias Hunger's avatar
Tobias Hunger committed
800
ProjectExplorer::BuildStep *QMakeStepFactory::clone(BuildStepList *parent, ProjectExplorer::BuildStep *source)
dt's avatar
dt committed
801
{
Tobias Hunger's avatar
Tobias Hunger committed
802
    if (!canClone(parent, source))
803
        return 0;
Tobias Hunger's avatar
Tobias Hunger committed
804
    return new QMakeStep(parent, qobject_cast<QMakeStep *>(source));
dt's avatar
dt committed
805
806
}

Tobias Hunger's avatar
Tobias Hunger committed
807
bool QMakeStepFactory::canRestore(BuildStepList *parent, const QVariantMap &map) const
808
809
{
    QString id(ProjectExplorer::idFromMap(map));
Tobias Hunger's avatar
Tobias Hunger committed
810
    return canCreate(parent, id);
811
812
}

Tobias Hunger's avatar
Tobias Hunger committed
813
ProjectExplorer::BuildStep *QMakeStepFactory::restore(BuildStepList *parent, const QVariantMap &map)
dt's avatar
dt committed
814
{
Tobias Hunger's avatar
Tobias Hunger committed
815
    if (!canRestore(parent, map))
816
        return 0;
Tobias Hunger's avatar
Tobias Hunger committed
817
    QMakeStep *bs = new QMakeStep(parent);
818
819
820
821
    if (bs->fromMap(map))
        return bs;
    delete bs;
    return 0;
dt's avatar
dt committed
822
823
}

Tobias Hunger's avatar
Tobias Hunger committed
824
QStringList QMakeStepFactory::availableCreationIds(ProjectExplorer::BuildStepList *parent) const
825
{
Tobias Hunger's avatar
Tobias Hunger committed
826
827
    if (parent->id() == QLatin1String(ProjectExplorer::Constants::BUILDSTEPS_BUILD))
        if (Qt4BuildConfiguration *bc = qobject_cast<Qt4BuildConfiguration *>(parent->parent()))
828
829
            if (!bc->qmakeStep())
                return QStringList() << QLatin1String(QMAKE_BS_ID);
830
831
    return QStringList();
}
dt's avatar
dt committed
832

833
834
835
QString QMakeStepFactory::displayNameForId(const QString &id) const
{
    if (id == QLatin1String(QMAKE_BS_ID))
836
        return tr("qmake");
837
838
    return QString();
}