qmakestep.cpp 24.9 KB
Newer Older
1
/**************************************************************************
con's avatar
con committed
2
3
4
**
** This file is part of Qt Creator
**
con's avatar
con committed
5
** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
con's avatar
con committed
6
**
hjk's avatar
hjk committed
7
** Contact: Nokia Corporation (info@qt.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
Tobias Hunger's avatar
Tobias Hunger committed
29
** Nokia at info@qt.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 "qt4basetargetfactory.h"
44
#include "ui_showbuildlog.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
63
#include <qtconcurrent/runextensions.h>
#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_linkQmlDebuggingLibrary(DebugLink)
con's avatar
con committed
83
{
84
    ctor();
con's avatar
con committed
85
86
}

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

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

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

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

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

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

138
139
    arguments << "-r";
    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
149
    if (!userProvidedMkspec)
        arguments << "-spec" << mkspec();
150

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

154
155
    arguments << moreArguments();

156
    QString args = Utils::QtcProcess::joinArgs(arguments);
157
    Utils::QtcProcess::addArgs(&args, m_userArgs);
158
    return args;
dt's avatar
dt committed
159
160
}

dt's avatar
dt committed
161
162
163
164
///
/// moreArguments,
/// -unix for Maemo
/// -after OBJECTS_DIR, MOC_DIR, UI_DIR, RCC_DIR
165
/// QMAKE_VAR_QMLJSDEBUGGER_PATH
dt's avatar
dt committed
166
167
168
169
QStringList QMakeStep::moreArguments()
{
    Qt4BuildConfiguration *bc = qt4BuildConfiguration();
    QStringList arguments;
170
#if defined(Q_OS_WIN) || defined(Q_OS_MAC)
171
    ProjectExplorer::ToolChain *tc = bc->toolChain();
Robert Loehning's avatar
Robert Loehning committed
172
173
    if (tc && (tc->targetAbi().osFlavor() == ProjectExplorer::Abi::HarmattanLinuxFlavor
               || tc->targetAbi().osFlavor() == ProjectExplorer::Abi::MaemoLinuxFlavor))
ck's avatar
ck committed
174
175
        arguments << QLatin1String("-unix");
#endif
176

177
    if (linkQmlDebuggingLibrary() && bc->qtVersion()) {
178
179
180
        if (!bc->qtVersion()->needsQmlDebuggingLibrary()) {
            // This Qt version has the QML debugging services built in, however
            // they still need to be enabled at compile time
181
            arguments << QLatin1String(Constants::QMAKEVAR_DECLARATIVE_DEBUG);
182
183
184
185
186
187
188
189
190
191
192
        } 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;
            }
        }
193
194
    }

dt's avatar
dt committed
195
    if (bc->qtVersion() && !bc->qtVersion()->supportsShadowBuilds()) {
196
197
198
199
200
201
        // 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")
202
203
204
205
                  << QLatin1String("OBJECTS_DIR=obj")
                  << QLatin1String("MOC_DIR=moc")
                  << QLatin1String("UI_DIR=ui")
                  << QLatin1String("RCC_DIR=rcc");
206
    }
con's avatar
con committed
207
208
209
    return arguments;
}

210
bool QMakeStep::init()
con's avatar
con committed
211
{
dt's avatar
dt committed
212
    Qt4BuildConfiguration *qt4bc = qt4BuildConfiguration();
213
    const QtSupport::BaseQtVersion *qtVersion = qt4bc->qtVersion();
dt's avatar
dt committed
214
215
216

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

218
    QString args = allArguments();
219
    QString workingDirectory;
220

221
222
223
224
    if (qt4bc->subNodeBuild())
        workingDirectory = qt4bc->subNodeBuild()->buildDir();
    else
        workingDirectory = qt4bc->buildDirectory();
con's avatar
con committed
225
226
227

    QString program = qtVersion->qmakeCommand();

Tobias Hunger's avatar
Tobias Hunger committed
228
    // Check whether we need to run qmake
229
    m_needToRunQMake = true;
230
231
232
233
234
235
236
237
238
    QString makefile = workingDirectory;

    if (qt4bc->subNodeBuild()) {
        if (!qt4bc->subNodeBuild()->makefile().isEmpty()) {
            makefile.append(qt4bc->subNodeBuild()->makefile());
        } else {
            makefile.append("/Makefile");
        }
    } else if (!qt4bc->makefile().isEmpty()) {
239
        makefile.append("/");
240
241
242
243
244
245
        makefile.append(qt4bc->makefile());
    } else {
        makefile.append("/Makefile");
    }

    if (QFileInfo(makefile).exists()) {
246
        QString qmakePath = QtSupport::QtVersionManager::findQMakeBinaryFromMakefile(makefile);
247
        if (qtVersion->qmakeCommand() == qmakePath) {
248
            m_needToRunQMake = !qt4bc->compareToImportFrom(makefile);
dt's avatar
dt committed
249
        }
con's avatar
con committed
250
251
252
253
    }

    if (m_forced) {
        m_forced = false;
254
        m_needToRunQMake = true;
con's avatar
con committed
255
256
    }

257
    setEnabled(m_needToRunQMake);
258
259
260
261
262
263
    ProcessParameters *pp = processParameters();
    pp->setMacroExpander(qt4bc->macroExpander());
    pp->setWorkingDirectory(workingDirectory);
    pp->setCommand(program);
    pp->setArguments(args);
    pp->setEnvironment(qt4bc->environment());
264

Tobias Hunger's avatar
Tobias Hunger committed
265
    setOutputParser(new QMakeParser);
dt's avatar
dt committed
266

dt's avatar
dt committed
267
268
269
270
271
    Qt4ProFileNode *node = qt4bc->qt4Target()->qt4Project()->rootProjectNode();
    if (qt4bc->subNodeBuild())
        node = qt4bc->subNodeBuild();
    QString proFile = node->path();

272
273
274
275
276
277
278
    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
279
    m_scriptTemplate = node->projectType() == ScriptTemplate;
dt's avatar
dt committed
280

Tobias Hunger's avatar
Tobias Hunger committed
281
    return AbstractProcessStep::init();
con's avatar
con committed
282
283
284
285
}

void QMakeStep::run(QFutureInterface<bool> &fi)
{
dt's avatar
dt committed
286
    if (m_scriptTemplate) {
con's avatar
con committed
287
288
289
        fi.reportResult(true);
        return;
    }
290

291
    // Warn on common error conditions:
292
    bool canContinue = true;
dt's avatar
dt committed
293
    foreach (const ProjectExplorer::Task &t, m_tasks) {
294
295
296
297
298
        addTask(t);
        if (t.type == Task::Error)
            canContinue = false;
    }
    if (!canContinue) {
299
        emit addOutput(tr("Configuration is faulty, please check the Build Issues view for details."), BuildStep::MessageOutput);
300
301
        fi.reportResult(false);
        return;
302
303
    }

304
    if (!m_needToRunQMake) {
305
        emit addOutput(tr("Configuration unchanged, skipping qmake step."), BuildStep::MessageOutput);
con's avatar
con committed
306
307
308
        fi.reportResult(true);
        return;
    }
309

Tobias Hunger's avatar
Tobias Hunger committed
310
    AbstractProcessStep::run(fi);
con's avatar
con committed
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
}

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
330
    return false;
con's avatar
con committed
331
332
333
334
335
336
337
338
}

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

339
bool QMakeStep::processSucceeded(int exitCode, QProcess::ExitStatus status)
con's avatar
con committed
340
{
341
    bool result = AbstractProcessStep::processSucceeded(exitCode, status);
con's avatar
con committed
342
343
    if (!result)
        m_forced = true;
344
    qt4BuildConfiguration()->emitBuildDirectoryInitialized();
con's avatar
con committed
345
346
347
    return result;
}

348
void QMakeStep::setUserArguments(const QString &arguments)
349
{
350
351
    if (m_userArgs == arguments)
        return;
dt's avatar
dt committed
352
    m_userArgs = arguments;
353

354
    emit userArgumentsChanged();
355
356

    qt4BuildConfiguration()->emitQMakeBuildConfigurationChanged();
357
    qt4BuildConfiguration()->emitProFileEvaluateNeeded();
358
359
}

360
361
bool QMakeStep::isQmlDebuggingLibrarySupported(QString *reason) const
{
362
    QtSupport::BaseQtVersion *version = qt4BuildConfiguration()->qtVersion();
dt's avatar
dt committed
363
364
365
366
367
    if (!version) {
        if (reason)
            *reason = tr("No Qt version.");
        return false;
    }
368
369

    if (!version->needsQmlDebuggingLibrary() || version->hasQmlDebuggingLibrary())
370
371
        return true;

dt's avatar
dt committed
372
    if (!version->qtAbis().isEmpty()) {
373
        ProjectExplorer::Abi abi = qt4BuildConfiguration()->qtVersion()->qtAbis().first();
374
        if (abi.osFlavor() == ProjectExplorer::Abi::MaemoLinuxFlavor) {
375
            if (reason)
Friedemann Kleint's avatar
Friedemann Kleint committed
376
                reason->clear();
377
378
379
380
381
//               *reason = tr("Qml debugging on device not yet supported.");
            return false;
        }
    }

dt's avatar
dt committed
382
    if (!version->isValid()) {
383
384
385
386
387
        if (reason)
            *reason = tr("Invalid Qt version.");
        return false;
    }

388
    if (version->qtVersion() < QtSupport::QtVersionNumber(4, 7, 1)) {
389
390
391
392
393
394
        if (reason)
            *reason = tr("Requires Qt 4.7.1 or newer.");
        return false;
    }

    if (reason)
395
        *reason = tr("Library not available. <a href='compile'>Compile...</a>");
396
397
398
399
400
401

    return false;
}

bool QMakeStep::linkQmlDebuggingLibrary() const
{
402
403
404
405
406
    if (m_linkQmlDebuggingLibrary == DoLink)
        return true;
    if (m_linkQmlDebuggingLibrary == DoNotLink)
        return false;
    return (qt4BuildConfiguration()->buildType() & BuildConfiguration::Debug);
407
408
409
410
}

void QMakeStep::setLinkQmlDebuggingLibrary(bool enable)
{
411
412
    if ((enable && (m_linkQmlDebuggingLibrary == DoLink))
            || (!enable && (m_linkQmlDebuggingLibrary == DoNotLink)))
413
        return;
414
    m_linkQmlDebuggingLibrary = enable ? DoLink : DoNotLink;
415
416
417
418

    emit linkQmlDebuggingLibraryChanged();

    qt4BuildConfiguration()->emitQMakeBuildConfigurationChanged();
419
    qt4BuildConfiguration()->emitProFileEvaluateNeeded();
420

421
422
423
424
425
426
427
428
    Core::ICore * const core = Core::ICore::instance();
    QMessageBox *question = new QMessageBox(core->mainWindow());
    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();
429
430
}

431
432
433
QStringList QMakeStep::parserArguments()
{
    QStringList result;
434
435
436
    for (Utils::QtcProcess::ConstArgIterator ait(allArguments()); ait.next(); )
        if (ait.isSimple())
            result << ait.value();
437
    return result;
438
439
}

440
QString QMakeStep::userArguments()
441
{
dt's avatar
dt committed
442
    return m_userArgs;
443
444
}

445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
QString QMakeStep::mkspec()
{
    Qt4BuildConfiguration *bc = qt4BuildConfiguration();
    QString additionalArguments = m_userArgs;
    for (Utils::QtcProcess::ArgIterator ait(&additionalArguments); ait.next(); ) {
        if (ait.value() == QLatin1String("-spec")) {
            if (ait.next())
                return ait.value();
        }
    }

    const QString tcSpec = bc->toolChain() ? bc->toolChain()->mkspec() : QString();
    if (!bc->qtVersion())
        return tcSpec;
    if (!tcSpec.isEmpty() && bc->qtVersion()->hasMkspec(tcSpec))
        return tcSpec;
    return bc->qtVersion()->mkspec();
}

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

474
bool QMakeStep::fromMap(const QVariantMap &map)
475
{
476
    m_userArgs = map.value(QLatin1String(QMAKE_ARGUMENTS_KEY)).toString();
477
    m_forced = map.value(QLatin1String(QMAKE_FORCED_KEY), false).toBool();
478
479
480
481
482
483
484
485
486
487
    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;
        }
    }

488
    return BuildStep::fromMap(map);
489
490
}

491
492
493
494
495
496
497
498
499
500
501
502
503
504
void QMakeStep::recompileMessageBoxFinished(int button)
{
    if (button == QMessageBox::Yes) {
        Qt4BuildConfiguration *bc = qt4BuildConfiguration();
        if (!bc)
            return;

        QList<ProjectExplorer::BuildStepList *> stepLists;
        stepLists << bc->stepList(ProjectExplorer::Constants::BUILDSTEPS_CLEAN);
        stepLists << bc->stepList(ProjectExplorer::Constants::BUILDSTEPS_BUILD);
        ProjectExplorerPlugin::instance()->buildManager()->buildLists(stepLists);
    }
}

505
506
507
508
////
// QMakeStepConfigWidget
////

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

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

    qmakeBuildConfigChanged();

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

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

546
547
548
549
550
QMakeStepConfigWidget::~QMakeStepConfigWidget()
{
    delete m_ui;
}

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

556
557
558
559
560
QString QMakeStepConfigWidget::displayName() const
{
    return m_step->displayName();
}

561
void QMakeStepConfigWidget::qtVersionChanged()
562
{
563
    updateSummaryLabel();
dt's avatar
dt committed
564
    updateEffectiveQMakeCall();
565
    updateQmlDebuggingOption();
566
567
}

568
void QMakeStepConfigWidget::qtVersionsDumpUpdated(const QString &qmakeCommand)
569
{
570
    QtSupport::BaseQtVersion *version = m_step->qt4BuildConfiguration()->qtVersion();
571
572
    if (version && version->qmakeCommand() == qmakeCommand)
        qtVersionChanged();
573
574
}

575
void QMakeStepConfigWidget::qmakeBuildConfigChanged()
dt's avatar
dt committed
576
{
577
    Qt4BuildConfiguration *bc = m_step->qt4BuildConfiguration();
578
    bool debug = bc->qmakeBuildConfiguration() & QtSupport::BaseQtVersion::DebugBuild;
579
    m_ignoreChange = true;
580
    m_ui->buildConfigurationComboBox->setCurrentIndex(debug? 0 : 1);
581
582
583
584
    m_ignoreChange = false;
    updateSummaryLabel();
    updateEffectiveQMakeCall();
}
dt's avatar
dt committed
585

586
587
588
589
void QMakeStepConfigWidget::userArgumentsChanged()
{
    if (m_ignoreChange)
        return;
590
    m_ui->qmakeAdditonalArgumentsLineEdit->setText(m_step->userArguments());
591
592
    updateSummaryLabel();
    updateEffectiveQMakeCall();
dt's avatar
dt committed
593
594
}

595
596
597
598
void QMakeStepConfigWidget::linkQmlDebuggingLibraryChanged()
{
    if (m_ignoreChange)
        return;
599
    m_ui->qmlDebuggingLibraryCheckBox->setChecked(m_step->linkQmlDebuggingLibrary());
600
601
602

    updateSummaryLabel();
    updateEffectiveQMakeCall();
603
    updateQmlDebuggingOption();
604
605
}

606
void QMakeStepConfigWidget::qmakeArgumentsLineEdited()
con's avatar
con committed
607
{
608
    m_ignoreChange = true;
609
    m_step->setUserArguments(m_ui->qmakeAdditonalArgumentsLineEdit->text());
610
    m_ignoreChange = false;
611

612
    updateSummaryLabel();
613
    updateEffectiveQMakeCall();
con's avatar
con committed
614
615
}

616
void QMakeStepConfigWidget::buildConfigurationSelected()
con's avatar
con committed
617
{
618
619
620
    if (m_ignoreChange)
        return;
    Qt4BuildConfiguration *bc = m_step->qt4BuildConfiguration();
621
    QtSupport::BaseQtVersion::QmakeBuildConfigs buildConfiguration = bc->qmakeBuildConfiguration();
622
    if (m_ui->buildConfigurationComboBox->currentIndex() == 0) { // debug
dt_'s avatar
dt_ committed
623
624
625
        buildConfiguration = buildConfiguration | QtSupport::BaseQtVersion::DebugBuild;
    } else {
        buildConfiguration = buildConfiguration & ~QtSupport::BaseQtVersion::DebugBuild;
con's avatar
con committed
626
    }
627
628
629
    m_ignoreChange = true;
    bc->setQMakeBuildConfiguration(buildConfiguration);
    m_ignoreChange = false;
con's avatar
con committed
630

631
632
    updateSummaryLabel();
    updateEffectiveQMakeCall();
con's avatar
con committed
633
634
}

635
636
637
638
639
640
641
642
643
644
645
void QMakeStepConfigWidget::linkQmlDebuggingLibraryChecked(bool checked)
{
    if (m_ignoreChange)
        return;

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

    updateSummaryLabel();
    updateEffectiveQMakeCall();
646
    updateQmlDebuggingOption();
647
648
649
650
}

void QMakeStepConfigWidget::buildQmlDebuggingHelper()
{
651
    QtSupport::BaseQtVersion *version = m_step->qt4BuildConfiguration()->qtVersion();
dt's avatar
dt committed
652
653
    if (!version)
        return;
654

655
    QtSupport::DebuggingHelperBuildTask *buildTask =
656
657
            new QtSupport::DebuggingHelperBuildTask(version, m_step->qt4BuildConfiguration()->toolChain(),
                                                    QtSupport::DebuggingHelperBuildTask::QmlDebugging);
658

659
660
661
    // pop up Application Output on error
    buildTask->showOutputOnError(true);

662
    QFuture<void> task = QtConcurrent::run(&QtSupport::DebuggingHelperBuildTask::run, buildTask);
663
664
665
666
667
    const QString taskName = tr("Building helpers");
    Core::ICore::instance()->progressManager()->addTask(task, taskName,
                                                        QLatin1String("Qt4ProjectManager::BuildHelpers"));
}

668
void QMakeStepConfigWidget::updateSummaryLabel()
669
{
670
    Qt4BuildConfiguration *qt4bc = m_step->qt4BuildConfiguration();
671
    QtSupport::BaseQtVersion *qtVersion = qt4bc->qtVersion();
672
    if (!qtVersion) {
Friedemann Kleint's avatar
Friedemann Kleint committed
673
        m_summaryText = tr("<b>qmake:</b> No Qt version set. Cannot run qmake.");
674
        emit updateSummary();
675
        return;
676
677
678
    }

    // We don't want the full path to the .pro file
679
    QString args = m_step->allArguments(true);
680
681
    // And we only use the .pro filename not the full path
    QString program = QFileInfo(qtVersion->qmakeCommand()).fileName();
682
    m_summaryText = tr("<b>qmake:</b> %1 %2").arg(program, args);
683
    emit updateSummary();
684

685
686
}

687
void QMakeStepConfigWidget::updateQmlDebuggingOption()
688
{
689
    m_ui->qmlDebuggingLibraryCheckBox->setEnabled(m_step->isQmlDebuggingLibrarySupported());
690

691
    QtSupport::BaseQtVersion *qtVersion = m_step->qt4BuildConfiguration()->qtVersion();
692
    if (!qtVersion || !qtVersion->needsQmlDebuggingLibrary())
693
        m_ui->debuggingLibraryLabel->setText(tr("Enable QML debugging:"));
694
    else
695
        m_ui->debuggingLibraryLabel->setText(tr("Link QML debugging library:"));
696
697
698
699
700
701

    QString warningText;

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

704
705
    m_ui->qmlDebuggingWarningText->setText(warningText);
    m_ui->qmlDebuggingWarningIcon->setVisible(!warningText.isEmpty());
706
707
}

708
709
void QMakeStepConfigWidget::updateEffectiveQMakeCall()
{
dt's avatar
dt committed
710
    Qt4BuildConfiguration *qt4bc = m_step->qt4BuildConfiguration();
711
    QtSupport::BaseQtVersion *qtVersion = qt4bc->qtVersion();
712
    QString program = tr("<No Qt version>");
dt's avatar
dt committed
713
714
    if (qtVersion)
        program = QFileInfo(qtVersion->qmakeCommand()).fileName();
715
    m_ui->qmakeArgumentsEdit->setPlainText(program + QLatin1Char(' ') + m_step->allArguments());
con's avatar
con committed
716
717
}

dt's avatar
dt committed
718
719
720
721
////
// QMakeStepFactory
////

722
723
QMakeStepFactory::QMakeStepFactory(QObject *parent) :
    ProjectExplorer::IBuildStepFactory(parent)
dt's avatar
dt committed
724
725
726
727
728
729
730
{
}

QMakeStepFactory::~QMakeStepFactory()
{
}

Tobias Hunger's avatar
Tobias Hunger committed
731
bool QMakeStepFactory::canCreate(BuildStepList *parent, const QString &id) const
dt's avatar
dt committed
732
{
Tobias Hunger's avatar
Tobias Hunger committed
733
    if (parent->id() != QLatin1String(ProjectExplorer::Constants::BUILDSTEPS_BUILD))
734
        return false;
Tobias Hunger's avatar
Tobias Hunger committed
735
    if (!qobject_cast<Qt4BuildConfiguration *>(parent->parent()))
736
737
        return false;
    return (id == QLatin1String(QMAKE_BS_ID));
dt's avatar
dt committed
738
739
}

Tobias Hunger's avatar
Tobias Hunger committed
740
ProjectExplorer::BuildStep *QMakeStepFactory::create(BuildStepList *parent, const QString &id)
dt's avatar
dt committed
741
{
Tobias Hunger's avatar
Tobias Hunger committed
742
    if (!canCreate(parent, id))
743
        return 0;
Tobias Hunger's avatar
Tobias Hunger committed
744
    return new QMakeStep(parent);
745
746
}

Tobias Hunger's avatar
Tobias Hunger committed
747
bool QMakeStepFactory::canClone(BuildStepList *parent, BuildStep *source) const
748
{
Tobias Hunger's avatar
Tobias Hunger committed
749
    return canCreate(parent, source->id());
dt's avatar
dt committed
750
751
}

Tobias Hunger's avatar
Tobias Hunger committed
752
ProjectExplorer::BuildStep *QMakeStepFactory::clone(BuildStepList *parent, ProjectExplorer::BuildStep *source)
dt's avatar
dt committed
753
{
Tobias Hunger's avatar
Tobias Hunger committed
754
    if (!canClone(parent, source))
755
        return 0;
Tobias Hunger's avatar
Tobias Hunger committed
756
    return new QMakeStep(parent, qobject_cast<QMakeStep *>(source));
dt's avatar
dt committed
757
758
}

Tobias Hunger's avatar
Tobias Hunger committed
759
bool QMakeStepFactory::canRestore(BuildStepList *parent, const QVariantMap &map) const
760
761
{
    QString id(ProjectExplorer::idFromMap(map));
Tobias Hunger's avatar
Tobias Hunger committed
762
    return canCreate(parent, id);
763
764
}

Tobias Hunger's avatar
Tobias Hunger committed
765
ProjectExplorer::BuildStep *QMakeStepFactory::restore(BuildStepList *parent, const QVariantMap &map)
dt's avatar
dt committed
766
{
Tobias Hunger's avatar
Tobias Hunger committed
767
    if (!canRestore(parent, map))
768
        return 0;
Tobias Hunger's avatar
Tobias Hunger committed
769
    QMakeStep *bs = new QMakeStep(parent);
770
771
772
773
    if (bs->fromMap(map))
        return bs;
    delete bs;
    return 0;
dt's avatar
dt committed
774
775
}

Tobias Hunger's avatar
Tobias Hunger committed
776
QStringList QMakeStepFactory::availableCreationIds(ProjectExplorer::BuildStepList *parent) const
777
{
Tobias Hunger's avatar
Tobias Hunger committed
778
779
    if (parent->id() == QLatin1String(ProjectExplorer::Constants::BUILDSTEPS_BUILD))
        if (Qt4BuildConfiguration *bc = qobject_cast<Qt4BuildConfiguration *>(parent->parent()))
780
781
            if (!bc->qmakeStep())
                return QStringList() << QLatin1String(QMAKE_BS_ID);
782
783
    return QStringList();
}
dt's avatar
dt committed
784

785
786
787
QString QMakeStepFactory::displayNameForId(const QString &id) const
{
    if (id == QLatin1String(QMAKE_BS_ID))
788
        return tr("qmake");
789
790
    return QString();
}