qmakestep.cpp 25.8 KB
Newer Older
hjk's avatar
hjk committed
1
/****************************************************************************
con's avatar
con committed
2
**
3
** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
hjk's avatar
hjk committed
4
** Contact: http://www.qt-project.org/legal
con's avatar
con committed
5
**
hjk's avatar
hjk committed
6
** This file is part of Qt Creator.
con's avatar
con committed
7
**
hjk's avatar
hjk committed
8
9
10
11
12
13
14
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Digia.  For licensing terms and
** conditions see http://qt.digia.com/licensing.  For further information
** use the contact form at http://qt.digia.com/contact-us.
15
**
16
** GNU Lesser General Public License Usage
hjk's avatar
hjk committed
17
18
19
20
21
22
23
24
25
** 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.
**
** In addition, as a special exception, Digia gives you certain additional
** rights.  These rights are described in the Digia Qt LGPL Exception
con's avatar
con committed
26
27
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
hjk's avatar
hjk committed
28
****************************************************************************/
hjk's avatar
hjk committed
29

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

Tobias Hunger's avatar
Tobias Hunger committed
33
34
#include "qmakeparser.h"
#include "qt4buildconfiguration.h"
con's avatar
con committed
35
36
#include "qt4project.h"
#include "qt4projectmanagerconstants.h"
Tobias Hunger's avatar
Tobias Hunger committed
37
#include "qmakekitinformation.h"
38
#include "qt4nodes.h"
con's avatar
con committed
39

40
#include <projectexplorer/buildmanager.h>
Tobias Hunger's avatar
Tobias Hunger committed
41
#include <projectexplorer/buildsteplist.h>
42
#include <projectexplorer/projectexplorer.h>
Tobias Hunger's avatar
Tobias Hunger committed
43
#include <projectexplorer/target.h>
Tobias Hunger's avatar
Tobias Hunger committed
44

con's avatar
con committed
45
#include <coreplugin/icore.h>
46
#include <coreplugin/progressmanager/progressmanager.h>
Tobias Hunger's avatar
Tobias Hunger committed
47
#include <qtsupport/qtkitinformation.h>
48
49
#include <qtsupport/qtversionmanager.h>
#include <qtsupport/debugginghelperbuildtask.h>
50
#include <utils/hostosinfo.h>
51
#include <utils/qtcprocess.h>
con's avatar
con committed
52

53
#include <QDir>
54
#include <utils/runextensions.h>
55
#include <QMessageBox>
con's avatar
con committed
56
57
58
59

using namespace Qt4ProjectManager;
using namespace Qt4ProjectManager::Internal;
using namespace ProjectExplorer;
60
using namespace Utils;
con's avatar
con committed
61

62
namespace {
Orgad Shaneh's avatar
Orgad Shaneh committed
63
const char QMAKE_BS_ID[] = "QtProjectManager.QMakeBuildStep";
64

Orgad Shaneh's avatar
Orgad Shaneh committed
65
66
67
68
const char QMAKE_ARGUMENTS_KEY[] = "QtProjectManager.QMakeBuildStep.QMakeArguments";
const char QMAKE_FORCED_KEY[] = "QtProjectManager.QMakeBuildStep.QMakeForced";
const char QMAKE_QMLDEBUGLIBAUTO_KEY[] = "QtProjectManager.QMakeBuildStep.LinkQmlDebuggingLibraryAuto";
const char QMAKE_QMLDEBUGLIB_KEY[] = "QtProjectManager.QMakeBuildStep.LinkQmlDebuggingLibrary";
69
70
}

Tobias Hunger's avatar
Tobias Hunger committed
71
QMakeStep::QMakeStep(BuildStepList *bsl) :
72
    AbstractProcessStep(bsl, Core::Id(QMAKE_BS_ID)),
73
    m_forced(false),
74
    m_needToRunQMake(false),
75
    m_linkQmlDebuggingLibrary(DebugLink)
con's avatar
con committed
76
{
77
    ctor();
con's avatar
con committed
78
79
}

80
QMakeStep::QMakeStep(BuildStepList *bsl, const Core::Id id) :
Tobias Hunger's avatar
Tobias Hunger committed
81
    AbstractProcessStep(bsl, id),
82
    m_forced(false),
83
    m_linkQmlDebuggingLibrary(DebugLink)
84
85
86
87
{
    ctor();
}

Tobias Hunger's avatar
Tobias Hunger committed
88
89
QMakeStep::QMakeStep(BuildStepList *bsl, QMakeStep *bs) :
    AbstractProcessStep(bsl, bs),
90
    m_forced(bs->m_forced),
91
92
    m_userArgs(bs->m_userArgs),
    m_linkQmlDebuggingLibrary(bs->m_linkQmlDebuggingLibrary)
93
{
94
95
96
97
98
    ctor();
}

void QMakeStep::ctor()
{
99
100
    //: QMakeStep default display name
    setDefaultDisplayName(tr("qmake"));
101
102
}

con's avatar
con committed
103
104
105
106
QMakeStep::~QMakeStep()
{
}

dt's avatar
dt committed
107
108
109
110
111
Qt4BuildConfiguration *QMakeStep::qt4BuildConfiguration() const
{
    return static_cast<Qt4BuildConfiguration *>(buildConfiguration());
}

dt's avatar
dt committed
112
113
114
115
116
117
118
///
/// Returns all arguments
/// That is: possbile subpath
/// spec
/// config arguemnts
/// moreArguments
/// user arguments
119
QString QMakeStep::allArguments(bool shorted)
con's avatar
con committed
120
{
dt's avatar
dt committed
121
    Qt4BuildConfiguration *bc = qt4BuildConfiguration();
con's avatar
con committed
122
    QStringList arguments;
123
    if (bc->subNodeBuild())
124
        arguments << QDir::toNativeSeparators(bc->subNodeBuild()->path());
125
    else if (shorted)
126
        arguments << QDir::toNativeSeparators(QFileInfo(project()->document()->fileName()).fileName());
127
    else
128
        arguments << QDir::toNativeSeparators(project()->document()->fileName());
con's avatar
con committed
129

130
    arguments << QLatin1String("-r");
131
    bool userProvidedMkspec = false;
132
    for (QtcProcess::ConstArgIterator ait(m_userArgs); ait.next(); ) {
133
134
135
136
137
        if (ait.value() == QLatin1String("-spec")) {
            if (ait.next()) {
                userProvidedMkspec = true;
                break;
            }
dt's avatar
dt committed
138
        }
139
    }
140
    FileName specArg = mkspec();
141
    if (!userProvidedMkspec && !specArg.isEmpty())
142
        arguments << QLatin1String("-spec") << specArg.toUserOutput();
143

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

147
    arguments << deducedArguments();
148

149
    QString args = QtcProcess::joinArgs(arguments);
150
    // User arguments
151
    QtcProcess::addArgs(&args, m_userArgs);
152
    // moreArgumentsAfter
153
    foreach (const QString &arg, deducedArgumentsAfter())
154
        QtcProcess::addArg(&args, arg);
155
    return args;
dt's avatar
dt committed
156
157
}

dt's avatar
dt committed
158
159
160
///
/// moreArguments,
/// -unix for Maemo
161
/// QMAKE_VAR_QMLJSDEBUGGER_PATH
162
QStringList QMakeStep::deducedArguments()
dt's avatar
dt committed
163
164
{
    QStringList arguments;
Tobias Hunger's avatar
Tobias Hunger committed
165
    ProjectExplorer::ToolChain *tc
Tobias Hunger's avatar
Tobias Hunger committed
166
            = ProjectExplorer::ToolChainKitInformation::toolChain(target()->kit());
167
168
169
    ProjectExplorer::Abi targetAbi;
    if (tc)
        targetAbi = tc->targetAbi();
170
171
172
    if ((HostOsInfo::isWindowsHost() || HostOsInfo::isMacHost())
            && (targetAbi.osFlavor() == ProjectExplorer::Abi::HarmattanLinuxFlavor
                || targetAbi.osFlavor() == ProjectExplorer::Abi::MaemoLinuxFlavor)) {
ck's avatar
ck committed
173
        arguments << QLatin1String("-unix");
174
    }
175

176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
    // 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");
        }
    }

Tobias Hunger's avatar
Tobias Hunger committed
192
    QtSupport::BaseQtVersion *version = QtSupport::QtKitInformation::qtVersion(target()->kit());
Tobias Hunger's avatar
Tobias Hunger committed
193
194
    if (linkQmlDebuggingLibrary() && version) {
        if (!version->needsQmlDebuggingLibrary()) {
195
196
            // This Qt version has the QML debugging services built in, however
            // they still need to be enabled at compile time
197
198
199
            // TODO: For Qt5, we can pass both arguments as there can be Qt Quick 1/2 projects.
            // Currently there is no support for debugging multiple engines.
            arguments << QLatin1String(Constants::QMAKEVAR_QUICK1_DEBUG);
200
            if (version->qtVersion().majorVersion >= 5)
201
                arguments << QLatin1String(Constants::QMAKEVAR_QUICK2_DEBUG);
202
        } else {
Tobias Hunger's avatar
Tobias Hunger committed
203
            const QString qmlDebuggingHelperLibrary = version->qmlDebuggingHelperLibrary(true);
204
205
206
207
208
209
210
211
212
            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;
            }
        }
213
214
    }

215
216
217
218

    return arguments;
}

219
/// -after OBJECTS_DIR, MOC_DIR, UI_DIR, RCC_DIR
220
QStringList QMakeStep::deducedArgumentsAfter()
221
{
Tobias Hunger's avatar
Tobias Hunger committed
222
    QtSupport::BaseQtVersion *version = QtSupport::QtKitInformation::qtVersion(target()->kit());
223
    if (version && !version->supportsShadowBuilds()) {
224
225
226
        // 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.
227
        // This is a HACK, remove once all make generators support
228
        // shadow building
229
230
231
232
233
        return QStringList() << QLatin1String("-after")
                             << QLatin1String("OBJECTS_DIR=obj")
                             << QLatin1String("MOC_DIR=moc")
                             << QLatin1String("UI_DIR=ui")
                             << QLatin1String("RCC_DIR=rcc");
234
    }
235
    return QStringList();
con's avatar
con committed
236
237
}

238
bool QMakeStep::init()
con's avatar
con committed
239
{
dt's avatar
dt committed
240
    Qt4BuildConfiguration *qt4bc = qt4BuildConfiguration();
Tobias Hunger's avatar
Tobias Hunger committed
241
    const QtSupport::BaseQtVersion *qtVersion = QtSupport::QtKitInformation::qtVersion(target()->kit());
dt's avatar
dt committed
242
243
244

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

246
    QString args = allArguments();
247
    QString workingDirectory;
248

249
250
251
252
    if (qt4bc->subNodeBuild())
        workingDirectory = qt4bc->subNodeBuild()->buildDir();
    else
        workingDirectory = qt4bc->buildDirectory();
con's avatar
con committed
253

254
    FileName program = qtVersion->qmakeCommand();
con's avatar
con committed
255

256
257
258
    QString makefile = workingDirectory;

    if (qt4bc->subNodeBuild()) {
Tobias Hunger's avatar
Tobias Hunger committed
259
        if (!qt4bc->subNodeBuild()->makefile().isEmpty())
260
            makefile.append(qt4bc->subNodeBuild()->makefile());
Tobias Hunger's avatar
Tobias Hunger committed
261
        else
262
            makefile.append(QLatin1String("/Makefile"));
263
    } else if (!qt4bc->makefile().isEmpty()) {
264
        makefile.append(QLatin1Char('/'));
265
266
        makefile.append(qt4bc->makefile());
    } else {
267
        makefile.append(QLatin1String("/Makefile"));
268
269
    }

270
    // Check whether we need to run qmake
Tobias Hunger's avatar
Tobias Hunger committed
271
    bool makefileOutDated = (qt4bc->compareToImportFrom(makefile) != Qt4BuildConfiguration::MakefileMatches);
272
    if (m_forced || makefileOutDated)
273
        m_needToRunQMake = true;
274
    m_forced = false;
con's avatar
con committed
275

276
277
278
    ProcessParameters *pp = processParameters();
    pp->setMacroExpander(qt4bc->macroExpander());
    pp->setWorkingDirectory(workingDirectory);
279
    pp->setCommand(program.toString());
280
281
    pp->setArguments(args);
    pp->setEnvironment(qt4bc->environment());
282
    pp->resolveAll();
283

Tobias Hunger's avatar
Tobias Hunger committed
284
    setOutputParser(new QMakeParser);
dt's avatar
dt committed
285

Tobias Hunger's avatar
Tobias Hunger committed
286
    Qt4ProFileNode *node = static_cast<Qt4Project *>(qt4bc->target()->project())->rootQt4ProjectNode();
dt's avatar
dt committed
287
288
289
290
    if (qt4bc->subNodeBuild())
        node = qt4bc->subNodeBuild();
    QString proFile = node->path();

Tobias Hunger's avatar
Tobias Hunger committed
291
    m_tasks = qtVersion->reportIssues(proFile, workingDirectory);
292
293
    qSort(m_tasks);

dt's avatar
dt committed
294
    m_scriptTemplate = node->projectType() == ScriptTemplate;
dt's avatar
dt committed
295

Tobias Hunger's avatar
Tobias Hunger committed
296
    return AbstractProcessStep::init();
con's avatar
con committed
297
298
299
300
}

void QMakeStep::run(QFutureInterface<bool> &fi)
{
dt's avatar
dt committed
301
    if (m_scriptTemplate) {
con's avatar
con committed
302
303
304
        fi.reportResult(true);
        return;
    }
305

306
    // Warn on common error conditions:
307
    bool canContinue = true;
dt's avatar
dt committed
308
    foreach (const ProjectExplorer::Task &t, m_tasks) {
309
310
311
312
313
        addTask(t);
        if (t.type == Task::Error)
            canContinue = false;
    }
    if (!canContinue) {
314
        emit addOutput(tr("Configuration is faulty, please check the Issues view for details."), BuildStep::MessageOutput);
315
        fi.reportResult(false);
316
        emit finished();
317
        return;
318
319
    }

320
    if (!m_needToRunQMake) {
321
        emit addOutput(tr("Configuration unchanged, skipping qmake step."), BuildStep::MessageOutput);
con's avatar
con committed
322
        fi.reportResult(true);
323
        emit finished();
con's avatar
con committed
324
325
        return;
    }
326

327
    m_needToRunQMake = false;
Tobias Hunger's avatar
Tobias Hunger committed
328
    AbstractProcessStep::run(fi);
con's avatar
con committed
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
}

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
348
    return false;
con's avatar
con committed
349
350
351
352
}

void QMakeStep::processStartupFailed()
{
353
    m_needToRunQMake = true;
con's avatar
con committed
354
355
356
    AbstractProcessStep::processStartupFailed();
}

357
bool QMakeStep::processSucceeded(int exitCode, QProcess::ExitStatus status)
con's avatar
con committed
358
{
359
    bool result = AbstractProcessStep::processSucceeded(exitCode, status);
con's avatar
con committed
360
    if (!result)
361
        m_needToRunQMake = true;
362
363
    Qt4Project *project = static_cast<Qt4Project *>(qt4BuildConfiguration()->target()->project());
    project->emitBuildDirectoryInitialized();
con's avatar
con committed
364
365
366
    return result;
}

367
void QMakeStep::setUserArguments(const QString &arguments)
368
{
369
370
    if (m_userArgs == arguments)
        return;
dt's avatar
dt committed
371
    m_userArgs = arguments;
372

373
    emit userArgumentsChanged();
374
375

    qt4BuildConfiguration()->emitQMakeBuildConfigurationChanged();
376
    qt4BuildConfiguration()->emitProFileEvaluateNeeded();
377
378
}

379
380
bool QMakeStep::isQmlDebuggingLibrarySupported(QString *reason) const
{
Tobias Hunger's avatar
Tobias Hunger committed
381
    QtSupport::BaseQtVersion *version = QtSupport::QtKitInformation::qtVersion(target()->kit());
dt's avatar
dt committed
382
383
384
385
386
    if (!version) {
        if (reason)
            *reason = tr("No Qt version.");
        return false;
    }
387
388

    if (!version->needsQmlDebuggingLibrary() || version->hasQmlDebuggingLibrary())
389
390
        return true;

dt's avatar
dt committed
391
    if (!version->qtAbis().isEmpty()) {
Tobias Hunger's avatar
Tobias Hunger committed
392
        ProjectExplorer::Abi abi = version->qtAbis().first();
393
        if (abi.osFlavor() == ProjectExplorer::Abi::MaemoLinuxFlavor) {
394
            if (reason)
Friedemann Kleint's avatar
Friedemann Kleint committed
395
                reason->clear();
396
397
398
399
400
//               *reason = tr("Qml debugging on device not yet supported.");
            return false;
        }
    }

dt's avatar
dt committed
401
    if (!version->isValid()) {
402
403
404
405
406
        if (reason)
            *reason = tr("Invalid Qt version.");
        return false;
    }

407
    if (version->qtVersion() < QtSupport::QtVersionNumber(4, 7, 1)) {
408
409
410
411
412
413
        if (reason)
            *reason = tr("Requires Qt 4.7.1 or newer.");
        return false;
    }

    if (reason)
414
        *reason = tr("Library not available. <a href='compile'>Compile...</a>");
415
416
417
418
419
420

    return false;
}

bool QMakeStep::linkQmlDebuggingLibrary() const
{
421
422
423
424
425
    if (m_linkQmlDebuggingLibrary == DoLink)
        return true;
    if (m_linkQmlDebuggingLibrary == DoNotLink)
        return false;
    return (qt4BuildConfiguration()->buildType() & BuildConfiguration::Debug);
426
427
428
429
}

void QMakeStep::setLinkQmlDebuggingLibrary(bool enable)
{
430
431
    if ((enable && (m_linkQmlDebuggingLibrary == DoLink))
            || (!enable && (m_linkQmlDebuggingLibrary == DoNotLink)))
432
        return;
433
    m_linkQmlDebuggingLibrary = enable ? DoLink : DoNotLink;
434
435
436
437

    emit linkQmlDebuggingLibraryChanged();

    qt4BuildConfiguration()->emitQMakeBuildConfigurationChanged();
438
    qt4BuildConfiguration()->emitProFileEvaluateNeeded();
439
440
}

441
442
443
QStringList QMakeStep::parserArguments()
{
    QStringList result;
444
    for (QtcProcess::ConstArgIterator ait(allArguments()); ait.next(); )
445
446
        if (ait.isSimple())
            result << ait.value();
447
    return result;
448
449
}

450
QString QMakeStep::userArguments()
451
{
dt's avatar
dt committed
452
    return m_userArgs;
453
454
}

455
FileName QMakeStep::mkspec()
456
457
{
    QString additionalArguments = m_userArgs;
458
    for (QtcProcess::ArgIterator ait(&additionalArguments); ait.next(); ) {
459
460
        if (ait.value() == QLatin1String("-spec")) {
            if (ait.next())
461
                return FileName::fromUserInput(ait.value());
462
463
464
        }
    }

Tobias Hunger's avatar
Tobias Hunger committed
465
    return Qt4ProjectManager::QmakeKitInformation::effectiveMkspec(target()->kit());
466
467
}

468
QVariantMap QMakeStep::toMap() const
469
{
470
471
    QVariantMap map(AbstractProcessStep::toMap());
    map.insert(QLatin1String(QMAKE_ARGUMENTS_KEY), m_userArgs);
472
473
    map.insert(QLatin1String(QMAKE_QMLDEBUGLIBAUTO_KEY), m_linkQmlDebuggingLibrary == DebugLink);
    map.insert(QLatin1String(QMAKE_QMLDEBUGLIB_KEY), m_linkQmlDebuggingLibrary == DoLink);
474
    map.insert(QLatin1String(QMAKE_FORCED_KEY), m_forced);
475
    return map;
476
477
}

478
bool QMakeStep::fromMap(const QVariantMap &map)
479
{
480
    m_userArgs = map.value(QLatin1String(QMAKE_ARGUMENTS_KEY)).toString();
481
    m_forced = map.value(QLatin1String(QMAKE_FORCED_KEY), false).toBool();
482
483
484
    if (map.value(QLatin1String(QMAKE_QMLDEBUGLIBAUTO_KEY), false).toBool()) {
        m_linkQmlDebuggingLibrary = DebugLink;
    } else {
485
        if (map.value(QLatin1String(QMAKE_QMLDEBUGLIB_KEY), false).toBool())
486
            m_linkQmlDebuggingLibrary = DoLink;
487
        else
488
489
490
            m_linkQmlDebuggingLibrary = DoNotLink;
    }

491
    return BuildStep::fromMap(map);
492
493
}

494
495
496
497
////
// QMakeStepConfigWidget
////

con's avatar
con committed
498
QMakeStepConfigWidget::QMakeStepConfigWidget(QMakeStep *step)
499
    : BuildStepConfigWidget(), m_ui(new Internal::Ui::QMakeStep), m_step(step),
500
      m_ignoreChange(false)
con's avatar
con committed
501
{
502
    m_ui->setupUi(this);
dt_'s avatar
dt_ committed
503
504
505
506
507
508
509
510
511
512

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

    qmakeBuildConfigChanged();

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

Robert Loehning's avatar
Robert Loehning committed
513
    connect(m_ui->qmakeAdditonalArgumentsLineEdit, SIGNAL(textEdited(QString)),
514
            this, SLOT(qmakeArgumentsLineEdited()));
515
    connect(m_ui->buildConfigurationComboBox, SIGNAL(currentIndexChanged(int)),
516
            this, SLOT(buildConfigurationSelected()));
517
    connect(m_ui->qmlDebuggingLibraryCheckBox, SIGNAL(toggled(bool)),
518
            this, SLOT(linkQmlDebuggingLibraryChecked(bool)));
519
    connect(m_ui->qmlDebuggingWarningText, SIGNAL(linkActivated(QString)),
520
            this, SLOT(buildQmlDebuggingHelper()));
521
522
    connect(step, SIGNAL(userArgumentsChanged()),
            this, SLOT(userArgumentsChanged()));
523
524
    connect(step, SIGNAL(linkQmlDebuggingLibraryChanged()),
            this, SLOT(linkQmlDebuggingLibraryChanged()));
525
526
    connect(step->qt4BuildConfiguration(), SIGNAL(qmakeBuildConfigurationChanged()),
            this, SLOT(qmakeBuildConfigChanged()));
Tobias Hunger's avatar
Tobias Hunger committed
527
    connect(step->target(), SIGNAL(kitChanged()), this, SLOT(qtVersionChanged()));
528
529
    connect(QtSupport::QtVersionManager::instance(), SIGNAL(dumpUpdatedFor(Utils::FileName)),
            this, SLOT(qtVersionChanged()));
530
531
}

532
533
534
535
536
QMakeStepConfigWidget::~QMakeStepConfigWidget()
{
    delete m_ui;
}

dt's avatar
dt committed
537
538
539
540
541
QString QMakeStepConfigWidget::summaryText() const
{
    return m_summaryText;
}

542
543
544
545
546
QString QMakeStepConfigWidget::additionalSummaryText() const
{
    return m_additionalSummaryText;
}

547
548
549
550
551
QString QMakeStepConfigWidget::displayName() const
{
    return m_step->displayName();
}

552
void QMakeStepConfigWidget::qtVersionChanged()
553
{
554
    updateSummaryLabel();
dt's avatar
dt committed
555
    updateEffectiveQMakeCall();
556
    updateQmlDebuggingOption();
557
558
}

559
void QMakeStepConfigWidget::qmakeBuildConfigChanged()
dt's avatar
dt committed
560
{
561
    Qt4BuildConfiguration *bc = m_step->qt4BuildConfiguration();
562
    bool debug = bc->qmakeBuildConfiguration() & QtSupport::BaseQtVersion::DebugBuild;
563
    m_ignoreChange = true;
564
    m_ui->buildConfigurationComboBox->setCurrentIndex(debug? 0 : 1);
565
566
567
568
    m_ignoreChange = false;
    updateSummaryLabel();
    updateEffectiveQMakeCall();
}
dt's avatar
dt committed
569

570
571
572
573
void QMakeStepConfigWidget::userArgumentsChanged()
{
    if (m_ignoreChange)
        return;
574
    m_ui->qmakeAdditonalArgumentsLineEdit->setText(m_step->userArguments());
575
576
    updateSummaryLabel();
    updateEffectiveQMakeCall();
dt's avatar
dt committed
577
578
}

579
580
581
582
void QMakeStepConfigWidget::linkQmlDebuggingLibraryChanged()
{
    if (m_ignoreChange)
        return;
583
    m_ui->qmlDebuggingLibraryCheckBox->setChecked(m_step->linkQmlDebuggingLibrary());
584
585
586

    updateSummaryLabel();
    updateEffectiveQMakeCall();
587
    updateQmlDebuggingOption();
588
589
}

590
void QMakeStepConfigWidget::qmakeArgumentsLineEdited()
con's avatar
con committed
591
{
592
    m_ignoreChange = true;
593
    m_step->setUserArguments(m_ui->qmakeAdditonalArgumentsLineEdit->text());
594
    m_ignoreChange = false;
595

596
    updateSummaryLabel();
597
    updateEffectiveQMakeCall();
con's avatar
con committed
598
599
}

600
void QMakeStepConfigWidget::buildConfigurationSelected()
con's avatar
con committed
601
{
602
603
604
    if (m_ignoreChange)
        return;
    Qt4BuildConfiguration *bc = m_step->qt4BuildConfiguration();
605
    QtSupport::BaseQtVersion::QmakeBuildConfigs buildConfiguration = bc->qmakeBuildConfiguration();
606
    if (m_ui->buildConfigurationComboBox->currentIndex() == 0) { // debug
dt_'s avatar
dt_ committed
607
608
609
        buildConfiguration = buildConfiguration | QtSupport::BaseQtVersion::DebugBuild;
    } else {
        buildConfiguration = buildConfiguration & ~QtSupport::BaseQtVersion::DebugBuild;
con's avatar
con committed
610
    }
611
612
613
    m_ignoreChange = true;
    bc->setQMakeBuildConfiguration(buildConfiguration);
    m_ignoreChange = false;
con's avatar
con committed
614

615
616
    updateSummaryLabel();
    updateEffectiveQMakeCall();
con's avatar
con committed
617
618
}

619
620
621
622
623
624
625
626
627
628
629
void QMakeStepConfigWidget::linkQmlDebuggingLibraryChecked(bool checked)
{
    if (m_ignoreChange)
        return;

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

    updateSummaryLabel();
    updateEffectiveQMakeCall();
630
    updateQmlDebuggingOption();
631

hjk's avatar
hjk committed
632
    QMessageBox *question = new QMessageBox(Core::ICore::mainWindow());
633
634
635
636
637
638
    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();
639
640
641
642
}

void QMakeStepConfigWidget::buildQmlDebuggingHelper()
{
Tobias Hunger's avatar
Tobias Hunger committed
643
    QtSupport::BaseQtVersion *version = QtSupport::QtKitInformation::qtVersion(m_step->target()->kit());
dt's avatar
dt committed
644
645
    if (!version)
        return;
646

Tobias Hunger's avatar
Tobias Hunger committed
647
    ToolChain *tc = ProjectExplorer::ToolChainKitInformation::toolChain(m_step->target()->kit());
Tobias Hunger's avatar
Tobias Hunger committed
648

649
    QtSupport::DebuggingHelperBuildTask *buildTask =
Tobias Hunger's avatar
Tobias Hunger committed
650
            new QtSupport::DebuggingHelperBuildTask(version, tc,
651
                                                    QtSupport::DebuggingHelperBuildTask::QmlDebugging);
652

653
654
655
    // pop up Application Output on error
    buildTask->showOutputOnError(true);

656
    QFuture<void> task = QtConcurrent::run(&QtSupport::DebuggingHelperBuildTask::run, buildTask);
657
    const QString taskName = tr("Building helpers");
hjk's avatar
hjk committed
658
    Core::ICore::progressManager()->addTask(task, taskName,
659
660
661
                                                        QLatin1String("Qt4ProjectManager::BuildHelpers"));
}

662
void QMakeStepConfigWidget::updateSummaryLabel()
663
{
Tobias Hunger's avatar
Tobias Hunger committed
664
    QtSupport::BaseQtVersion *qtVersion = QtSupport::QtKitInformation::qtVersion(m_step->target()->kit());
665
    if (!qtVersion) {
666
        setSummaryText(tr("<b>qmake:</b> No Qt version set. Cannot run qmake."));
667
        return;
668
669
    }
    // We don't want the full path to the .pro file
670
    QString args = m_step->allArguments(true);
671
    // And we only use the .pro filename not the full path
672
    QString program = qtVersion->qmakeCommand().toFileInfo().fileName();
673
    setSummaryText(tr("<b>qmake:</b> %1 %2").arg(program, args));
674
675
}

676
void QMakeStepConfigWidget::updateQmlDebuggingOption()
677
{
678
    m_ui->qmlDebuggingLibraryCheckBox->setEnabled(m_step->isQmlDebuggingLibrarySupported());
679
    m_ui->debuggingLibraryLabel->setText(tr("Enable QML debugging:"));
680
681
682
683
684
685

    QString warningText;

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

688
689
    m_ui->qmlDebuggingWarningText->setText(warningText);
    m_ui->qmlDebuggingWarningIcon->setVisible(!warningText.isEmpty());
690
691
}

692
693
void QMakeStepConfigWidget::updateEffectiveQMakeCall()
{
Tobias Hunger's avatar
Tobias Hunger committed
694
    QtSupport::BaseQtVersion *qtVersion = QtSupport::QtKitInformation::qtVersion(m_step->target()->kit());
695
    QString program = tr("<No Qt version>");
dt's avatar
dt committed
696
    if (qtVersion)
697
        program = qtVersion->qmakeCommand().toFileInfo().fileName();
698
    m_ui->qmakeArgumentsEdit->setPlainText(program + QLatin1Char(' ') + m_step->allArguments());
con's avatar
con committed
699
700
}

701
702
703
704
705
706
707
708
void QMakeStepConfigWidget::recompileMessageBoxFinished(int button)
{
    if (button == QMessageBox::Yes) {
        Qt4BuildConfiguration *bc = m_step->qt4BuildConfiguration();
        if (!bc)
            return;

        QList<ProjectExplorer::BuildStepList *> stepLists;
709
710
        const Core::Id clean = Core::Id(ProjectExplorer::Constants::BUILDSTEPS_CLEAN);
        const Core::Id build = Core::Id(ProjectExplorer::Constants::BUILDSTEPS_BUILD);
711
        stepLists << bc->stepList(clean) << bc->stepList(build);
712
        ProjectExplorer::BuildManager *bm = ProjectExplorerPlugin::instance()->buildManager();
713
714
        bm->buildLists(stepLists, QStringList() << ProjectExplorerPlugin::displayNameForStepId(clean)
                       << ProjectExplorerPlugin::displayNameForStepId(build));
715
716
717
    }
}

718
719
720
721
722
723
724
725
void QMakeStepConfigWidget::setSummaryText(const QString &text)
{
    if (text == m_summaryText)
        return;
    m_summaryText = text;
    emit updateSummary();
}

dt's avatar
dt committed
726
727
728
729
////
// QMakeStepFactory
////

730
731
QMakeStepFactory::QMakeStepFactory(QObject *parent) :
    ProjectExplorer::IBuildStepFactory(parent)
dt's avatar
dt committed
732
733
734
735
736
737
738
{
}

QMakeStepFactory::~QMakeStepFactory()
{
}

739
bool QMakeStepFactory::canCreate(BuildStepList *parent, const Core::Id id) const
dt's avatar
dt committed
740
{
741
    if (parent->id() != ProjectExplorer::Constants::BUILDSTEPS_BUILD)
742
        return false;
Tobias Hunger's avatar
Tobias Hunger committed
743
    if (!qobject_cast<Qt4BuildConfiguration *>(parent->parent()))
744
        return false;
745
    return id == QMAKE_BS_ID;
dt's avatar
dt committed
746
747
}

748
ProjectExplorer::BuildStep *QMakeStepFactory::create(BuildStepList *parent, const Core::Id id)
dt's avatar
dt committed
749
{
Tobias Hunger's avatar
Tobias Hunger committed
750
    if (!canCreate(parent, id))
751
        return 0;
Tobias Hunger's avatar
Tobias Hunger committed
752
    return new QMakeStep(parent);
753
754
}

Tobias Hunger's avatar
Tobias Hunger committed
755
bool QMakeStepFactory::canClone(BuildStepList *parent, BuildStep *source) const
756
{
Tobias Hunger's avatar
Tobias Hunger committed
757
    return canCreate(parent, source->id());
dt's avatar
dt committed
758
759
}

Tobias Hunger's avatar
Tobias Hunger committed
760
ProjectExplorer::BuildStep *QMakeStepFactory::clone(BuildStepList *parent, ProjectExplorer::BuildStep *source)
dt's avatar
dt committed
761
{
Tobias Hunger's avatar
Tobias Hunger committed
762
    if (!canClone(parent, source))
763
        return 0;
Tobias Hunger's avatar
Tobias Hunger committed
764
    return new QMakeStep(parent, qobject_cast<QMakeStep *>(source));
dt's avatar
dt committed
765
766
}

Tobias Hunger's avatar
Tobias Hunger committed
767
bool QMakeStepFactory::canRestore(BuildStepList *parent, const QVariantMap &map) const
768
{
769
    return canCreate(parent, ProjectExplorer::idFromMap(map));
770
771
}

Tobias Hunger's avatar
Tobias Hunger committed
772
ProjectExplorer::BuildStep *QMakeStepFactory::restore(BuildStepList *parent, const QVariantMap &map)
dt's avatar
dt committed
773
{
Tobias Hunger's avatar
Tobias Hunger committed
774
    if (!canRestore(parent, map))
775
        return 0;
Tobias Hunger's avatar
Tobias Hunger committed
776
    QMakeStep *bs = new QMakeStep(parent);
777
778
779
780
    if (bs->fromMap(map))
        return bs;
    delete bs;
    return 0;
dt's avatar
dt committed
781
782
}

783
QList<Core::Id> QMakeStepFactory::availableCreationIds(ProjectExplorer::BuildStepList *parent) const
784
{
785
    if (parent->id() == ProjectExplorer::Constants::BUILDSTEPS_BUILD)
Tobias Hunger's avatar
Tobias Hunger committed
786
        if (Qt4BuildConfiguration *bc = qobject_cast<Qt4BuildConfiguration *>(parent->parent()))
dt's avatar