qtversionmanager.cpp 41.3 KB
Newer Older
1
/**************************************************************************
con's avatar
con committed
2 3 4
**
** This file is part of Qt Creator
**
5
** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
con's avatar
con committed
6
**
7
** Contact: Nokia Corporation (qt-info@nokia.com)
con's avatar
con committed
8
**
9
** Commercial Usage
10
**
11 12 13 14
** Licensees holding valid Qt Commercial licenses may use this file in
** accordance with the Qt Commercial License Agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Nokia.
15
**
16
** GNU Lesser General Public License Usage
17
**
18 19 20 21 22 23
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file.  Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24
**
25
** If you are unsure which license is appropriate for your use, please
26
** contact the sales department at http://www.qtsoftware.com/contact.
con's avatar
con committed
27
**
28
**************************************************************************/
hjk's avatar
hjk committed
29

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

32
#include "qt4projectmanagerconstants.h"
33
#include "profilereader.h"
con's avatar
con committed
34

35 36 37 38
#ifdef QTCREATOR_WITH_S60
#include "qt-s60/s60manager.h"
#endif

39 40 41
#include <projectexplorer/debugginghelper.h>
#include <projectexplorer/projectexplorer.h>
#include <projectexplorer/cesdkhandler.h>
42
#include <coreplugin/coreconstants.h>
43
#include <coreplugin/icore.h>
44
#include <coreplugin/modemanager.h>
45
#include <welcome/welcomemode.h>
46
#include <extensionsystem/pluginmanager.h>
con's avatar
con committed
47
#include <help/helpplugin.h>
hjk's avatar
hjk committed
48
#include <utils/qtcassert.h>
con's avatar
con committed
49

50

hjk's avatar
hjk committed
51
#include <QtCore/QProcess>
con's avatar
con committed
52 53
#include <QtCore/QSettings>
#include <QtCore/QTime>
54 55
#include <QtGui/QApplication>
#include <QtGui/QDesktopServices>
con's avatar
con committed
56

57 58 59 60
#ifdef Q_OS_WIN32
#include <windows.h>
#endif

61 62 63 64
using namespace Qt4ProjectManager;
using namespace Qt4ProjectManager::Internal;

using ProjectExplorer::DebuggingHelperLibrary;
con's avatar
con committed
65 66 67 68

static const char *QtVersionsSectionName = "QtVersions";
static const char *defaultQtVersionKey = "DefaultQtVersion";
static const char *newQtVersionsKey = "NewQtVersions";
69
static const char *PATH_AUTODETECTION_SOURCE = "PATH";
con's avatar
con committed
70

71
QtVersionManager *QtVersionManager::m_self = 0;
72

con's avatar
con committed
73 74 75
QtVersionManager::QtVersionManager()
    : m_emptyVersion(new QtVersion)
{
76
    m_self = this;
77
    QSettings *s = Core::ICore::instance()->settings();
con's avatar
con committed
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92
    m_defaultVersion = s->value(defaultQtVersionKey, 0).toInt();

    m_idcount = 1;
    int size = s->beginReadArray(QtVersionsSectionName);
    for (int i = 0; i < size; ++i) {
        s->setArrayIndex(i);
        // Find the right id
        // Either something saved or something generated
        // Note: This code assumes that either all ids are read from the settings
        // or generated on the fly.
        int id = s->value("Id", -1).toInt();
        if (id == -1)
            id = getUniqueId();
        else if (id > m_idcount)
            m_idcount = id;
93
        bool isAutodetected;
94 95
        QString autodetectionSource;
        if (s->contains("isAutodetected")) {
96
            isAutodetected = s->value("isAutodetected", false).toBool();
97 98
            autodetectionSource = s->value("autodetectionSource", QString()).toString();
        } else {// compatibility
99
            isAutodetected = s->value("IsSystemVersion", false).toBool();
100 101 102
            if (isAutodetected)
                autodetectionSource = QLatin1String(PATH_AUTODETECTION_SOURCE);
        }
con's avatar
con committed
103 104 105
        QtVersion *version = new QtVersion(s->value("Name").toString(),
                                           s->value("Path").toString(),
                                           id,
106 107
                                           isAutodetected,
                                           autodetectionSource);
con's avatar
con committed
108 109
        version->setMingwDirectory(s->value("MingwDirectory").toString());
        version->setMsvcVersion(s->value("msvcVersion").toString());
con's avatar
con committed
110 111 112
#ifdef QTCREATOR_WITH_S60
        version->setMwcDirectory(s->value("MwcDirectory").toString());
#endif
con's avatar
con committed
113 114 115 116 117 118 119 120 121 122
        m_versions.append(version);
    }
    s->endArray();
    updateUniqueIdToIndexMap();

    ++m_idcount;
    addNewVersionsFromInstaller();
    updateSystemVersion();

    writeVersionsIntoSettings();
123

con's avatar
con committed
124
    updateDocumentation();
125
    updateExamples();
con's avatar
con committed
126 127 128 129 130 131 132 133 134 135
}

QtVersionManager::~QtVersionManager()
{
    qDeleteAll(m_versions);
    m_versions.clear();
    delete m_emptyVersion;
    m_emptyVersion = 0;
}

136
QtVersionManager *QtVersionManager::instance()
137
{
138
    return m_self;
139 140
}

con's avatar
con committed
141 142 143 144
void QtVersionManager::addVersion(QtVersion *version)
{
    m_versions.append(version);
    emit qtVersionsChanged();
145
    writeVersionsIntoSettings();
con's avatar
con committed
146 147
}

148 149 150 151 152 153 154 155
void QtVersionManager::removeVersion(QtVersion *version)
{
    m_versions.removeAll(version);
    emit qtVersionsChanged();
    writeVersionsIntoSettings();
    delete version;
}

con's avatar
con committed
156 157
void QtVersionManager::updateDocumentation()
{
158 159
    Help::HelpManager *helpManager
        = ExtensionSystem::PluginManager::instance()->getObject<Help::HelpManager>();
dt's avatar
dt committed
160
    Q_ASSERT(helpManager);
con's avatar
con committed
161 162 163
    QStringList fileEndings = QStringList() << "/qch/qt.qch" << "/qch/qmake.qch" << "/qch/designer.qch";
    QStringList files;
    foreach (QtVersion *version, m_versions) {
164
        QString docPath = version->documentationPath();
con's avatar
con committed
165 166 167 168 169 170
        foreach (const QString &fileEnding, fileEndings)
            files << docPath+fileEnding;
    }
    helpManager->registerDocumentation(files);
}

171 172 173 174 175 176 177 178 179 180
void QtVersionManager::updateExamples()
{
    QList<QtVersion *> versions;
    versions.append(currentQtVersion());
    versions.append(m_versions);

    QString examplesPath;
    QString docPath;
    QString demosPath;
    QtVersion *version = 0;
181
    // try to find a version which has both, demos and examples, starting with default Qt
182 183 184 185 186
    foreach (version, versions) {
        if (version->hasExamples())
            examplesPath = version->examplesPath();
        if (version->hasDemos())
            demosPath = version->demosPath();
187
        if (!examplesPath.isEmpty() && !demosPath.isEmpty()) {
188 189 190
            if (Welcome::WelcomeMode *welcomeMode = qobject_cast<Welcome::WelcomeMode*>
                    (Core::ICore::instance()->modeManager()->mode(Core::Constants::MODE_WELCOME)))
                welcomeMode->updateExamples(examplesPath, demosPath, version->sourcePath());
191 192 193 194 195
            return;
        }
    }
}

con's avatar
con committed
196 197 198 199 200 201 202 203
int QtVersionManager::getUniqueId()
{
    return m_idcount++;
}

void QtVersionManager::updateUniqueIdToIndexMap()
{
    m_uniqueIdToIndex.clear();
hjk's avatar
hjk committed
204
    for (int i = 0; i < m_versions.size(); ++i)
con's avatar
con committed
205 206 207 208 209
        m_uniqueIdToIndex.insert(m_versions.at(i)->uniqueId(), i);
}

void QtVersionManager::writeVersionsIntoSettings()
{
210
    QSettings *s = Core::ICore::instance()->settings();
con's avatar
con committed
211
    s->setValue(defaultQtVersionKey, m_defaultVersion);
212
    s->beginWriteArray(QtVersionsSectionName);
con's avatar
con committed
213
    for (int i = 0; i < m_versions.size(); ++i) {
214
        const QtVersion *version = m_versions.at(i);
con's avatar
con committed
215
        s->setArrayIndex(i);
216 217 218 219 220 221 222 223
        s->setValue("Name", version->name());
        s->setValue("Path", version->path());
        s->setValue("Id", version->uniqueId());
        s->setValue("MingwDirectory", version->mingwDirectory());
        s->setValue("msvcVersion", version->msvcVersion());
        s->setValue("isAutodetected", version->isAutodetected());
        if (version->isAutodetected())
            s->setValue("autodetectionSource", version->autodetectionSource());
con's avatar
con committed
224 225 226
#ifdef QTCREATOR_WITH_S60
        s->setValue("MwcDirectory", version->mwcDirectory());
#endif
con's avatar
con committed
227 228 229 230 231 232 233 234 235 236 237 238 239 240 241
    }
    s->endArray();
}

QList<QtVersion* > QtVersionManager::versions() const
{
    return m_versions;
}

QtVersion *QtVersionManager::version(int id) const
{
    int pos = m_uniqueIdToIndex.value(id, -1);
    if (pos != -1)
        return m_versions.at(pos);

hjk's avatar
hjk committed
242
    if (m_defaultVersion < m_versions.count())
con's avatar
con committed
243 244 245 246 247 248 249 250 251 252 253
        return m_versions.at(m_defaultVersion);
    else
        return m_emptyVersion;
}

void QtVersionManager::addNewVersionsFromInstaller()
{
    // Add new versions which may have been installed by the WB installer in the form:
    // NewQtVersions="qt 4.3.2=c:\\qt\\qt432;qt embedded=c:\\qtembedded;"
    // or NewQtVersions="qt 4.3.2=c:\\qt\\qt432=c:\\qtcreator\\mingw\\=prependToPath;
    // Duplicate entries are not added, the first new version is set as default.
254
    QSettings *settings = Core::ICore::instance()->settings();
255 256 257

    if (!settings->contains(newQtVersionsKey) &&
        !settings->contains(QLatin1String("Installer/")+newQtVersionsKey))
con's avatar
con committed
258 259 260 261 262
        return;

//    qDebug()<<"QtVersionManager::addNewVersionsFromInstaller()";

    QString newVersionsValue = settings->value(newQtVersionsKey).toString();
263 264 265
    if (newVersionsValue.isEmpty())
        newVersionsValue = settings->value(QLatin1String("Installer/")+newQtVersionsKey).toString();

con's avatar
con committed
266 267 268 269
    QStringList newVersionsList = newVersionsValue.split(';', QString::SkipEmptyParts);
    bool defaultVersionWasReset = false;
    foreach (QString newVersion, newVersionsList) {
        QStringList newVersionData = newVersion.split('=');
hjk's avatar
hjk committed
270
        if (newVersionData.count()>=2) {
con's avatar
con committed
271 272
            if (QDir(newVersionData[1]).exists()) {
                QtVersion *version = new QtVersion(newVersionData[0], newVersionData[1], m_idcount++ );
hjk's avatar
hjk committed
273
                if (newVersionData.count() >= 3)
con's avatar
con committed
274 275 276 277
                    version->setMingwDirectory(newVersionData[2]);

                bool versionWasAlreadyInList = false;
                foreach(const QtVersion * const it, m_versions) {
hjk's avatar
hjk committed
278
                    if (QDir(version->path()).canonicalPath() == QDir(it->path()).canonicalPath()) {
con's avatar
con committed
279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297
                        versionWasAlreadyInList = true;
                        break;
                    }
                }

                if (!versionWasAlreadyInList) {
                    m_versions.append(version);
                } else {
                    // clean up
                    delete version;
                }
                if (!defaultVersionWasReset) {
                    m_defaultVersion = versionWasAlreadyInList? m_defaultVersion : m_versions.count() - 1;
                    defaultVersionWasReset = true;
                }
            }
        }
    }
    settings->remove(newQtVersionsKey);
298
    settings->remove(QLatin1String("Installer/")+newQtVersionsKey);
con's avatar
con committed
299 300 301 302 303 304
    updateUniqueIdToIndexMap();
}

void QtVersionManager::updateSystemVersion()
{
    bool haveSystemVersion = false;
305
    QString systemQMakePath = DebuggingHelperLibrary::findSystemQt(ProjectExplorer::Environment::systemEnvironment());
306 307 308 309 310 311 312 313 314
    QString systemQtPath;
    if (systemQMakePath.isNull()) {
        systemQtPath = tr("<not found>");
    } else {
        QDir dir(QFileInfo(systemQMakePath).absoluteDir());
        dir.cdUp();
        systemQtPath = dir.absolutePath();
    }

con's avatar
con committed
315
    foreach (QtVersion *version, m_versions) {
316 317
        if (version->isAutodetected()
            && version->autodetectionSource() == PATH_AUTODETECTION_SOURCE) {
318
            version->setPath(systemQtPath);
319
            version->setName(tr("Qt in PATH"));
con's avatar
con committed
320 321 322 323 324
            haveSystemVersion = true;
        }
    }
    if (haveSystemVersion)
        return;
325
    QtVersion *version = new QtVersion(tr("Qt in PATH"),
326
                                       systemQtPath,
con's avatar
con committed
327
                                       getUniqueId(),
328 329
                                       true,
                                       PATH_AUTODETECTION_SOURCE);
con's avatar
con committed
330 331 332 333 334 335 336 337
    m_versions.prepend(version);
    updateUniqueIdToIndexMap();
    if (m_versions.size() > 1) // we had other versions before adding system version
        ++m_defaultVersion;
}

QtVersion *QtVersionManager::currentQtVersion() const
{
hjk's avatar
hjk committed
338
    if (m_defaultVersion < m_versions.count())
con's avatar
con committed
339 340 341 342 343
        return m_versions.at(m_defaultVersion);
    else
        return m_emptyVersion;
}

344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369
void QtVersionManager::setNewQtVersions(QList<QtVersion *> newVersions, int newDefaultVersion)
{
    bool versionPathsChanged = m_versions.size() != newVersions.size();
    if (!versionPathsChanged) {
        for (int i = 0; i < m_versions.size(); ++i) {
            if (m_versions.at(i)->path() != newVersions.at(i)->path()) {
                versionPathsChanged = true;
                break;
            }
        }
    }
    qDeleteAll(m_versions);
    m_versions.clear();
    foreach(QtVersion *version, newVersions)
        m_versions.append(new QtVersion(*version));
    if (versionPathsChanged)
        updateDocumentation();
    updateUniqueIdToIndexMap();

    bool emitDefaultChanged = false;
    if (m_defaultVersion != newDefaultVersion) {
        m_defaultVersion = newDefaultVersion;
        emitDefaultChanged = true;
    }

    emit qtVersionsChanged();
370
    if (emitDefaultChanged) {
371
        emit defaultQtVersionChanged();
372
    }
373

374
    updateExamples();
375 376 377
    writeVersionsIntoSettings();
}

378

con's avatar
con committed
379 380 381 382 383

///
/// QtVersion
///

384 385
QtVersion::QtVersion(const QString &name, const QString &path, int id,
                     bool isAutodetected, const QString &autodetectionSource)
386
    : m_name(name),
387
    m_isAutodetected(isAutodetected),
388
    m_autodetectionSource(autodetectionSource),
389
    m_hasDebuggingHelper(false),
390 391 392
    m_notInstalled(false),
    m_defaultConfigIsDebug(true),
    m_defaultConfigIsDebugAndRelease(true),
393 394
    m_hasExamples(false),
    m_hasDemos(false),
395
    m_hasDocumentation(false)
con's avatar
con committed
396
{
hjk's avatar
hjk committed
397
    if (id == -1)
con's avatar
con committed
398 399 400
        m_id = getUniqueId();
    else
        m_id = id;
401
    setPath(path);
con's avatar
con committed
402 403
}

404 405
QtVersion::QtVersion(const QString &name, const QString &path,
                     bool isAutodetected, const QString &autodetectionSource)
con's avatar
con committed
406
    : m_name(name),
407 408
    m_isAutodetected(isAutodetected),
    m_autodetectionSource(autodetectionSource),
409 410
    m_hasDebuggingHelper(false),
    m_mkspecUpToDate(false),
411
    m_versionInfoUpToDate(false)
con's avatar
con committed
412 413
{
    m_id = getUniqueId();
414
    setPath(path);
con's avatar
con committed
415 416
}

417 418
QtVersion::~QtVersion()
{
419

420 421
}

con's avatar
con committed
422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442
QString QtVersion::name() const
{
    return m_name;
}

QString QtVersion::path() const
{
    return m_path;
}

QString QtVersion::sourcePath() const
{
    return m_sourcePath;
}

QString QtVersion::mkspec() const
{
    updateMkSpec();
    return m_mkspec;
}

dt's avatar
dt committed
443 444 445 446 447 448
QString QtVersion::mkspecPath() const
{
    updateMkSpec();
    return m_mkspecFullPath;
}

449 450 451 452 453 454
QString QtVersion::qtVersionString() const
{
    qmakeCommand();
    return m_qtVersionString;
}

con's avatar
con committed
455 456 457 458 459 460
QHash<QString,QString> QtVersion::versionInfo() const
{
    updateVersionInfo();
    return m_versionInfo;
}

461 462 463 464 465 466 467
QString QtVersion::qmakeCXX() const
{
    updateQMakeCXX();
    return m_qmakeCXX;
}


con's avatar
con committed
468 469 470 471 472 473 474 475 476 477 478
void QtVersion::setName(const QString &name)
{
    m_name = name;
}

void QtVersion::setPath(const QString &path)
{
    m_path = QDir::cleanPath(path);
    updateSourcePath();
    m_versionInfoUpToDate = false;
    m_mkspecUpToDate = false;
479 480
    m_designerCommand = m_linguistCommand = m_qmakeCommand = m_uicCommand = QString::null;
    // TODO do i need to optimize this?
481
    m_hasDebuggingHelper = !debuggingHelperLibrary().isEmpty();
482 483
    m_qmakeCXX = QString::null;
    m_qmakeCXXUpToDate = false;
con's avatar
con committed
484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532
}

void QtVersion::updateSourcePath()
{
    m_sourcePath = m_path;
    QFile qmakeCache(m_path + QLatin1String("/.qmake.cache"));
    if (qmakeCache.exists()) {
        qmakeCache.open(QIODevice::ReadOnly | QIODevice::Text);
        QTextStream stream(&qmakeCache);
        while (!stream.atEnd()) {
            QString line = stream.readLine().trimmed();
            if (line.startsWith(QLatin1String("QT_SOURCE_TREE"))) {
                m_sourcePath = line.split(QLatin1Char('=')).at(1).trimmed();
                if (m_sourcePath.startsWith(QLatin1String("$$quote("))) {
                    m_sourcePath.remove(0, 8);
                    m_sourcePath.chop(1);
                }
                break;
            }
        }
    }
}

// Returns the version that was used to build the project in that directory
// That is returns the directory
// To find out wheter we already have a qtversion for that directory call
// QtVersion *QtVersionManager::qtVersionForDirectory(const QString directory);
QString QtVersionManager::findQtVersionFromMakefile(const QString &directory)
{
    bool debugAdding = false;
    QFile makefile(directory + "/Makefile" );
    if (makefile.exists() && makefile.open(QFile::ReadOnly)) {
        QTextStream ts(&makefile);
        while (!ts.atEnd()) {
            QString line = ts.readLine();
            QRegExp r1("QMAKE\\s*=(.*)");
            if (r1.exactMatch(line)) {
                if (debugAdding)
                    qDebug()<<"#~~ QMAKE is:"<<r1.cap(1).trimmed();
                QFileInfo qmake(r1.cap(1).trimmed());
                QFileInfo binDir(qmake.absolutePath());
                QString qtDir = binDir.absolutePath();
                if (debugAdding)
                    qDebug() << "#~~ QtDir:"<<qtDir;
                return qtDir;
            }
        }
        makefile.close();
    }
533
    return QString::null;
con's avatar
con committed
534 535 536 537 538 539 540 541 542 543 544 545 546
}

QtVersion *QtVersionManager::qtVersionForDirectory(const QString &directory)
{
   foreach(QtVersion *v, versions()) {
        if (v->path() == directory) {
            return v;
            break;
        }
    }
   return 0;
}

547
void dumpQMakeAssignments(const QList<QMakeAssignment> &list)
con's avatar
con committed
548
{
549 550 551 552 553 554 555 556 557
    foreach(QMakeAssignment qa, list) {
        qDebug()<<qa.variable<<qa.op<<qa.value;
    }
}

// New code
QPair<QtVersion::QmakeBuildConfig, QStringList> QtVersionManager::scanMakeFile(const QString &directory, QtVersion::QmakeBuildConfig defaultBuildConfig)
{
    qDebug()<<"ScanMakeFile, the gory details:";
con's avatar
con committed
558
    QtVersion::QmakeBuildConfig result = QtVersion::NoBuild;
559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608
    QStringList result2;

    QString line = findQMakeLine(directory);
    if (!line.isEmpty()) {
        qDebug()<<"Found line"<<line;
        line = trimLine(line);
        qDebug()<<"Trimmed to"<<line;
        QStringList parts = splitLine(line);
        qDebug()<<"Splitted into"<<parts;
        QList<QMakeAssignment> assignments;
        QList<QMakeAssignment> afterAssignments;
        QStringList additionalArguments;
        parseParts(parts, &assignments, &afterAssignments, &additionalArguments);

        qDebug()<<"After parseParts";
        dumpQMakeAssignments(assignments);
        qDebug()<<"-after";
        dumpQMakeAssignments(afterAssignments);

        // Search in assignments for CONFIG(+=,-=,=)(debug,release,debug_and_release)
        // Also remove them from the list
        result = qmakeBuildConfigFromCmdArgs(&assignments, defaultBuildConfig);

        qDebug()<<"After qmakeBuildConfigFromCmdArgs";
        dumpQMakeAssignments(assignments);

        result2.append(additionalArguments);
        foreach(QMakeAssignment qa, assignments)
            result2.append(qa.variable + qa.op + qa.value);
        if (!afterAssignments.isEmpty()) {
            result2.append("-after");
            foreach(QMakeAssignment qa, afterAssignments)
                result2.append(qa.variable + qa.op + qa.value);
        }
    }

    // Dump the gathered information:
    qDebug()<<"\n\nDumping information from scanMakeFile";
    qDebug()<<"QMake CONFIG variable parsing";
    qDebug()<<"  "<< (result & QtVersion::NoBuild ? "No Build" : QString::number(int(result)));
    qDebug()<<"  "<< (result & QtVersion::DebugBuild ? "debug" : "release");
    qDebug()<<"  "<< (result & QtVersion::BuildAll ? "debug_and_release" : "no debug_and_release");
    qDebug()<<"\nAddtional Arguments";
    qDebug()<<result2;
    qDebug()<<"\n\n";
    return qMakePair(result, result2);
}

QString QtVersionManager::findQMakeLine(const QString &directory)
{
con's avatar
con committed
609 610 611 612 613
    QFile makefile(directory + "/Makefile" );
    if (makefile.exists() && makefile.open(QFile::ReadOnly)) {
        QTextStream ts(&makefile);
        while (!ts.atEnd()) {
            QString line = ts.readLine();
614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632
            if (line.startsWith("# Command:"))
                return line;
        }
    }
    return QString();
}

/// This function trims the "#Command /path/to/qmake" from the the line
QString QtVersionManager::trimLine(const QString line)
{

    // Actually the first space after #Command: /path/to/qmake
    int firstSpace = line.indexOf(" ", 11);
    return line.mid(firstSpace).trimmed();
}

QStringList QtVersionManager::splitLine(const QString &line)
{
    // Split on each " ", except on those which are escaped
633 634
    // On Unix also remove all escaping
    // On Windows also, but different escaping
635 636 637 638 639
    bool escape = false;
    QString currentWord;
    QStringList results;
    int length = line.length();
    for (int i=0; i<length; ++i) {
640 641 642 643 644 645 646 647 648 649
#ifdef Q_OS_WIN
        if (line.at(i) == '"') {
            escape = !escape;
        } else if (escape || line.at(i) != ' ') {
            currentWord += line.at(i);
        } else {
            results << currentWord;
            currentWord.clear();;
        }
#else
650 651 652 653 654 655 656 657 658 659 660
        if (escape) {
            currentWord += line.at(i);
            escape = false;
        } else if (line.at(i) == ' ') {
            results << currentWord;
            currentWord.clear();
        } else if (line.at(i) == '\\') {
            escape = true;
        } else {
            currentWord += line.at(i);
        }
661
#endif
662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737
    }
    return results;
}

void QtVersionManager::parseParts(const QStringList &parts, QList<QMakeAssignment> *assignments, QList<QMakeAssignment> *afterAssignments, QStringList *additionalArguments)
{
    QRegExp regExp("([^\\s\\+-]*)\\s*(\\+=|=|-=|~=)(.*)");
    bool after = false;
    bool ignoreNext = false;
    foreach (const QString &part, parts) {
        if (ignoreNext) {
            // Ignoring
            ignoreNext = false;
        } else if (part == "after") {
            after = true;
        } else if(part.contains('=')) {
            if (regExp.exactMatch(part)) {
                qDebug()<<regExp.cap(1)<<"|"<<regExp.cap(2)<<"|"<<regExp.cap(3);
                QMakeAssignment qa;
                qa.variable = regExp.cap(1);
                qa.op = regExp.cap(2);
                qa.value = regExp.cap(3).trimmed();
                if (after)
                    afterAssignments->append(qa);
                else
                    assignments->append(qa);
            } else {
                qDebug()<<"regexp did not match";
            }
        } else if (part == "-o") {
            ignoreNext = true;
        } else {
            qDebug()<<"Not parsed"<<part;
            additionalArguments->append(part);
        }
    }
#if defined(Q_OS_WIN32)
    additionalArguments->removeAll("-win32");
#elif defined(Q_OS_MAC)
    additionalArguments->removeAll("-macx");
#elif defined(Q_OS_QNX6)
    additionalArguments->removeAll("-qnx6");
#else
    additionalArguments->removeAll("-unix");
#endif
}


/// This function extracts all the CONFIG+=debug, CONFIG+=release
QtVersion::QmakeBuildConfig QtVersionManager::qmakeBuildConfigFromCmdArgs(QList<QMakeAssignment> *assignments, QtVersion::QmakeBuildConfig defaultBuildConfig)
{
    QtVersion::QmakeBuildConfig result = defaultBuildConfig;
    QList<QMakeAssignment> oldAssignments = *assignments;
    assignments->clear();
    foreach(QMakeAssignment qa, oldAssignments) {
        if (qa.variable == "CONFIG") {
            QStringList values = qa.value.split(' ');
            QStringList newValues;
            foreach(const QString &value, values) {
                if (value == "debug") {
                    if (qa.op == "+=")
                        result = QtVersion::QmakeBuildConfig(result  | QtVersion::DebugBuild);
                    else
                        result = QtVersion::QmakeBuildConfig(result  & ~QtVersion::DebugBuild);
                } else if (value == "release") {
                    if (qa.op == "+=")
                        result = QtVersion::QmakeBuildConfig(result & ~QtVersion::DebugBuild);
                    else
                        result = QtVersion::QmakeBuildConfig(result | QtVersion::DebugBuild);
                } else if (value == "debug_and_release") {
                    if (qa.op == "+=")
                        result = QtVersion::QmakeBuildConfig(result | QtVersion::BuildAll);
                    else
                        result = QtVersion::QmakeBuildConfig(result & ~QtVersion::BuildAll);
                } else {
                    newValues.append(value);
con's avatar
con committed
738
                }
739 740 741 742
                QMakeAssignment newQA = qa;
                newQA.value = newValues.join(" ");
                if (!newValues.isEmpty())
                    assignments->append(newQA);
con's avatar
con committed
743
            }
744 745
        } else {
            assignments->append(qa);
con's avatar
con committed
746 747 748 749 750 751 752 753 754 755 756 757
        }
    }
    return result;
}

void QtVersion::updateVersionInfo() const
{
    if (m_versionInfoUpToDate)
        return;
    // extract data from qmake executable
    m_versionInfo.clear();
    m_notInstalled = false;
758 759
    m_hasExamples = false;
    m_hasDocumentation = false;
con's avatar
con committed
760 761
    QFileInfo qmake(qmakeCommand());
    if (qmake.exists()) {
762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777
        static const char * const variables[] = {
             "QT_INSTALL_DATA",
             "QT_INSTALL_LIBS",
             "QT_INSTALL_HEADERS",
             "QT_INSTALL_DEMOS",
             "QT_INSTALL_EXAMPLES",
             "QT_INSTALL_CONFIGURATION",
             "QT_INSTALL_TRANSLATIONS",
             "QT_INSTALL_PLUGINS",
             "QT_INSTALL_BINS",
             "QT_INSTALL_DOCS",
             "QT_INSTALL_PREFIX"
        };
        QStringList args;
        for (uint i = 0; i < sizeof variables / sizeof variables[0]; ++i)
            args << "-query" << variables[i];
con's avatar
con committed
778 779 780 781 782 783 784 785 786
        QProcess process;
        process.start(qmake.absoluteFilePath(), args, QIODevice::ReadOnly);
        if (process.waitForFinished(2000)) {
            QByteArray output = process.readAllStandardOutput();
            QTextStream stream(&output);
            while (!stream.atEnd()) {
                QString line = stream.readLine();
                int index = line.indexOf(":");
                if (index != -1)
Joerg Bornemann's avatar
Joerg Bornemann committed
787
                    m_versionInfo.insert(line.left(index), QDir::fromNativeSeparators(line.mid(index+1)));
con's avatar
con committed
788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804
            }
        }

        if (m_versionInfo.contains("QT_INSTALL_DATA"))
            m_versionInfo.insert("QMAKE_MKSPECS", QDir::cleanPath(m_versionInfo.value("QT_INSTALL_DATA")+"/mkspecs"));

        // Now check for a qt that is configured with a prefix but not installed
        if (m_versionInfo.contains("QT_INSTALL_BINS")) {
            QFileInfo fi(m_versionInfo.value("QT_INSTALL_BINS"));
            if (!fi.exists())
                m_notInstalled = true;
        }
        if (m_versionInfo.contains("QT_INSTALL_HEADERS")){
            QFileInfo fi(m_versionInfo.value("QT_INSTALL_HEADERS"));
            if (!fi.exists())
                m_notInstalled = true;
        }
805 806 807 808 809 810 811 812 813 814 815 816 817 818 819
        if (m_versionInfo.contains("QT_INSTALL_DOCS")){
            QFileInfo fi(m_versionInfo.value("QT_INSTALL_DOCS"));
            if (fi.exists())
                m_hasDocumentation = true;
        }
        if (m_versionInfo.contains("QT_INSTALL_EXAMPLES")){
            QFileInfo fi(m_versionInfo.value("QT_INSTALL_EXAMPLES"));
            if (fi.exists())
                m_hasExamples = true;
        }
        if (m_versionInfo.contains("QT_INSTALL_DEMOS")){
            QFileInfo fi(m_versionInfo.value("QT_INSTALL_DEMOS"));
            if (fi.exists())
                m_hasDemos = true;
        }
con's avatar
con committed
820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836

        // Parse qconfigpri
        QString baseDir = m_versionInfo.contains("QT_INSTALL_DATA") ?
                           m_versionInfo.value("QT_INSTALL_DATA") :
                           m_path;
        QFile qconfigpri(baseDir + QLatin1String("/mkspecs/qconfig.pri"));
        if (qconfigpri.exists()) {
            qconfigpri.open(QIODevice::ReadOnly | QIODevice::Text);
            QTextStream stream(&qconfigpri);
            while (!stream.atEnd()) {
                QString line = stream.readLine().trimmed();
                if (line.startsWith(QLatin1String("CONFIG"))) {
                    m_defaultConfigIsDebugAndRelease = false;
                    QStringList values = line.split(QLatin1Char('=')).at(1).trimmed().split(" ");
                    foreach(const QString &value, values) {
                        if (value == "debug")
                            m_defaultConfigIsDebug = true;
hjk's avatar
hjk committed
837
                        else if (value == "release")
con's avatar
con committed
838
                            m_defaultConfigIsDebug = false;
hjk's avatar
hjk committed
839
                        else if (value == "build_all")
con's avatar
con committed
840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861
                            m_defaultConfigIsDebugAndRelease = true;
                    }
                }
            }
        }
    }
    m_versionInfoUpToDate = true;
}

bool QtVersion::isInstalled() const
{
    updateVersionInfo();
    return !m_notInstalled;
}

void QtVersion::updateMkSpec() const
{
    if (m_mkspecUpToDate)
        return;
    //qDebug()<<"Finding mkspec for"<<path();

    QString mkspec;
862 863 864 865 866 867
    // no .qmake.cache so look at the default mkspec
    QString mkspecPath = versionInfo().value("QMAKE_MKSPECS");
    if (mkspecPath.isEmpty())
        mkspecPath = path() + "/mkspecs/default";
    else
        mkspecPath = mkspecPath + "/default";
con's avatar
con committed
868 869
//        qDebug() << "default mkspec is located at" << mkspecPath;
#ifdef Q_OS_WIN
870 871 872 873 874 875 876 877
    QFile f2(mkspecPath + "/qmake.conf");
    if (f2.exists() && f2.open(QIODevice::ReadOnly)) {
        while (!f2.atEnd()) {
            QByteArray line = f2.readLine();
            if (line.startsWith("QMAKESPEC_ORIGINAL")) {
                const QList<QByteArray> &temp = line.split('=');
                if (temp.size() == 2) {
                    mkspec = temp.at(1).trimmed();
con's avatar
con committed
878
                }
879
                break;
con's avatar
con committed
880 881
            }
        }
882 883
        f2.close();
    }
con's avatar
con committed
884
#elif defined(Q_OS_MAC)
885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901
    QFile f2(mkspecPath + "/qmake.conf");
    if (f2.exists() && f2.open(QIODevice::ReadOnly)) {
        while (!f2.atEnd()) {
            QByteArray line = f2.readLine();
            if (line.startsWith("MAKEFILE_GENERATOR")) {
                const QList<QByteArray> &temp = line.split('=');
                if (temp.size() == 2) {
                    const QByteArray &value = temp.at(1);
                    if (value.contains("XCODE")) {
                        // we don't want to generate xcode projects...
//                      qDebug() << "default mkspec is xcode, falling back to g++";
                        mkspec = "macx-g++";
                    } else {
                        //resolve mkspec link
                        QFileInfo f3(mkspecPath);
                        if (f3.isSymLink()) {
                            mkspec = f3.symLinkTarget();
con's avatar
con committed
902 903 904
                        }
                    }
                }
905
                break;
con's avatar
con committed
906 907
            }
        }
908 909
        f2.close();
    }
con's avatar
con committed
910
#else
911 912 913 914
    QFileInfo f2(mkspecPath);
    if (f2.isSymLink()) {
        mkspec = f2.symLinkTarget();
    }
con's avatar
con committed
915 916
#endif

dt's avatar
dt committed
917 918
    m_mkspecFullPath = mkspec;
    int index = mkspec.lastIndexOf('/');
hjk's avatar
hjk committed
919
    if (index == -1)
con's avatar
con committed
920
        index = mkspec.lastIndexOf('\\');
Joerg Bornemann's avatar
Joerg Bornemann committed
921 922
    QString mkspecDir = QDir(m_path + "/mkspecs/").canonicalPath();
    if (index >= 0 && QDir(mkspec.left(index)).canonicalPath() == mkspecDir)
con's avatar
con committed
923 924 925 926 927 928 929 930 931 932 933 934 935 936
        mkspec = mkspec.mid(index+1).trimmed();

    m_mkspec = mkspec;
    m_mkspecUpToDate = true;
//    qDebug()<<"mkspec for "<<m_path<<" is "<<mkspec;
}

QString QtVersion::qmakeCommand() const
{
    // We can't use versionInfo QT_INSTALL_BINS here
    // because that functions calls us to find out the values for versionInfo
    if (!m_qmakeCommand.isNull())
        return m_qmakeCommand;

937
    QDir qtDir = path() + QLatin1String("/bin/");
938
    foreach (const QString &possibleCommand, DebuggingHelperLibrary::possibleQMakeCommands()) {
con's avatar
con committed
939 940 941
        QString s = qtDir.absoluteFilePath(possibleCommand);
        QFileInfo qmake(s);
        if (qmake.exists() && qmake.isExecutable()) {
942
            QString qtVersion = DebuggingHelperLibrary::qtVersionForQMake(qmake.absoluteFilePath());
943 944
            if (!qtVersion.isNull()) {
                m_qtVersionString = qtVersion;
con's avatar
con committed
945 946 947 948 949 950 951 952
                m_qmakeCommand = qmake.absoluteFilePath();
                return qmake.absoluteFilePath();
            }
        }
    }
    return QString::null;
}

953 954 955 956 957 958 959 960 961
void QtVersion::updateQMakeCXX() const
{
    if (m_qmakeCXXUpToDate)
        return;
    ProFileReader *reader = new ProFileReader();
    reader->setCumulative(false);
    reader->setParsePreAndPostFiles(false);
    reader->readProFile(mkspecPath() + "/qmake.conf");
    m_qmakeCXX = reader->value("QMAKE_CXX");
962

963 964 965 966
    delete reader;
    m_qmakeCXXUpToDate = true;
}

967
ProjectExplorer::ToolChain *QtVersion::createToolChain(ProjectExplorer::ToolChain::ToolChainType type) const
968
{
969
    ProjectExplorer::ToolChain *tempToolchain = 0;
con's avatar
con committed
970
    if (type == ProjectExplorer::ToolChain::MinGW) {
971 972 973 974 975
        QString qmake_cxx = qmakeCXX();
        ProjectExplorer::Environment env = ProjectExplorer::Environment::systemEnvironment();
        //addToEnvironment(env);
        env.prependOrSetPath(mingwDirectory()+"/bin");
        qmake_cxx = env.searchInPath(qmake_cxx);
con's avatar
con committed
976
        tempToolchain = ProjectExplorer::ToolChain::createMinGWToolChain(qmake_cxx, mingwDirectory());
977
        //qDebug()<<"Mingw ToolChain";
con's avatar
con committed
978
    } else if(type == ProjectExplorer::ToolChain::MSVC) {
con's avatar
con committed
979
        tempToolchain = ProjectExplorer::ToolChain::createMSVCToolChain(msvcVersion(), isQt64Bit());
980
        //qDebug()<<"MSVC ToolChain ("<<version->msvcVersion()<<")";
con's avatar
con committed
981 982
    } else if(type == ProjectExplorer::ToolChain::WINCE) {
        tempToolchain = ProjectExplorer::ToolChain::createWinCEToolChain(msvcVersion(), wincePlatform());
983
        //qDebug()<<"WinCE ToolChain ("<<version->msvcVersion()<<","<<version->wincePlatform()<<")";
con's avatar
con committed
984
    } else if(type == ProjectExplorer::ToolChain::GCC || type == ProjectExplorer::ToolChain::LinuxICC) {
985 986 987 988 989 990 991 992 993
        QString qmake_cxx = qmakeCXX();
        ProjectExplorer::Environment env = ProjectExplorer::Environment::systemEnvironment();
        //addToEnvironment(env);
        qmake_cxx = env.searchInPath(qmake_cxx);
        if (qmake_cxx.isEmpty()) {
            // macx-xcode mkspec resets the value of QMAKE_CXX.
            // Unfortunately, we need a valid QMAKE_CXX to configure the parser.
            qmake_cxx = QLatin1String("cc");
        }
con's avatar
con committed
994
        tempToolchain = ProjectExplorer::ToolChain::createGccToolChain(qmake_cxx);
995
        //qDebug()<<"GCC ToolChain ("<<qmake_cxx<<")";
996
#ifdef QTCREATOR_WITH_S60
con's avatar
con committed
997 998 999 1000
    } else if (type == ProjectExplorer::ToolChain::WINSCW) {
        tempToolchain = S60Manager::instance()->createWINSCWToolChain(this);
    } else if (type == ProjectExplorer::ToolChain::GCCE) {
        tempToolchain = S60Manager::instance()->createGCCEToolChain(this);
1001
#endif
1002
    } else {
con's avatar
con committed
1003
        qDebug()<<"Could not create ToolChain for"<<mkspec();
1004 1005
        qDebug()<<"Qt Creator doesn't know about the system includes, nor the systems defines.";
    }
1006
    return tempToolchain;
1007 1008 1009
}


1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020
QString QtVersion::findQtBinary(const QStringList &possibleCommands) const
{
    const QString qtdirbin = versionInfo().value(QLatin1String("QT_INSTALL_BINS")) + QLatin1Char('/');
    foreach (const QString &possibleCommand, possibleCommands) {
        const QString fullPath = qtdirbin + possibleCommand;
        if (QFileInfo(fullPath).isFile())
            return QDir::cleanPath(fullPath);
    }
    return QString::null;
}

dt's avatar
dt committed
1021 1022 1023 1024 1025 1026
QString QtVersion::uicCommand() const
{
    if (!isValid())
        return QString::null;
    if (!m_uicCommand.isNull())
        return m_uicCommand;
1027 1028 1029
#ifdef Q_OS_WIN
    const QStringList possibleCommands(QLatin1String("uic.exe"));
#else
dt's avatar
dt committed
1030
    QStringList possibleCommands;
1031 1032 1033 1034 1035 1036 1037 1038 1039 1040
    possibleCommands << QLatin1String("uic-qt4") << QLatin1String("uic4") << QLatin1String("uic");
#endif
    m_uicCommand = findQtBinary(possibleCommands);
    return m_uicCommand;
}

// Return a list of GUI binary names
// 'foo', 'foo.exe', 'Foo.app/Contents/MacOS/Foo'
static inline QStringList possibleGuiBinaries(const QString &name)
{
dt's avatar
dt committed
1041
#ifdef Q_OS_WIN
1042
    return QStringList(name + QLatin1String(".exe"));
Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
1043
#elif defined(Q_OS_MAC) // 'Foo.app/Contents/MacOS/Foo'
1044 1045 1046 1047 1048 1049
    QString upCaseName = name;
    upCaseName[0] = upCaseName.at(0).toUpper();
    QString macBinary = upCaseName;
    macBinary += QLatin1String(".app/Contents/MacOS/");
    macBinary += upCaseName;
    return QStringList(macBinary);
dt's avatar
dt committed
1050
#else
1051
    return QStringList(name);
dt's avatar
dt committed
1052
#endif
1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070
}

QString QtVersion::designerCommand() const
{
    if (!isValid())
        return QString::null;
    if (m_designerCommand.isNull())
        m_designerCommand = findQtBinary(possibleGuiBinaries(QLatin1String("designer")));
    return m_designerCommand;
}

QString QtVersion::linguistCommand() const
{
    if (!isValid())
        return QString::null;
    if (m_linguistCommand.isNull())
        m_linguistCommand = findQtBinary(possibleGuiBinaries(QLatin1String("linguist")));
    return m_linguistCommand;
dt's avatar
dt committed
1071 1072
}

con's avatar
con committed
1073
QList<ProjectExplorer::ToolChain::ToolChainType> QtVersion::possibleToolChainTypes() const
con's avatar
con committed
1074
{
con's avatar
con committed
1075
    QList<ProjectExplorer::ToolChain::ToolChainType> toolChains;
con's avatar
con committed
1076
    if (!isValid())
con's avatar
con committed
1077
        return toolChains << ProjectExplorer::ToolChain::INVALID;
con's avatar
con committed
1078
    const QString &spec = mkspec();
hjk's avatar
hjk committed
1079
    if (spec.contains("win32-msvc") || spec.contains(QLatin1String("win32-icc")))
con's avatar
con committed
1080
        toolChains << ProjectExplorer::ToolChain::MSVC;
1081
    else if (spec.contains("win32-g++"))
con's avatar
con committed
1082
        toolChains << ProjectExplorer::ToolChain::MinGW;
hjk's avatar
hjk committed
1083
    else if (spec == QString::null)
con's avatar
con committed
1084
        toolChains << ProjectExplorer::ToolChain::INVALID;
1085
    else if (spec.contains("wince"))
con's avatar
con committed
1086
        toolChains << ProjectExplorer::ToolChain::WINCE;
1087
    else if (spec.contains("linux-icc"))
con's avatar
con committed
1088 1089 1090 1091 1092
        toolChains << ProjectExplorer::ToolChain::LinuxICC;
#ifdef QTCREATOR_WITH_S60
    else if (spec.contains("symbian-abld"))
        toolChains << ProjectExplorer::ToolChain::GCCE << ProjectExplorer::ToolChain::WINSCW;
#endif
con's avatar
con committed
1093
    else
con's avatar
con committed
1094 1095 1096 1097 1098 1099 1100
        toolChains << ProjectExplorer::ToolChain::GCC;
    return toolChains;
}

ProjectExplorer::ToolChain::ToolChainType QtVersion::defaultToolchainType() const
{
    return possibleToolChainTypes().at(0);
con's avatar
con committed
1101 1102
}

con's avatar
con committed
1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114
#ifdef QTCREATOR_WITH_S60
QString QtVersion::mwcDirectory() const
{
    return m_mwcDirectory;
}

void QtVersion::setMwcDirectory(const QString &directory)
{
    m_mwcDirectory = directory;
}
#endif

con's avatar
con committed
1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129
QString QtVersion::mingwDirectory() const
{
    return m_mingwDirectory;
}

void QtVersion::setMingwDirectory(const QString &directory)
{
    m_mingwDirectory = directory;
}

QString QtVersion::msvcVersion() const
{
    return m_msvcVersion;
}

dt's avatar
dt committed
1130 1131
QString QtVersion::wincePlatform() const
{
1132
//    qDebug()<<"QtVersion::wincePlatform returning"<<ProjectExplorer::CeSdkHandler::platformName(mkspecPath() + "/qmake.conf");
dt's avatar
dt committed
1133 1134 1135
    return ProjectExplorer::CeSdkHandler::platformName(mkspecPath() + "/qmake.conf");
}

con's avatar
con committed
1136 1137 1138 1139 1140
void QtVersion::setMsvcVersion(const QString &version)
{
    m_msvcVersion = version;
}

1141
void QtVersion::addToEnvironment(ProjectExplorer::Environment &env) const
con's avatar
con committed
1142
{
dt's avatar
dt committed
1143
    env.set("QTDIR", m_path);
con's avatar
con committed
1144
    QString qtdirbin = versionInfo().value("QT_INSTALL_BINS");
dt's avatar
dt committed
1145
    env.prependOrSetPath(qtdirbin);
con's avatar
con committed
1146 1147 1148 1149 1150 1151 1152 1153 1154
}

int QtVersion::uniqueId() const
{
    return m_id;
}

int QtVersion::getUniqueId()
{
1155
    return QtVersionManager::instance()->getUniqueId();
con's avatar
con committed
1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172
}

bool QtVersion::isValid() const
{
    return (!(m_id == -1 || m_path == QString::null || m_name == QString::null || mkspec() == QString::null) && !m_notInstalled);
}

QtVersion::QmakeBuildConfig QtVersion::defaultBuildConfig() const
{
    updateVersionInfo();
    QtVersion::QmakeBuildConfig result = QtVersion::QmakeBuildConfig(0);
    if (m_defaultConfigIsDebugAndRelease)
        result = QtVersion::BuildAll;
    if (m_defaultConfigIsDebug)
        result = QtVersion::QmakeBuildConfig(result | QtVersion::DebugBuild);
    return result;
}
1173 1174 1175 1176 1177 1178

bool QtVersion::hasDebuggingHelper() const
{
    return m_hasDebuggingHelper;
}

1179 1180 1181 1182 1183
QString QtVersion::debuggingHelperLibrary() const
{
    QString qtInstallData = versionInfo().value("QT_INSTALL_DATA");
    if (qtInstallData.isEmpty())
        qtInstallData = path();
1184
    return DebuggingHelperLibrary::debuggingHelperLibrary(qtInstallData, path());
1185 1186
}

1187 1188 1189 1190 1191 1192 1193 1194
QStringList QtVersion::debuggingHelperLibraryLocations() const
{
    QString qtInstallData = versionInfo().value("QT_INSTALL_DATA");
    if (qtInstallData.isEmpty())
        qtInstallData = path();
    return DebuggingHelperLibrary::debuggingHelperLibraryLocations(qtInstallData, path());
}

1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229
bool QtVersion::hasDocumentation() const
{
    updateVersionInfo();
    return m_hasDocumentation;
}

QString QtVersion::documentationPath() const
{
    updateVersionInfo();
    return m_versionInfo["QT_INSTALL_DOCS"];
}

bool QtVersion::hasDemos() const
{
    updateVersionInfo();
    return m_hasDemos;
}

QString QtVersion::demosPath() const
{
    updateVersionInfo();
    return m_versionInfo["QT_INSTALL_DEMOS"];
}

bool QtVersion::hasExamples() const
{
    updateVersionInfo();
    return m_hasExamples;
}

QString QtVersion::examplesPath() const
{
    updateVersionInfo();
    return m_versionInfo["QT_INSTALL_EXAMPLES"];
}
1230

con's avatar
con committed
1231
bool QtVersion::isQt64Bit() const
1232 1233
{
        const QString make = qmakeCommand();
Daniel Molkentin's avatar
Daniel Molkentin committed
1234
//        qDebug() << make;
1235 1236
        bool isAmd64 = false;
#ifdef Q_OS_WIN32
Friedemann Kleint's avatar
Friedemann Kleint committed
1237 1238 1239
#  ifdef __GNUC__   // MinGW lacking some definitions/winbase.h
#    define SCS_64BIT_BINARY 6
#  endif   
1240
        DWORD binaryType = 0;
Friedemann Kleint's avatar
Friedemann Kleint committed
1241
        bool success = GetBinaryTypeW(reinterpret_cast<const TCHAR*>(make.utf16()), &binaryType) != 0;
1242 1243 1244 1245
        if (success && binaryType == SCS_64BIT_BINARY)
            isAmd64=true;
//        qDebug() << "isAmd64:" << isAmd64 << binaryType;
        return isAmd64;