qmakestep.cpp 26.3 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
**
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"
45
#include "ui_showbuildlog.h"
con's avatar
con committed
46

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

157 158
    arguments << moreArguments();

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

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

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

202 203 204 205 206 207 208

    return arguments;
}

QStringList QMakeStep::moreArgumentsAfter()
{
    Qt4BuildConfiguration *bc = qt4BuildConfiguration();
dt's avatar
dt committed
209
    if (bc->qtVersion() && !bc->qtVersion()->supportsShadowBuilds()) {
210 211 212 213 214
        // 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
215 216 217 218 219
        return QStringList() << QLatin1String("-after")
                             << QLatin1String("OBJECTS_DIR=obj")
                             << QLatin1String("MOC_DIR=moc")
                             << QLatin1String("UI_DIR=ui")
                             << QLatin1String("RCC_DIR=rcc");
220
    }
221
    return QStringList();
con's avatar
con committed
222 223
}

224
bool QMakeStep::init()
con's avatar
con committed
225
{
dt's avatar
dt committed
226
    Qt4BuildConfiguration *qt4bc = qt4BuildConfiguration();
227
    const QtSupport::BaseQtVersion *qtVersion = qt4bc->qtVersion();
dt's avatar
dt committed
228 229 230

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

232
    QString args = allArguments();
233
    QString workingDirectory;
234

235 236 237 238
    if (qt4bc->subNodeBuild())
        workingDirectory = qt4bc->subNodeBuild()->buildDir();
    else
        workingDirectory = qt4bc->buildDirectory();
con's avatar
con committed
239 240 241

    QString program = qtVersion->qmakeCommand();

242 243 244 245 246 247 248 249 250
    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()) {
251
        makefile.append("/");
252 253 254 255 256
        makefile.append(qt4bc->makefile());
    } else {
        makefile.append("/Makefile");
    }

257 258
    // Check whether we need to run qmake
    bool makefileOutDated = true;
259
    if (QFileInfo(makefile).exists()) {
260
        QString qmakePath = QtSupport::QtVersionManager::findQMakeBinaryFromMakefile(makefile);
261
        if (qtVersion->qmakeCommand() == qmakePath) {
262
            makefileOutDated = !qt4bc->compareToImportFrom(makefile);
dt's avatar
dt committed
263
        }
con's avatar
con committed
264 265
    }

266
    if (m_forced || makefileOutDated)
267
        m_needToRunQMake = true;
268
    m_forced = false;
con's avatar
con committed
269

270
    setEnabled(m_needToRunQMake);
271 272 273 274 275 276
    ProcessParameters *pp = processParameters();
    pp->setMacroExpander(qt4bc->macroExpander());
    pp->setWorkingDirectory(workingDirectory);
    pp->setCommand(program);
    pp->setArguments(args);
    pp->setEnvironment(qt4bc->environment());
277

Tobias Hunger's avatar
Tobias Hunger committed
278
    setOutputParser(new QMakeParser);
dt's avatar
dt committed
279

280
    Qt4ProFileNode *node = qt4bc->qt4Target()->qt4Project()->rootQt4ProjectNode();
dt's avatar
dt committed
281 282 283 284
    if (qt4bc->subNodeBuild())
        node = qt4bc->subNodeBuild();
    QString proFile = node->path();

285 286 287 288 289 290 291
    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
292
    m_scriptTemplate = node->projectType() == ScriptTemplate;
dt's avatar
dt committed
293

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

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

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

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

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

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
344
    return false;
con's avatar
con committed
345 346 347 348
}

void QMakeStep::processStartupFailed()
{
349
    m_needToRunQMake = true;
con's avatar
con committed
350 351 352
    AbstractProcessStep::processStartupFailed();
}

353
bool QMakeStep::processSucceeded(int exitCode, QProcess::ExitStatus status)
con's avatar
con committed
354
{
355
    bool result = AbstractProcessStep::processSucceeded(exitCode, status);
con's avatar
con committed
356
    if (!result)
357
        m_needToRunQMake = true;
358
    qt4BuildConfiguration()->emitBuildDirectoryInitialized();
con's avatar
con committed
359 360 361
    return result;
}

362
void QMakeStep::setUserArguments(const QString &arguments)
363
{
364 365
    if (m_userArgs == arguments)
        return;
dt's avatar
dt committed
366
    m_userArgs = arguments;
367

368
    emit userArgumentsChanged();
369 370

    qt4BuildConfiguration()->emitQMakeBuildConfigurationChanged();
371
    qt4BuildConfiguration()->emitProFileEvaluateNeeded();
372 373
}

374 375
bool QMakeStep::isQmlDebuggingLibrarySupported(QString *reason) const
{
376
    QtSupport::BaseQtVersion *version = qt4BuildConfiguration()->qtVersion();
dt's avatar
dt committed
377 378 379 380 381
    if (!version) {
        if (reason)
            *reason = tr("No Qt version.");
        return false;
    }
382 383

    if (!version->needsQmlDebuggingLibrary() || version->hasQmlDebuggingLibrary())
384 385
        return true;

dt's avatar
dt committed
386
    if (!version->qtAbis().isEmpty()) {
387
        ProjectExplorer::Abi abi = qt4BuildConfiguration()->qtVersion()->qtAbis().first();
388
        if (abi.osFlavor() == ProjectExplorer::Abi::MaemoLinuxFlavor) {
389
            if (reason)
Friedemann Kleint's avatar
Friedemann Kleint committed
390
                reason->clear();
391 392 393 394 395
//               *reason = tr("Qml debugging on device not yet supported.");
            return false;
        }
    }

dt's avatar
dt committed
396
    if (!version->isValid()) {
397 398 399 400 401
        if (reason)
            *reason = tr("Invalid Qt version.");
        return false;
    }

402
    if (version->qtVersion() < QtSupport::QtVersionNumber(4, 7, 1)) {
403 404 405 406 407 408
        if (reason)
            *reason = tr("Requires Qt 4.7.1 or newer.");
        return false;
    }

    if (reason)
409
        *reason = tr("Library not available. <a href='compile'>Compile...</a>");
410 411 412 413 414 415

    return false;
}

bool QMakeStep::linkQmlDebuggingLibrary() const
{
416 417 418 419 420
    if (m_linkQmlDebuggingLibrary == DoLink)
        return true;
    if (m_linkQmlDebuggingLibrary == DoNotLink)
        return false;
    return (qt4BuildConfiguration()->buildType() & BuildConfiguration::Debug);
421 422 423 424
}

void QMakeStep::setLinkQmlDebuggingLibrary(bool enable)
{
425 426
    if ((enable && (m_linkQmlDebuggingLibrary == DoLink))
            || (!enable && (m_linkQmlDebuggingLibrary == DoNotLink)))
427
        return;
428
    m_linkQmlDebuggingLibrary = enable ? DoLink : DoNotLink;
429 430 431 432

    emit linkQmlDebuggingLibraryChanged();

    qt4BuildConfiguration()->emitQMakeBuildConfigurationChanged();
433
    qt4BuildConfiguration()->emitProFileEvaluateNeeded();
434 435
}

436 437 438
QStringList QMakeStep::parserArguments()
{
    QStringList result;
439 440 441
    for (Utils::QtcProcess::ConstArgIterator ait(allArguments()); ait.next(); )
        if (ait.isSimple())
            result << ait.value();
442
    return result;
443 444
}

445
QString QMakeStep::userArguments()
446
{
dt's avatar
dt committed
447
    return m_userArgs;
448 449
}

450 451 452 453 454 455 456 457 458 459 460
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();
        }
    }

461 462 463 464 465
    QtSupport::BaseQtVersion *version = bc->qtVersion();
    // We do not know which abi the Qt version has, so let's stick with the defaults
    if (version && version->qtAbis().count() == 1 && version->qtAbis().first().isNull())
        return QString();

466
    const QString tcSpec = bc->toolChain() ? bc->toolChain()->mkspec() : QString();
467
    if (!version)
468
        return tcSpec;
469
    if (!tcSpec.isEmpty() && version->hasMkspec(tcSpec))
470
        return tcSpec;
471
    return version->mkspec();
472 473
}

474
QVariantMap QMakeStep::toMap() const
475
{
476 477
    QVariantMap map(AbstractProcessStep::toMap());
    map.insert(QLatin1String(QMAKE_ARGUMENTS_KEY), m_userArgs);
478 479
    map.insert(QLatin1String(QMAKE_QMLDEBUGLIBAUTO_KEY), m_linkQmlDebuggingLibrary == DebugLink);
    map.insert(QLatin1String(QMAKE_QMLDEBUGLIB_KEY), m_linkQmlDebuggingLibrary == DoLink);
480
    map.insert(QLatin1String(QMAKE_FORCED_KEY), m_forced);
481
    return map;
482 483
}

484
bool QMakeStep::fromMap(const QVariantMap &map)
485
{
486
    m_userArgs = map.value(QLatin1String(QMAKE_ARGUMENTS_KEY)).toString();
487
    m_forced = map.value(QLatin1String(QMAKE_FORCED_KEY), false).toBool();
488 489 490 491 492 493 494 495 496 497
    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;
        }
    }

498
    return BuildStep::fromMap(map);
499 500
}

501 502 503 504
////
// QMakeStepConfigWidget
////

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

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

    qmakeBuildConfigChanged();

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

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

542 543 544 545 546
QMakeStepConfigWidget::~QMakeStepConfigWidget()
{
    delete m_ui;
}

dt's avatar
dt committed
547 548 549 550 551
QString QMakeStepConfigWidget::summaryText() const
{
    return m_summaryText;
}

552 553 554 555 556
QString QMakeStepConfigWidget::additionalSummaryText() const
{
    return m_additionalSummaryText;
}

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

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

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

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

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

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

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

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

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

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

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

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

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

    updateSummaryLabel();
    updateEffectiveQMakeCall();
647
    updateQmlDebuggingOption();
648 649 650 651 652 653 654 655 656 657


    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();
658 659 660 661
}

void QMakeStepConfigWidget::buildQmlDebuggingHelper()
{
662
    QtSupport::BaseQtVersion *version = m_step->qt4BuildConfiguration()->qtVersion();
dt's avatar
dt committed
663 664
    if (!version)
        return;
665

666
    QtSupport::DebuggingHelperBuildTask *buildTask =
667 668
            new QtSupport::DebuggingHelperBuildTask(version, m_step->qt4BuildConfiguration()->toolChain(),
                                                    QtSupport::DebuggingHelperBuildTask::QmlDebugging);
669

670 671 672
    // pop up Application Output on error
    buildTask->showOutputOnError(true);

673
    QFuture<void> task = QtConcurrent::run(&QtSupport::DebuggingHelperBuildTask::run, buildTask);
674 675 676 677 678
    const QString taskName = tr("Building helpers");
    Core::ICore::instance()->progressManager()->addTask(task, taskName,
                                                        QLatin1String("Qt4ProjectManager::BuildHelpers"));
}

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

693 694 695 696 697 698 699 700 701
    ToolChain *tc = qt4bc->toolChain();
    if (!tc)
        return;

    QString tcSpec = tc->mkspec();
    if (!tcSpec.isEmpty() && tcSpec != m_step->mkspec())
        setAdditionalSummaryText(tr("<b>Warning:</b> The tool chain suggested \"%1\" as mkspec.").arg(tcSpec));
    else
        setAdditionalSummaryText(QString());
702 703
}

704
void QMakeStepConfigWidget::updateQmlDebuggingOption()
705
{
706
    m_ui->qmlDebuggingLibraryCheckBox->setEnabled(m_step->isQmlDebuggingLibrarySupported());
707

708
    QtSupport::BaseQtVersion *qtVersion = m_step->qt4BuildConfiguration()->qtVersion();
709
    m_ui->debuggingLibraryLabel->setText(tr("Enable QML debugging:"));
710 711 712 713 714 715

    QString warningText;

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

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

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

732 733 734 735 736 737 738 739 740 741 742 743 744 745
void QMakeStepConfigWidget::recompileMessageBoxFinished(int button)
{
    if (button == QMessageBox::Yes) {
        Qt4BuildConfiguration *bc = m_step->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);
    }
}

746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761
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
762 763 764 765
////
// QMakeStepFactory
////

766 767
QMakeStepFactory::QMakeStepFactory(QObject *parent) :
    ProjectExplorer::IBuildStepFactory(parent)
dt's avatar
dt committed
768 769 770 771 772 773 774
{
}

QMakeStepFactory::~QMakeStepFactory()
{
}

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

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

Tobias Hunger's avatar
Tobias Hunger committed
791
bool QMakeStepFactory::canClone(BuildStepList *parent, BuildStep *source) const
792
{
Tobias Hunger's avatar
Tobias Hunger committed
793
    return canCreate(parent, source->id());
dt's avatar
dt committed
794 795
}

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

Tobias Hunger's avatar
Tobias Hunger committed
803
bool QMakeStepFactory::canRestore(BuildStepList *parent, const QVariantMap &map) const
804 805
{
    QString id(ProjectExplorer::idFromMap(map));
Tobias Hunger's avatar
Tobias Hunger committed
806
    return canCreate(parent, id);
807 808
}

Tobias Hunger's avatar
Tobias Hunger committed
809
ProjectExplorer::BuildStep *QMakeStepFactory::restore(BuildStepList *parent, const QVariantMap &map)
dt's avatar
dt committed
810
{
Tobias Hunger's avatar
Tobias Hunger committed
811
    if (!canRestore(parent,