2012-10-02 09:12:39 +02:00
|
|
|
/****************************************************************************
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2014-01-07 13:27:11 +01:00
|
|
|
** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
|
2012-10-02 09:12:39 +02:00
|
|
|
** Contact: http://www.qt-project.org/legal
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** This file is part of Qt Creator.
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** Commercial License Usage
|
|
|
|
|
** Licensees holding valid commercial Qt licenses may use this file in
|
|
|
|
|
** accordance with the commercial license agreement provided with the
|
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
|
|
|
|
** a written agreement between you and Digia. For licensing terms and
|
|
|
|
|
** conditions see http://qt.digia.com/licensing. For further information
|
|
|
|
|
** use the contact form at http://qt.digia.com/contact-us.
|
2008-12-02 14:17:16 +01:00
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
** GNU Lesser General Public License Usage
|
2012-10-02 09:12:39 +02:00
|
|
|
** Alternatively, this file may be used under the terms of the GNU Lesser
|
|
|
|
|
** General Public License version 2.1 as published by the Free Software
|
|
|
|
|
** Foundation and appearing in the file LICENSE.LGPL included in the
|
|
|
|
|
** packaging of this file. Please review the following information to
|
|
|
|
|
** ensure the GNU Lesser General Public License version 2.1 requirements
|
|
|
|
|
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
|
|
|
|
**
|
|
|
|
|
** In addition, as a special exception, Digia gives you certain additional
|
|
|
|
|
** rights. These rights are described in the Digia Qt LGPL Exception
|
2010-12-17 16:01:08 +01:00
|
|
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
****************************************************************************/
|
2008-12-02 16:19:05 +01:00
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
#include "qtversionmanager.h"
|
2008-12-02 16:19:05 +01:00
|
|
|
|
2012-09-03 18:31:44 +02:00
|
|
|
#include "qtkitinformation.h"
|
2011-05-04 13:14:46 +02:00
|
|
|
#include "qtversionfactory.h"
|
2013-03-27 08:59:57 +01:00
|
|
|
#include "baseqtversion.h"
|
2013-07-10 14:17:20 +02:00
|
|
|
#include "qtsupportconstants.h"
|
2011-05-04 13:14:46 +02:00
|
|
|
|
2009-01-20 11:52:04 +01:00
|
|
|
#include <coreplugin/icore.h>
|
2010-06-11 13:11:37 +02:00
|
|
|
#include <coreplugin/helpmanager.h>
|
2011-02-28 16:50:14 +01:00
|
|
|
|
2009-01-19 12:39:20 +01:00
|
|
|
#include <extensionsystem/pluginmanager.h>
|
2011-02-28 16:50:14 +01:00
|
|
|
|
2014-03-31 12:20:39 +02:00
|
|
|
#include <projectexplorer/toolchainmanager.h>
|
|
|
|
|
|
2014-06-16 18:25:52 +04:00
|
|
|
#include <utils/algorithm.h>
|
2013-11-27 16:10:14 +01:00
|
|
|
#include <utils/buildablehelperlibrary.h>
|
2012-03-23 17:41:45 +01:00
|
|
|
#include <utils/filesystemwatcher.h>
|
2013-03-19 10:07:51 +01:00
|
|
|
#include <utils/hostosinfo.h>
|
2011-08-16 10:45:23 +02:00
|
|
|
#include <utils/persistentsettings.h>
|
2010-10-19 11:14:03 +02:00
|
|
|
#include <utils/qtcprocess.h>
|
2011-05-04 13:14:46 +02:00
|
|
|
#include <utils/qtcassert.h>
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2012-04-17 08:01:25 +02:00
|
|
|
#include <QDebug>
|
|
|
|
|
#include <QDir>
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <QFile>
|
|
|
|
|
#include <QSettings>
|
|
|
|
|
#include <QTextStream>
|
2013-03-27 09:15:01 +01:00
|
|
|
#include <QStringList>
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <QTimer>
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2013-08-29 14:11:29 +02:00
|
|
|
using namespace Utils;
|
2009-04-28 12:43:04 +02:00
|
|
|
|
2013-08-29 14:11:29 +02:00
|
|
|
namespace QtSupport {
|
|
|
|
|
|
|
|
|
|
using namespace Internal;
|
|
|
|
|
|
2014-02-19 12:23:11 +01:00
|
|
|
struct QMakeAssignment
|
|
|
|
|
{
|
|
|
|
|
QString variable;
|
|
|
|
|
QString op;
|
|
|
|
|
QString value;
|
|
|
|
|
};
|
|
|
|
|
|
2013-08-29 14:11:29 +02:00
|
|
|
const char QTVERSION_DATA_KEY[] = "QtVersion.";
|
|
|
|
|
const char QTVERSION_TYPE_KEY[] = "QtVersion.Type";
|
|
|
|
|
const char QTVERSION_FILE_VERSION_KEY[] = "Version";
|
|
|
|
|
const char QTVERSION_FILENAME[] = "/qtcreator/qtversion.xml";
|
|
|
|
|
const char QTVERSION_LEGACY_FILENAME[] = "/qtversion.xml"; // TODO: pre 2.6, remove later
|
|
|
|
|
|
|
|
|
|
static QMap<int, BaseQtVersion *> m_versions;
|
|
|
|
|
static int m_idcount = 0;
|
|
|
|
|
// managed by QtProjectManagerPlugin
|
|
|
|
|
static QtVersionManager *m_instance = 0;
|
|
|
|
|
static FileSystemWatcher *m_configFileWatcher = 0;
|
|
|
|
|
static QTimer *m_fileWatcherTimer = 0;
|
|
|
|
|
static PersistentSettingsWriter *m_writer = 0;
|
2011-05-04 13:14:46 +02:00
|
|
|
|
2009-08-17 11:49:59 +02:00
|
|
|
enum { debug = 0 };
|
|
|
|
|
|
2013-08-29 14:11:29 +02:00
|
|
|
static FileName globalSettingsFileName()
|
2012-03-23 17:41:45 +01:00
|
|
|
{
|
2012-08-21 10:44:57 +02:00
|
|
|
QSettings *globalSettings = ExtensionSystem::PluginManager::globalSettings();
|
2013-08-29 14:11:29 +02:00
|
|
|
return FileName::fromString(QFileInfo(globalSettings->fileName()).absolutePath()
|
2012-09-18 17:09:25 +02:00
|
|
|
+ QLatin1String(QTVERSION_FILENAME));
|
2012-03-23 17:41:45 +01:00
|
|
|
}
|
|
|
|
|
|
2013-08-29 14:11:29 +02:00
|
|
|
static FileName settingsFileName(const QString &path)
|
2011-05-04 13:14:46 +02:00
|
|
|
{
|
2012-08-21 10:44:57 +02:00
|
|
|
QSettings *settings = ExtensionSystem::PluginManager::settings();
|
|
|
|
|
QFileInfo settingsLocation(settings->fileName());
|
2013-08-29 14:11:29 +02:00
|
|
|
return FileName::fromString(settingsLocation.absolutePath() + path);
|
2011-05-04 13:14:46 +02:00
|
|
|
}
|
|
|
|
|
|
2011-02-21 12:16:20 +01:00
|
|
|
|
|
|
|
|
// prefer newer qts otherwise compare on id
|
2011-05-04 13:14:46 +02:00
|
|
|
bool qtVersionNumberCompare(BaseQtVersion *a, BaseQtVersion *b)
|
2011-02-21 12:16:20 +01:00
|
|
|
{
|
|
|
|
|
return a->qtVersion() > b->qtVersion() || (a->qtVersion() == b->qtVersion() && a->uniqueId() < b->uniqueId());
|
|
|
|
|
}
|
|
|
|
|
|
2014-02-19 12:23:11 +01:00
|
|
|
static QString findQMakeLine(const QString &makefile, const QString &key)
|
|
|
|
|
{
|
|
|
|
|
QFile fi(makefile);
|
|
|
|
|
if (fi.exists() && fi.open(QFile::ReadOnly)) {
|
|
|
|
|
QTextStream ts(&fi);
|
|
|
|
|
while (!ts.atEnd()) {
|
|
|
|
|
const QString line = ts.readLine();
|
|
|
|
|
if (line.startsWith(key))
|
|
|
|
|
return line;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return QString();
|
|
|
|
|
}
|
|
|
|
|
|
2014-03-04 00:12:11 +01:00
|
|
|
/// This function trims the "#Command /path/to/qmake" from the line
|
2014-05-05 17:16:40 +03:00
|
|
|
static QString trimLine(const QString &line)
|
2014-02-19 12:23:11 +01:00
|
|
|
{
|
|
|
|
|
|
|
|
|
|
// Actually the first space after #Command: /path/to/qmake
|
|
|
|
|
const int firstSpace = line.indexOf(QLatin1Char(' '), 11);
|
|
|
|
|
return line.mid(firstSpace).trimmed();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void parseArgs(const QString &args,
|
|
|
|
|
QList<QMakeAssignment> *assignments,
|
|
|
|
|
QList<QMakeAssignment> *afterAssignments,
|
|
|
|
|
QString *additionalArguments);
|
|
|
|
|
static BaseQtVersion::QmakeBuildConfigs qmakeBuildConfigFromCmdArgs(QList<QMakeAssignment> *assignments,
|
|
|
|
|
BaseQtVersion::QmakeBuildConfigs defaultBuildConfig);
|
|
|
|
|
static bool restoreQtVersions();
|
|
|
|
|
static void findSystemQt();
|
|
|
|
|
static void saveQtVersions();
|
|
|
|
|
static void updateDocumentation();
|
|
|
|
|
|
|
|
|
|
|
2011-02-01 18:36:00 +01:00
|
|
|
// --------------------------------------------------------------------------
|
|
|
|
|
// QtVersionManager
|
|
|
|
|
// --------------------------------------------------------------------------
|
2009-03-25 15:18:37 +01:00
|
|
|
|
2013-08-29 14:11:29 +02:00
|
|
|
QtVersionManager::QtVersionManager()
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2013-08-29 14:11:29 +02:00
|
|
|
m_instance = this;
|
|
|
|
|
m_configFileWatcher = 0;
|
|
|
|
|
m_fileWatcherTimer = new QTimer(this);
|
|
|
|
|
m_writer = 0;
|
2008-12-02 12:01:29 +01:00
|
|
|
m_idcount = 1;
|
2011-11-25 13:19:58 +01:00
|
|
|
|
2013-08-29 14:11:29 +02:00
|
|
|
qRegisterMetaType<FileName>();
|
2012-05-09 10:47:12 +00:00
|
|
|
|
|
|
|
|
// Give the file a bit of time to settle before reading it...
|
|
|
|
|
m_fileWatcherTimer->setInterval(2000);
|
|
|
|
|
connect(m_fileWatcherTimer, SIGNAL(timeout()), SLOT(updateFromInstaller()));
|
2011-05-04 13:14:46 +02:00
|
|
|
}
|
|
|
|
|
|
2014-03-31 12:20:39 +02:00
|
|
|
void QtVersionManager::triggerQtVersionRestore()
|
2011-05-04 13:14:46 +02:00
|
|
|
{
|
2014-03-31 12:20:39 +02:00
|
|
|
disconnect(ProjectExplorer::ToolChainManager::instance(), SIGNAL(toolChainsLoaded()),
|
|
|
|
|
this, SLOT(triggerQtVersionRestore()));
|
|
|
|
|
|
2011-05-04 13:14:46 +02:00
|
|
|
bool success = restoreQtVersions();
|
2013-08-29 14:11:29 +02:00
|
|
|
m_instance->updateFromInstaller(false);
|
2011-05-04 13:14:46 +02:00
|
|
|
if (!success) {
|
|
|
|
|
// We did neither restore our settings or upgraded
|
|
|
|
|
// in that case figure out if there's a qt in path
|
2012-07-26 16:08:41 +02:00
|
|
|
// and add it to the Qt versions
|
2011-05-04 13:14:46 +02:00
|
|
|
findSystemQt();
|
|
|
|
|
}
|
|
|
|
|
|
2013-08-29 14:11:29 +02:00
|
|
|
emit m_instance->qtVersionsLoaded();
|
|
|
|
|
emit m_instance->qtVersionsChanged(m_versions.keys(), QList<int>(), QList<int>());
|
2011-05-04 13:14:46 +02:00
|
|
|
saveQtVersions();
|
2012-03-23 17:41:45 +01:00
|
|
|
|
2013-08-29 14:11:29 +02:00
|
|
|
const FileName configFileName = globalSettingsFileName();
|
2012-08-20 18:52:20 +02:00
|
|
|
if (configFileName.toFileInfo().exists()) {
|
2013-08-29 14:11:29 +02:00
|
|
|
m_configFileWatcher = new FileSystemWatcher(m_instance);
|
2012-04-03 10:05:08 +02:00
|
|
|
connect(m_configFileWatcher, SIGNAL(fileChanged(QString)),
|
2012-05-09 10:47:12 +00:00
|
|
|
m_fileWatcherTimer, SLOT(start()));
|
2012-08-20 18:52:20 +02:00
|
|
|
m_configFileWatcher->addFile(configFileName.toString(),
|
2013-08-29 14:11:29 +02:00
|
|
|
FileSystemWatcher::WatchModifiedDate);
|
2012-04-03 10:05:08 +02:00
|
|
|
} // exists
|
2011-05-04 13:14:46 +02:00
|
|
|
}
|
|
|
|
|
|
2012-02-02 10:47:33 +01:00
|
|
|
bool QtVersionManager::delayedInitialize()
|
|
|
|
|
{
|
|
|
|
|
updateDocumentation();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2013-08-29 14:11:29 +02:00
|
|
|
bool QtVersionManager::isLoaded()
|
2013-02-28 14:41:43 +01:00
|
|
|
{
|
|
|
|
|
return m_writer;
|
|
|
|
|
}
|
|
|
|
|
|
2011-05-04 13:14:46 +02:00
|
|
|
QtVersionManager::~QtVersionManager()
|
|
|
|
|
{
|
2012-08-17 13:18:31 +02:00
|
|
|
delete m_writer;
|
2011-05-04 13:14:46 +02:00
|
|
|
qDeleteAll(m_versions);
|
|
|
|
|
m_versions.clear();
|
|
|
|
|
}
|
|
|
|
|
|
2014-03-31 12:20:39 +02:00
|
|
|
void QtVersionManager::initialized()
|
|
|
|
|
{
|
|
|
|
|
connect(ProjectExplorer::ToolChainManager::instance(), SIGNAL(toolChainsLoaded()),
|
|
|
|
|
QtVersionManager::instance(), SLOT(triggerQtVersionRestore()));
|
|
|
|
|
}
|
|
|
|
|
|
2014-04-01 12:38:06 +02:00
|
|
|
QtVersionManager *QtVersionManager::instance()
|
2011-05-04 13:14:46 +02:00
|
|
|
{
|
2013-08-29 14:11:29 +02:00
|
|
|
return m_instance;
|
2011-05-04 13:14:46 +02:00
|
|
|
}
|
|
|
|
|
|
2014-02-19 12:23:11 +01:00
|
|
|
static bool restoreQtVersions()
|
2011-05-04 13:14:46 +02:00
|
|
|
{
|
2012-09-26 17:06:53 +02:00
|
|
|
QTC_ASSERT(!m_writer, return false);
|
2013-08-29 14:11:29 +02:00
|
|
|
m_writer = new PersistentSettingsWriter(settingsFileName(QLatin1String(QTVERSION_FILENAME)),
|
2012-09-26 17:06:53 +02:00
|
|
|
QLatin1String("QtCreatorQtVersions"));
|
|
|
|
|
|
2012-06-18 11:34:15 +02:00
|
|
|
QList<QtVersionFactory *> factories = ExtensionSystem::PluginManager::getObjects<QtVersionFactory>();
|
2011-05-04 13:14:46 +02:00
|
|
|
|
2013-08-29 14:11:29 +02:00
|
|
|
PersistentSettingsReader reader;
|
|
|
|
|
FileName filename = settingsFileName(QLatin1String(QTVERSION_FILENAME));
|
2012-06-20 15:49:58 +02:00
|
|
|
|
2012-04-24 15:49:09 +02:00
|
|
|
// Read Qt Creator 2.5 qtversions.xml once:
|
2012-08-20 18:52:20 +02:00
|
|
|
if (!filename.toFileInfo().exists())
|
2012-09-18 17:09:25 +02:00
|
|
|
filename = settingsFileName(QLatin1String(QTVERSION_LEGACY_FILENAME));
|
2012-04-24 15:49:09 +02:00
|
|
|
if (!reader.load(filename))
|
2011-05-04 13:14:46 +02:00
|
|
|
return false;
|
|
|
|
|
QVariantMap data = reader.restoreValues();
|
|
|
|
|
|
|
|
|
|
// Check version:
|
|
|
|
|
int version = data.value(QLatin1String(QTVERSION_FILE_VERSION_KEY), 0).toInt();
|
|
|
|
|
if (version < 1)
|
|
|
|
|
return false;
|
|
|
|
|
|
2012-06-20 15:49:58 +02:00
|
|
|
const QString keyPrefix = QLatin1String(QTVERSION_DATA_KEY);
|
2013-03-14 14:14:48 +01:00
|
|
|
const QVariantMap::ConstIterator dcend = data.constEnd();
|
|
|
|
|
for (QVariantMap::ConstIterator it = data.constBegin(); it != dcend; ++it) {
|
|
|
|
|
const QString &key = it.key();
|
2012-06-20 15:49:58 +02:00
|
|
|
if (!key.startsWith(keyPrefix))
|
|
|
|
|
continue;
|
|
|
|
|
bool ok;
|
|
|
|
|
int count = key.mid(keyPrefix.count()).toInt(&ok);
|
|
|
|
|
if (!ok || count < 0)
|
|
|
|
|
continue;
|
2011-05-04 13:14:46 +02:00
|
|
|
|
2013-03-14 14:14:48 +01:00
|
|
|
const QVariantMap qtversionMap = it.value().toMap();
|
2012-01-06 17:43:27 +01:00
|
|
|
const QString type = qtversionMap.value(QLatin1String(QTVERSION_TYPE_KEY)).toString();
|
2011-05-04 13:14:46 +02:00
|
|
|
|
|
|
|
|
bool restored = false;
|
|
|
|
|
foreach (QtVersionFactory *f, factories) {
|
|
|
|
|
if (f->canRestore(type)) {
|
2011-06-28 14:35:38 +02:00
|
|
|
if (BaseQtVersion *qtv = f->restore(type, qtversionMap)) {
|
2011-05-04 13:14:46 +02:00
|
|
|
if (m_versions.contains(qtv->uniqueId())) {
|
|
|
|
|
// This shouldn't happen, we are restoring the same id multiple times?
|
2011-06-14 17:17:24 +02:00
|
|
|
qWarning() << "A Qt version with id"<<qtv->uniqueId()<<"already exists";
|
2011-05-04 13:14:46 +02:00
|
|
|
delete qtv;
|
|
|
|
|
} else {
|
|
|
|
|
m_versions.insert(qtv->uniqueId(), qtv);
|
|
|
|
|
m_idcount = qtv->uniqueId() > m_idcount ? qtv->uniqueId() : m_idcount;
|
|
|
|
|
restored = true;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (!restored)
|
2011-06-14 17:17:24 +02:00
|
|
|
qWarning("Warning: Unable to restore Qt version '%s' stored in %s.",
|
2011-05-04 13:14:46 +02:00
|
|
|
qPrintable(type),
|
2012-08-20 18:52:20 +02:00
|
|
|
qPrintable(filename.toUserOutput()));
|
2011-05-04 13:14:46 +02:00
|
|
|
}
|
|
|
|
|
++m_idcount;
|
2013-02-28 14:41:43 +01:00
|
|
|
|
2011-05-04 13:14:46 +02:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2012-08-28 12:17:10 +02:00
|
|
|
void QtVersionManager::updateFromInstaller(bool emitSignal)
|
2011-05-04 13:14:46 +02:00
|
|
|
{
|
2012-05-09 10:47:12 +00:00
|
|
|
m_fileWatcherTimer->stop();
|
|
|
|
|
|
2013-08-29 14:11:29 +02:00
|
|
|
const FileName path = globalSettingsFileName();
|
2012-08-17 13:18:31 +02:00
|
|
|
// Handle overwritting of data:
|
2012-03-23 17:41:45 +01:00
|
|
|
if (m_configFileWatcher) {
|
2012-08-20 18:52:20 +02:00
|
|
|
m_configFileWatcher->removeFile(path.toString());
|
2013-08-29 14:11:29 +02:00
|
|
|
m_configFileWatcher->addFile(path.toString(), FileSystemWatcher::WatchModifiedDate);
|
2012-03-23 17:41:45 +01:00
|
|
|
}
|
|
|
|
|
|
2012-05-09 10:48:29 +00:00
|
|
|
QList<int> added;
|
|
|
|
|
QList<int> removed;
|
|
|
|
|
QList<int> changed;
|
|
|
|
|
|
2012-06-18 11:34:15 +02:00
|
|
|
QList<QtVersionFactory *> factories = ExtensionSystem::PluginManager::getObjects<QtVersionFactory>();
|
2013-08-29 14:11:29 +02:00
|
|
|
PersistentSettingsReader reader;
|
2012-04-30 13:36:33 +02:00
|
|
|
QVariantMap data;
|
2012-08-20 18:52:20 +02:00
|
|
|
if (reader.load(path))
|
2012-04-30 13:36:33 +02:00
|
|
|
data = reader.restoreValues();
|
2011-05-12 11:53:58 +02:00
|
|
|
|
|
|
|
|
if (debug) {
|
2011-06-14 17:17:24 +02:00
|
|
|
qDebug()<< "======= Existing Qt versions =======";
|
2011-05-12 11:53:58 +02:00
|
|
|
foreach (BaseQtVersion *version, m_versions) {
|
2011-11-25 13:19:58 +01:00
|
|
|
qDebug() << version->qmakeCommand().toString() << "id:"<<version->uniqueId();
|
2011-05-12 11:53:58 +02:00
|
|
|
qDebug() << " autodetection source:"<< version->autodetectionSource();
|
|
|
|
|
qDebug() << "";
|
|
|
|
|
}
|
|
|
|
|
qDebug()<< "======= Adding sdk versions =======";
|
|
|
|
|
}
|
2012-06-20 15:49:58 +02:00
|
|
|
|
2011-05-12 11:53:58 +02:00
|
|
|
QStringList sdkVersions;
|
2012-06-20 15:49:58 +02:00
|
|
|
|
|
|
|
|
const QString keyPrefix = QLatin1String(QTVERSION_DATA_KEY);
|
2013-03-14 14:14:48 +01:00
|
|
|
const QVariantMap::ConstIterator dcend = data.constEnd();
|
|
|
|
|
for (QVariantMap::ConstIterator it = data.constBegin(); it != dcend; ++it) {
|
|
|
|
|
const QString &key = it.key();
|
2012-06-20 15:49:58 +02:00
|
|
|
if (!key.startsWith(keyPrefix))
|
|
|
|
|
continue;
|
|
|
|
|
bool ok;
|
|
|
|
|
int count = key.mid(keyPrefix.count()).toInt(&ok);
|
|
|
|
|
if (!ok || count < 0)
|
|
|
|
|
continue;
|
2011-05-12 11:53:58 +02:00
|
|
|
|
2013-03-14 14:14:48 +01:00
|
|
|
QVariantMap qtversionMap = it.value().toMap();
|
2012-01-06 17:43:27 +01:00
|
|
|
const QString type = qtversionMap.value(QLatin1String(QTVERSION_TYPE_KEY)).toString();
|
2011-05-12 11:53:58 +02:00
|
|
|
const QString autoDetectionSource = qtversionMap.value(QLatin1String("autodetectionSource")).toString();
|
|
|
|
|
sdkVersions << autoDetectionSource;
|
|
|
|
|
int id = -1; // see BaseQtVersion::fromMap()
|
|
|
|
|
QtVersionFactory *factory = 0;
|
|
|
|
|
foreach (QtVersionFactory *f, factories) {
|
2012-06-20 15:49:58 +02:00
|
|
|
if (f->canRestore(type))
|
2011-05-12 11:53:58 +02:00
|
|
|
factory = f;
|
|
|
|
|
}
|
|
|
|
|
if (!factory) {
|
|
|
|
|
if (debug)
|
|
|
|
|
qDebug("Warning: Unable to find factory for type '%s'", qPrintable(type));
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2012-07-26 16:08:41 +02:00
|
|
|
// First try to find a existing Qt version to update
|
2011-05-12 11:53:58 +02:00
|
|
|
bool restored = false;
|
|
|
|
|
foreach (BaseQtVersion *v, m_versions) {
|
|
|
|
|
if (v->autodetectionSource() == autoDetectionSource) {
|
|
|
|
|
id = v->uniqueId();
|
|
|
|
|
if (debug)
|
|
|
|
|
qDebug() << " Qt version found with same autodetection source" << autoDetectionSource << " => Migrating id:" << id;
|
2012-05-09 10:48:29 +00:00
|
|
|
m_versions.remove(id);
|
2013-07-10 14:17:20 +02:00
|
|
|
qtversionMap[QLatin1String(Constants::QTVERSIONID)] = id;
|
2013-07-10 14:20:26 +02:00
|
|
|
qtversionMap[QLatin1String(Constants::QTVERSIONNAME)] = v->displayName();
|
2013-07-10 14:12:30 +02:00
|
|
|
delete v;
|
2011-05-12 11:53:58 +02:00
|
|
|
|
2011-06-28 14:35:38 +02:00
|
|
|
if (BaseQtVersion *qtv = factory->restore(type, qtversionMap)) {
|
2011-05-12 11:53:58 +02:00
|
|
|
Q_ASSERT(qtv->isAutodetected());
|
2012-05-09 10:48:29 +00:00
|
|
|
m_versions.insert(id, qtv);
|
2011-05-12 11:53:58 +02:00
|
|
|
restored = true;
|
|
|
|
|
}
|
2012-05-09 10:48:29 +00:00
|
|
|
if (restored)
|
|
|
|
|
changed << id;
|
|
|
|
|
else
|
|
|
|
|
removed << id;
|
2011-05-12 11:53:58 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// Create a new qtversion
|
|
|
|
|
if (!restored) { // didn't replace any existing versions
|
|
|
|
|
if (debug)
|
|
|
|
|
qDebug() << " No Qt version found matching" << autoDetectionSource << " => Creating new version";
|
2011-06-28 14:35:38 +02:00
|
|
|
if (BaseQtVersion *qtv = factory->restore(type, qtversionMap)) {
|
2011-05-12 11:53:58 +02:00
|
|
|
Q_ASSERT(qtv->isAutodetected());
|
2012-05-09 10:48:29 +00:00
|
|
|
m_versions.insert(qtv->uniqueId(), qtv);
|
|
|
|
|
added << qtv->uniqueId();
|
2011-05-12 11:53:58 +02:00
|
|
|
restored = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (!restored)
|
|
|
|
|
if (debug)
|
|
|
|
|
qDebug("Warning: Unable to update qtversion '%s' from sdk installer.",
|
|
|
|
|
qPrintable(autoDetectionSource));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (debug) {
|
|
|
|
|
qDebug() << "======= Before removing outdated sdk versions =======";
|
|
|
|
|
foreach (BaseQtVersion *version, m_versions) {
|
2011-11-25 13:19:58 +01:00
|
|
|
qDebug() << version->qmakeCommand().toString() << "id:"<<version->uniqueId();
|
2011-05-12 11:53:58 +02:00
|
|
|
qDebug() << " autodetection source:"<< version->autodetectionSource();
|
|
|
|
|
qDebug() << "";
|
|
|
|
|
}
|
|
|
|
|
}
|
2013-08-29 14:11:29 +02:00
|
|
|
foreach (BaseQtVersion *qtVersion, QtVersionManager::versions()) {
|
2012-01-06 17:43:27 +01:00
|
|
|
if (qtVersion->autodetectionSource().startsWith(QLatin1String("SDK."))) {
|
2011-05-12 11:53:58 +02:00
|
|
|
if (!sdkVersions.contains(qtVersion->autodetectionSource())) {
|
|
|
|
|
if (debug)
|
|
|
|
|
qDebug() << " removing version"<<qtVersion->autodetectionSource();
|
2012-05-09 10:48:29 +00:00
|
|
|
m_versions.remove(qtVersion->uniqueId());
|
|
|
|
|
removed << qtVersion->uniqueId();
|
2011-05-12 11:53:58 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (debug) {
|
|
|
|
|
qDebug()<< "======= End result =======";
|
|
|
|
|
foreach (BaseQtVersion *version, m_versions) {
|
2011-11-25 13:19:58 +01:00
|
|
|
qDebug() << version->qmakeCommand().toString() << "id:"<<version->uniqueId();
|
2011-05-12 11:53:58 +02:00
|
|
|
qDebug() << " autodetection source:"<< version->autodetectionSource();
|
|
|
|
|
qDebug() << "";
|
|
|
|
|
}
|
|
|
|
|
}
|
2012-08-28 12:17:10 +02:00
|
|
|
if (emitSignal)
|
|
|
|
|
emit qtVersionsChanged(added, removed, changed);
|
2011-05-04 13:14:46 +02:00
|
|
|
}
|
|
|
|
|
|
2014-02-19 12:23:11 +01:00
|
|
|
static void saveQtVersions()
|
2011-05-04 13:14:46 +02:00
|
|
|
{
|
2012-08-17 13:18:31 +02:00
|
|
|
if (!m_writer)
|
2012-09-26 17:06:53 +02:00
|
|
|
return;
|
2012-08-31 17:01:15 +02:00
|
|
|
|
|
|
|
|
QVariantMap data;
|
|
|
|
|
data.insert(QLatin1String(QTVERSION_FILE_VERSION_KEY), 1);
|
2011-05-04 13:14:46 +02:00
|
|
|
|
|
|
|
|
int count = 0;
|
|
|
|
|
foreach (BaseQtVersion *qtv, m_versions) {
|
|
|
|
|
QVariantMap tmp = qtv->toMap();
|
|
|
|
|
if (tmp.isEmpty())
|
|
|
|
|
continue;
|
2012-01-06 17:43:27 +01:00
|
|
|
tmp.insert(QLatin1String(QTVERSION_TYPE_KEY), qtv->type());
|
2012-08-31 17:01:15 +02:00
|
|
|
data.insert(QString::fromLatin1(QTVERSION_DATA_KEY) + QString::number(count), tmp);
|
2011-05-04 13:14:46 +02:00
|
|
|
++count;
|
|
|
|
|
|
|
|
|
|
}
|
2012-08-31 17:01:15 +02:00
|
|
|
m_writer->save(data, Core::ICore::mainWindow());
|
2011-05-04 13:14:46 +02:00
|
|
|
}
|
|
|
|
|
|
2014-02-19 12:23:11 +01:00
|
|
|
static void findSystemQt()
|
2011-05-04 13:14:46 +02:00
|
|
|
{
|
2013-11-27 16:10:14 +01:00
|
|
|
FileName systemQMakePath = BuildableHelperLibrary::findSystemQt(Environment::systemEnvironment());
|
2011-05-04 13:14:46 +02:00
|
|
|
if (systemQMakePath.isNull())
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
BaseQtVersion *version = QtVersionFactory::createQtVersionFromQMakePath(systemQMakePath);
|
2012-09-27 20:31:49 +08:00
|
|
|
if (version) {
|
|
|
|
|
version->setDisplayName(BaseQtVersion::defaultDisplayName(version->qtVersionString(), systemQMakePath, true));
|
|
|
|
|
m_versions.insert(version->uniqueId(), version);
|
|
|
|
|
}
|
2011-05-04 13:14:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void QtVersionManager::addVersion(BaseQtVersion *version)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2013-02-28 14:41:43 +01:00
|
|
|
QTC_ASSERT(m_writer, return);
|
2009-10-12 15:31:20 +02:00
|
|
|
QTC_ASSERT(version != 0, return);
|
2011-02-21 12:16:20 +01:00
|
|
|
if (m_versions.contains(version->uniqueId()))
|
2010-03-26 10:37:05 +01:00
|
|
|
return;
|
|
|
|
|
|
2009-12-03 18:37:27 +01:00
|
|
|
int uniqueId = version->uniqueId();
|
2011-02-21 12:16:20 +01:00
|
|
|
m_versions.insert(uniqueId, version);
|
|
|
|
|
|
2013-08-29 14:11:29 +02:00
|
|
|
emit m_instance->qtVersionsChanged(QList<int>() << uniqueId, QList<int>(), QList<int>());
|
2011-05-04 13:14:46 +02:00
|
|
|
saveQtVersions();
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2011-05-04 13:14:46 +02:00
|
|
|
void QtVersionManager::removeVersion(BaseQtVersion *version)
|
2009-05-28 13:22:23 +02:00
|
|
|
{
|
2009-10-12 15:31:20 +02:00
|
|
|
QTC_ASSERT(version != 0, return);
|
2011-02-21 12:16:20 +01:00
|
|
|
m_versions.remove(version->uniqueId());
|
2013-08-29 14:11:29 +02:00
|
|
|
emit m_instance->qtVersionsChanged(QList<int>(), QList<int>() << version->uniqueId(), QList<int>());
|
2011-05-04 13:14:46 +02:00
|
|
|
saveQtVersions();
|
2009-05-28 13:22:23 +02:00
|
|
|
delete version;
|
|
|
|
|
}
|
|
|
|
|
|
2014-02-19 12:23:11 +01:00
|
|
|
static void updateDocumentation()
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
|
|
|
|
QStringList files;
|
2011-05-04 13:14:46 +02:00
|
|
|
foreach (BaseQtVersion *v, m_versions) {
|
2012-11-28 12:04:32 +01:00
|
|
|
const QStringList docPaths = QStringList() << v->documentationPath() + QLatin1Char('/')
|
|
|
|
|
<< v->documentationPath() + QLatin1String("/qch/");
|
|
|
|
|
foreach (const QString &docPath, docPaths) {
|
|
|
|
|
const QDir versionHelpDir(docPath);
|
|
|
|
|
foreach (const QString &helpFile,
|
|
|
|
|
versionHelpDir.entryList(QStringList() << QLatin1String("*.qch"), QDir::Files))
|
|
|
|
|
files << docPath + helpFile;
|
|
|
|
|
}
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
2013-08-29 19:00:34 +02:00
|
|
|
Core::HelpManager::registerDocumentation(files);
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2013-08-29 14:11:29 +02:00
|
|
|
void QtVersionManager::updateDumpFor(const FileName &qmakeCommand)
|
2011-05-09 11:19:37 +02:00
|
|
|
{
|
|
|
|
|
foreach (BaseQtVersion *v, versions()) {
|
|
|
|
|
if (v->qmakeCommand() == qmakeCommand)
|
|
|
|
|
v->recheckDumper();
|
|
|
|
|
}
|
2011-05-13 13:17:24 +02:00
|
|
|
emit dumpUpdatedFor(qmakeCommand);
|
2011-05-09 11:19:37 +02:00
|
|
|
}
|
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
int QtVersionManager::getUniqueId()
|
|
|
|
|
{
|
|
|
|
|
return m_idcount++;
|
|
|
|
|
}
|
|
|
|
|
|
2013-08-29 14:11:29 +02:00
|
|
|
QList<BaseQtVersion *> QtVersionManager::versions()
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2011-05-04 13:14:46 +02:00
|
|
|
QList<BaseQtVersion *> versions;
|
2013-02-28 14:41:43 +01:00
|
|
|
QTC_ASSERT(isLoaded(), return versions);
|
2011-05-04 13:14:46 +02:00
|
|
|
foreach (BaseQtVersion *version, m_versions)
|
2011-02-21 12:16:20 +01:00
|
|
|
versions << version;
|
2014-06-16 18:25:52 +04:00
|
|
|
Utils::sort(versions, qtVersionNumberCompare);
|
2011-02-21 12:16:20 +01:00
|
|
|
return versions;
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2013-08-29 14:11:29 +02:00
|
|
|
QList<BaseQtVersion *> QtVersionManager::validVersions()
|
2010-03-26 10:37:05 +01:00
|
|
|
{
|
2011-05-04 13:14:46 +02:00
|
|
|
QList<BaseQtVersion *> results;
|
2013-02-28 14:41:43 +01:00
|
|
|
QTC_ASSERT(isLoaded(), return results);
|
2011-05-12 12:25:25 +02:00
|
|
|
foreach (BaseQtVersion *v, m_versions) {
|
2010-03-26 10:37:05 +01:00
|
|
|
if (v->isValid())
|
|
|
|
|
results.append(v);
|
|
|
|
|
}
|
2014-06-16 18:25:52 +04:00
|
|
|
Utils::sort(results, qtVersionNumberCompare);
|
2010-03-26 10:37:05 +01:00
|
|
|
return results;
|
|
|
|
|
}
|
|
|
|
|
|
2013-08-29 14:11:29 +02:00
|
|
|
bool QtVersionManager::isValidId(int id)
|
2010-01-12 15:46:23 +01:00
|
|
|
{
|
2013-02-28 14:41:43 +01:00
|
|
|
QTC_ASSERT(isLoaded(), return false);
|
2011-02-21 12:16:20 +01:00
|
|
|
return m_versions.contains(id);
|
2010-01-12 15:46:23 +01:00
|
|
|
}
|
|
|
|
|
|
2013-08-29 14:11:29 +02:00
|
|
|
BaseQtVersion *QtVersionManager::version(int id)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2013-02-28 14:41:43 +01:00
|
|
|
QTC_ASSERT(isLoaded(), return 0);
|
2011-05-04 13:14:46 +02:00
|
|
|
QMap<int, BaseQtVersion *>::const_iterator it = m_versions.find(id);
|
2011-02-21 12:16:20 +01:00
|
|
|
if (it == m_versions.constEnd())
|
2011-05-04 13:14:46 +02:00
|
|
|
return 0;
|
2011-02-21 12:16:20 +01:00
|
|
|
return it.value();
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2014-02-19 12:23:11 +01:00
|
|
|
// This function is really simplistic...
|
|
|
|
|
static bool equals(BaseQtVersion *a, BaseQtVersion *b)
|
2009-12-03 18:37:27 +01:00
|
|
|
{
|
2011-05-04 13:14:46 +02:00
|
|
|
return a->equals(b);
|
2009-12-03 18:37:27 +01:00
|
|
|
}
|
|
|
|
|
|
2011-05-04 13:14:46 +02:00
|
|
|
void QtVersionManager::setNewQtVersions(QList<BaseQtVersion *> newVersions)
|
2009-04-22 18:05:55 +02:00
|
|
|
{
|
2009-12-03 18:37:27 +01:00
|
|
|
// We want to preserve the same order as in the settings dialog
|
|
|
|
|
// so we sort a copy
|
2011-05-04 13:14:46 +02:00
|
|
|
QList<BaseQtVersion *> sortedNewVersions = newVersions;
|
2014-06-16 18:25:52 +04:00
|
|
|
Utils::sort(sortedNewVersions, [](const BaseQtVersion *l, const BaseQtVersion *r) {
|
|
|
|
|
return l->uniqueId() < r->uniqueId();
|
|
|
|
|
});
|
2009-12-03 18:37:27 +01:00
|
|
|
|
2012-02-24 18:57:33 +01:00
|
|
|
QList<int> addedVersions;
|
|
|
|
|
QList<int> removedVersions;
|
2009-12-03 18:37:27 +01:00
|
|
|
QList<int> changedVersions;
|
|
|
|
|
// So we trying to find the minimal set of changed versions,
|
|
|
|
|
// iterate over both sorted list
|
|
|
|
|
|
|
|
|
|
// newVersions and oldVersions iterator
|
2011-05-04 13:14:46 +02:00
|
|
|
QList<BaseQtVersion *>::const_iterator nit, nend;
|
|
|
|
|
QMap<int, BaseQtVersion *>::const_iterator oit, oend;
|
2009-12-03 18:37:27 +01:00
|
|
|
nit = sortedNewVersions.constBegin();
|
|
|
|
|
nend = sortedNewVersions.constEnd();
|
|
|
|
|
oit = m_versions.constBegin();
|
|
|
|
|
oend = m_versions.constEnd();
|
|
|
|
|
|
|
|
|
|
while (nit != nend && oit != oend) {
|
|
|
|
|
int nid = (*nit)->uniqueId();
|
|
|
|
|
int oid = (*oit)->uniqueId();
|
|
|
|
|
if (nid < oid) {
|
2012-02-24 18:57:33 +01:00
|
|
|
addedVersions.push_back(nid);
|
2009-12-03 18:37:27 +01:00
|
|
|
++nit;
|
|
|
|
|
} else if (oid < nid) {
|
2012-02-24 18:57:33 +01:00
|
|
|
removedVersions.push_back(oid);
|
2009-12-03 18:37:27 +01:00
|
|
|
++oit;
|
|
|
|
|
} else {
|
|
|
|
|
if (!equals(*oit, *nit))
|
|
|
|
|
changedVersions.push_back(oid);
|
|
|
|
|
++oit;
|
|
|
|
|
++nit;
|
2009-04-22 18:05:55 +02:00
|
|
|
}
|
|
|
|
|
}
|
2009-12-03 18:37:27 +01:00
|
|
|
|
|
|
|
|
while (nit != nend) {
|
2012-02-24 18:57:33 +01:00
|
|
|
addedVersions.push_back((*nit)->uniqueId());
|
2009-12-10 12:08:40 +01:00
|
|
|
++nit;
|
2009-12-03 18:37:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
while (oit != oend) {
|
2012-02-24 18:57:33 +01:00
|
|
|
removedVersions.push_back((*oit)->uniqueId());
|
2009-12-10 12:08:40 +01:00
|
|
|
++oit;
|
2009-12-03 18:37:27 +01:00
|
|
|
}
|
|
|
|
|
|
2009-04-22 18:05:55 +02:00
|
|
|
qDeleteAll(m_versions);
|
|
|
|
|
m_versions.clear();
|
2011-05-04 13:14:46 +02:00
|
|
|
foreach (BaseQtVersion *v, sortedNewVersions)
|
2011-02-21 12:16:20 +01:00
|
|
|
m_versions.insert(v->uniqueId(), v);
|
2009-12-03 18:37:27 +01:00
|
|
|
|
2012-02-24 18:57:33 +01:00
|
|
|
if (!changedVersions.isEmpty() || !addedVersions.isEmpty() || !removedVersions.isEmpty())
|
2009-04-22 18:05:55 +02:00
|
|
|
updateDocumentation();
|
|
|
|
|
|
2011-05-04 13:14:46 +02:00
|
|
|
saveQtVersions();
|
2009-12-03 18:37:27 +01:00
|
|
|
|
2012-02-24 18:57:33 +01:00
|
|
|
if (!changedVersions.isEmpty() || !addedVersions.isEmpty() || !removedVersions.isEmpty())
|
2013-08-29 14:11:29 +02:00
|
|
|
emit m_instance->qtVersionsChanged(addedVersions, removedVersions, changedVersions);
|
2009-04-22 18:05:55 +02:00
|
|
|
}
|
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
// Returns the version that was used to build the project in that directory
|
|
|
|
|
// That is returns the directory
|
2010-01-11 10:22:55 +01:00
|
|
|
// To find out whether we already have a qtversion for that directory call
|
2008-12-02 12:01:29 +01:00
|
|
|
// QtVersion *QtVersionManager::qtVersionForDirectory(const QString directory);
|
2013-08-29 14:11:29 +02:00
|
|
|
FileName QtVersionManager::findQMakeBinaryFromMakefile(const QString &makefile)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
|
|
|
|
bool debugAdding = false;
|
2010-10-05 17:38:45 +02:00
|
|
|
QFile fi(makefile);
|
|
|
|
|
if (fi.exists() && fi.open(QFile::ReadOnly)) {
|
|
|
|
|
QTextStream ts(&fi);
|
2012-01-06 17:43:27 +01:00
|
|
|
QRegExp r1(QLatin1String("QMAKE\\s*=(.*)"));
|
2008-12-02 12:01:29 +01:00
|
|
|
while (!ts.atEnd()) {
|
|
|
|
|
QString line = ts.readLine();
|
|
|
|
|
if (r1.exactMatch(line)) {
|
|
|
|
|
if (debugAdding)
|
|
|
|
|
qDebug()<<"#~~ QMAKE is:"<<r1.cap(1).trimmed();
|
|
|
|
|
QFileInfo qmake(r1.cap(1).trimmed());
|
2009-09-03 19:16:22 +02:00
|
|
|
QString qmakePath = qmake.filePath();
|
2014-06-12 13:33:51 +02:00
|
|
|
if (!QString::fromLatin1(QTC_HOST_EXE_SUFFIX).isEmpty()
|
|
|
|
|
&& !qmakePath.endsWith(QLatin1String(QTC_HOST_EXE_SUFFIX))) {
|
|
|
|
|
qmakePath.append(QLatin1String(QTC_HOST_EXE_SUFFIX));
|
2013-03-19 10:07:51 +01:00
|
|
|
}
|
2010-02-19 11:41:34 +01:00
|
|
|
// Is qmake still installed?
|
2010-08-24 18:10:08 +02:00
|
|
|
QFileInfo fi(qmakePath);
|
2012-09-24 15:25:31 +02:00
|
|
|
if (fi.exists())
|
2013-08-29 14:11:29 +02:00
|
|
|
return FileName(fi);
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2013-08-29 14:11:29 +02:00
|
|
|
return FileName();
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2013-08-29 14:11:29 +02:00
|
|
|
BaseQtVersion *QtVersionManager::qtVersionForQMakeBinary(const FileName &qmakePath)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2014-07-10 12:57:06 +02:00
|
|
|
return Utils::findOrDefault(versions(), Utils::equal(&BaseQtVersion::qmakeCommand, qmakePath));
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2009-07-22 16:52:44 +02:00
|
|
|
void dumpQMakeAssignments(const QList<QMakeAssignment> &list)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2012-11-28 20:44:03 +02:00
|
|
|
foreach (const QMakeAssignment &qa, list) {
|
2009-07-22 16:52:44 +02:00
|
|
|
qDebug()<<qa.variable<<qa.op<<qa.value;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-04-19 19:24:30 +02:00
|
|
|
QtVersionManager::MakefileCompatible QtVersionManager::makefileIsFor(const QString &makefile, const QString &proFile)
|
2010-04-12 19:16:49 +02:00
|
|
|
{
|
|
|
|
|
if (proFile.isEmpty())
|
2011-04-19 19:24:30 +02:00
|
|
|
return CouldNotParse;
|
2010-04-12 19:16:49 +02:00
|
|
|
|
2011-11-21 17:36:00 +01:00
|
|
|
// The Makefile.Debug / Makefile.Release lack a # Command: line
|
|
|
|
|
if (findQMakeLine(makefile, QLatin1String("# Command:")).trimmed().isEmpty())
|
|
|
|
|
return CouldNotParse;
|
|
|
|
|
|
2010-10-05 17:38:45 +02:00
|
|
|
QString line = findQMakeLine(makefile, QLatin1String("# Project:")).trimmed();
|
2010-04-12 19:16:49 +02:00
|
|
|
if (line.isEmpty())
|
2011-04-19 19:24:30 +02:00
|
|
|
return CouldNotParse;
|
2010-04-12 19:16:49 +02:00
|
|
|
|
2012-01-06 17:43:27 +01:00
|
|
|
line.remove(0, line.indexOf(QLatin1Char(':')) + 1);
|
2010-04-12 19:16:49 +02:00
|
|
|
line = line.trimmed();
|
|
|
|
|
|
2010-10-05 17:38:45 +02:00
|
|
|
QFileInfo srcFileInfo(QFileInfo(makefile).absoluteDir(), line);
|
2010-04-12 19:16:49 +02:00
|
|
|
QFileInfo proFileInfo(proFile);
|
2011-04-19 19:24:30 +02:00
|
|
|
return (srcFileInfo == proFileInfo) ? SameProject : DifferentProject;
|
2010-04-12 19:16:49 +02:00
|
|
|
}
|
|
|
|
|
|
2011-05-04 13:14:46 +02:00
|
|
|
QPair<BaseQtVersion::QmakeBuildConfigs, QString> QtVersionManager::scanMakeFile(const QString &makefile, BaseQtVersion::QmakeBuildConfigs defaultBuildConfig)
|
2009-07-22 16:52:44 +02:00
|
|
|
{
|
2009-08-17 11:49:59 +02:00
|
|
|
if (debug)
|
|
|
|
|
qDebug()<<"ScanMakeFile, the gory details:";
|
2011-05-04 13:14:46 +02:00
|
|
|
BaseQtVersion::QmakeBuildConfigs result = defaultBuildConfig;
|
2010-10-19 11:14:03 +02:00
|
|
|
QString result2;
|
2009-07-22 16:52:44 +02:00
|
|
|
|
2010-10-05 17:38:45 +02:00
|
|
|
QString line = findQMakeLine(makefile, QLatin1String("# Command:"));
|
2009-07-22 16:52:44 +02:00
|
|
|
if (!line.isEmpty()) {
|
2009-08-17 11:49:59 +02:00
|
|
|
if (debug)
|
|
|
|
|
qDebug()<<"Found line"<<line;
|
2009-07-22 16:52:44 +02:00
|
|
|
line = trimLine(line);
|
|
|
|
|
QList<QMakeAssignment> assignments;
|
|
|
|
|
QList<QMakeAssignment> afterAssignments;
|
2010-10-19 11:14:03 +02:00
|
|
|
parseArgs(line, &assignments, &afterAssignments, &result2);
|
2009-07-22 16:52:44 +02:00
|
|
|
|
2009-08-17 11:49:59 +02:00
|
|
|
if (debug) {
|
|
|
|
|
dumpQMakeAssignments(assignments);
|
|
|
|
|
if (!afterAssignments.isEmpty())
|
|
|
|
|
qDebug()<<"-after";
|
|
|
|
|
dumpQMakeAssignments(afterAssignments);
|
|
|
|
|
}
|
2009-07-22 16:52:44 +02:00
|
|
|
|
|
|
|
|
// Search in assignments for CONFIG(+=,-=,=)(debug,release,debug_and_release)
|
|
|
|
|
// Also remove them from the list
|
|
|
|
|
result = qmakeBuildConfigFromCmdArgs(&assignments, defaultBuildConfig);
|
|
|
|
|
|
2010-04-23 11:28:02 +02:00
|
|
|
if (debug)
|
|
|
|
|
dumpQMakeAssignments(assignments);
|
2009-07-22 16:52:44 +02:00
|
|
|
|
2012-11-28 20:44:03 +02:00
|
|
|
foreach (const QMakeAssignment &qa, assignments)
|
2013-08-29 14:11:29 +02:00
|
|
|
QtcProcess::addArg(&result2, qa.variable + qa.op + qa.value);
|
2009-07-22 16:52:44 +02:00
|
|
|
if (!afterAssignments.isEmpty()) {
|
2013-08-29 14:11:29 +02:00
|
|
|
QtcProcess::addArg(&result2, QLatin1String("-after"));
|
2012-11-28 20:44:03 +02:00
|
|
|
foreach (const QMakeAssignment &qa, afterAssignments)
|
2013-08-29 14:11:29 +02:00
|
|
|
QtcProcess::addArg(&result2, qa.variable + qa.op + qa.value);
|
2009-07-22 16:52:44 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Dump the gathered information:
|
2009-08-17 11:49:59 +02:00
|
|
|
if (debug) {
|
|
|
|
|
qDebug()<<"\n\nDumping information from scanMakeFile";
|
|
|
|
|
qDebug()<<"QMake CONFIG variable parsing";
|
2012-01-06 17:43:27 +01:00
|
|
|
qDebug()<<" "<< (result & BaseQtVersion::NoBuild ? QByteArray("No Build") : QByteArray::number(int(result)));
|
2011-05-04 13:14:46 +02:00
|
|
|
qDebug()<<" "<< (result & BaseQtVersion::DebugBuild ? "debug" : "release");
|
|
|
|
|
qDebug()<<" "<< (result & BaseQtVersion::BuildAll ? "debug_and_release" : "no debug_and_release");
|
2009-08-17 11:49:59 +02:00
|
|
|
qDebug()<<"\nAddtional Arguments";
|
|
|
|
|
qDebug()<<result2;
|
|
|
|
|
qDebug()<<"\n\n";
|
|
|
|
|
}
|
2009-07-22 16:52:44 +02:00
|
|
|
return qMakePair(result, result2);
|
|
|
|
|
}
|
|
|
|
|
|
2014-02-19 12:23:11 +01:00
|
|
|
static void parseArgs(const QString &args, QList<QMakeAssignment> *assignments, QList<QMakeAssignment> *afterAssignments, QString *additionalArguments)
|
2009-07-22 16:52:44 +02:00
|
|
|
{
|
2012-01-06 17:43:27 +01:00
|
|
|
QRegExp regExp(QLatin1String("([^\\s\\+-]*)\\s*(\\+=|=|-=|~=)(.*)"));
|
2009-07-22 16:52:44 +02:00
|
|
|
bool after = false;
|
|
|
|
|
bool ignoreNext = false;
|
2010-10-19 11:14:03 +02:00
|
|
|
*additionalArguments = args;
|
2013-08-29 14:11:29 +02:00
|
|
|
QtcProcess::ArgIterator ait(additionalArguments);
|
2010-10-19 11:14:03 +02:00
|
|
|
while (ait.next()) {
|
2009-07-22 16:52:44 +02:00
|
|
|
if (ignoreNext) {
|
|
|
|
|
// Ignoring
|
|
|
|
|
ignoreNext = false;
|
2010-10-19 11:14:03 +02:00
|
|
|
ait.deleteArg();
|
|
|
|
|
} else if (ait.value() == QLatin1String("-after")) {
|
2009-07-22 16:52:44 +02:00
|
|
|
after = true;
|
2010-10-19 11:14:03 +02:00
|
|
|
ait.deleteArg();
|
|
|
|
|
} else if (ait.value().contains(QLatin1Char('='))) {
|
|
|
|
|
if (regExp.exactMatch(ait.value())) {
|
2009-07-22 16:52:44 +02:00
|
|
|
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";
|
|
|
|
|
}
|
2010-10-19 11:14:03 +02:00
|
|
|
ait.deleteArg();
|
|
|
|
|
} else if (ait.value() == QLatin1String("-o")) {
|
2009-07-22 16:52:44 +02:00
|
|
|
ignoreNext = true;
|
2010-10-19 11:14:03 +02:00
|
|
|
ait.deleteArg();
|
2009-07-22 16:52:44 +02:00
|
|
|
#if defined(Q_OS_WIN32)
|
2010-10-19 11:14:03 +02:00
|
|
|
} else if (ait.value() == QLatin1String("-win32")) {
|
2009-07-22 16:52:44 +02:00
|
|
|
#elif defined(Q_OS_MAC)
|
2010-10-19 11:14:03 +02:00
|
|
|
} else if (ait.value() == QLatin1String("-macx")) {
|
2009-07-22 16:52:44 +02:00
|
|
|
#elif defined(Q_OS_QNX6)
|
2010-10-19 11:14:03 +02:00
|
|
|
} else if (ait.value() == QLatin1String("-qnx6")) {
|
2009-07-22 16:52:44 +02:00
|
|
|
#else
|
2010-10-19 11:14:03 +02:00
|
|
|
} else if (ait.value() == QLatin1String("-unix")) {
|
2009-07-22 16:52:44 +02:00
|
|
|
#endif
|
2010-10-19 11:14:03 +02:00
|
|
|
ait.deleteArg();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
ait.deleteArg(); // The .pro file is always the last arg
|
2009-07-22 16:52:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// This function extracts all the CONFIG+=debug, CONFIG+=release
|
2014-02-19 12:23:11 +01:00
|
|
|
static BaseQtVersion::QmakeBuildConfigs qmakeBuildConfigFromCmdArgs(QList<QMakeAssignment> *assignments, BaseQtVersion::QmakeBuildConfigs defaultBuildConfig)
|
2009-07-22 16:52:44 +02:00
|
|
|
{
|
2011-05-04 13:14:46 +02:00
|
|
|
BaseQtVersion::QmakeBuildConfigs result = defaultBuildConfig;
|
2009-07-22 16:52:44 +02:00
|
|
|
QList<QMakeAssignment> oldAssignments = *assignments;
|
|
|
|
|
assignments->clear();
|
2012-11-28 20:44:03 +02:00
|
|
|
foreach (const QMakeAssignment &qa, oldAssignments) {
|
2012-01-06 17:43:27 +01:00
|
|
|
if (qa.variable == QLatin1String("CONFIG")) {
|
|
|
|
|
QStringList values = qa.value.split(QLatin1Char(' '));
|
2009-07-22 16:52:44 +02:00
|
|
|
QStringList newValues;
|
2012-11-28 20:44:03 +02:00
|
|
|
foreach (const QString &value, values) {
|
2012-01-06 17:43:27 +01:00
|
|
|
if (value == QLatin1String("debug")) {
|
|
|
|
|
if (qa.op == QLatin1String("+="))
|
2011-05-04 13:14:46 +02:00
|
|
|
result = result | BaseQtVersion::DebugBuild;
|
2009-07-22 16:52:44 +02:00
|
|
|
else
|
2011-05-04 13:14:46 +02:00
|
|
|
result = result & ~BaseQtVersion::DebugBuild;
|
2012-01-06 17:43:27 +01:00
|
|
|
} else if (value == QLatin1String("release")) {
|
|
|
|
|
if (qa.op == QLatin1String("+="))
|
2011-05-04 13:14:46 +02:00
|
|
|
result = result & ~BaseQtVersion::DebugBuild;
|
2009-07-22 16:52:44 +02:00
|
|
|
else
|
2011-05-04 13:14:46 +02:00
|
|
|
result = result | BaseQtVersion::DebugBuild;
|
2012-01-06 17:43:27 +01:00
|
|
|
} else if (value == QLatin1String("debug_and_release")) {
|
|
|
|
|
if (qa.op == QLatin1String("+="))
|
2011-05-04 13:14:46 +02:00
|
|
|
result = result | BaseQtVersion::BuildAll;
|
2009-07-22 16:52:44 +02:00
|
|
|
else
|
2011-05-04 13:14:46 +02:00
|
|
|
result = result & ~BaseQtVersion::BuildAll;
|
2009-07-22 16:52:44 +02:00
|
|
|
} else {
|
|
|
|
|
newValues.append(value);
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
2009-07-22 16:52:44 +02:00
|
|
|
QMakeAssignment newQA = qa;
|
2014-08-23 01:19:53 +02:00
|
|
|
newQA.value = newValues.join(QLatin1Char(' '));
|
2009-07-22 16:52:44 +02:00
|
|
|
if (!newValues.isEmpty())
|
|
|
|
|
assignments->append(newQA);
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
2009-07-22 16:52:44 +02:00
|
|
|
} else {
|
|
|
|
|
assignments->append(qa);
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return result;
|
|
|
|
|
}
|
2012-01-18 13:50:14 +01:00
|
|
|
|
2013-08-29 14:11:29 +02:00
|
|
|
} // namespace QtVersion
|