2012-10-02 09:12:39 +02:00
|
|
|
/****************************************************************************
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2016-01-15 14:57:40 +01:00
|
|
|
** Copyright (C) 2016 The Qt Company Ltd.
|
|
|
|
|
** Contact: https://www.qt.io/licensing/
|
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
|
2016-01-15 14:57:40 +01:00
|
|
|
** a written agreement between you and The Qt Company. For licensing terms
|
|
|
|
|
** and conditions see https://www.qt.io/terms-conditions. For further
|
|
|
|
|
** information use the contact form at https://www.qt.io/contact-us.
|
2008-12-02 14:17:16 +01:00
|
|
|
**
|
2016-01-15 14:57:40 +01:00
|
|
|
** GNU General Public License Usage
|
|
|
|
|
** Alternatively, this file may be used under the terms of the GNU
|
|
|
|
|
** General Public License version 3 as published by the Free Software
|
|
|
|
|
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
|
|
|
|
** included in the packaging of this file. Please review the following
|
|
|
|
|
** information to ensure the GNU General Public License requirements will
|
|
|
|
|
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
2010-12-17 16:01:08 +01:00
|
|
|
**
|
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>
|
2014-10-16 13:52:28 +02:00
|
|
|
#include <QStandardPaths>
|
2012-02-15 10:42:41 +01:00
|
|
|
#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;
|
|
|
|
|
|
|
|
|
|
const char QTVERSION_DATA_KEY[] = "QtVersion.";
|
|
|
|
|
const char QTVERSION_TYPE_KEY[] = "QtVersion.Type";
|
|
|
|
|
const char QTVERSION_FILE_VERSION_KEY[] = "Version";
|
2018-01-10 17:29:27 +01:00
|
|
|
const char QTVERSION_FILENAME[] = "/qtversion.xml";
|
2013-08-29 14:11:29 +02:00
|
|
|
|
|
|
|
|
static QMap<int, BaseQtVersion *> m_versions;
|
|
|
|
|
static int m_idcount = 0;
|
|
|
|
|
// managed by QtProjectManagerPlugin
|
2017-01-12 10:10:00 +01:00
|
|
|
static QtVersionManager *m_instance = nullptr;
|
|
|
|
|
static FileSystemWatcher *m_configFileWatcher = nullptr;
|
|
|
|
|
static QTimer *m_fileWatcherTimer = nullptr;
|
|
|
|
|
static PersistentSettingsWriter *m_writer = nullptr;
|
2011-05-04 13:14:46 +02:00
|
|
|
|
2009-08-17 11:49:59 +02:00
|
|
|
enum { debug = 0 };
|
|
|
|
|
|
2019-05-28 13:49:26 +02:00
|
|
|
static FilePath globalSettingsFileName()
|
2012-03-23 17:41:45 +01:00
|
|
|
{
|
2019-05-28 13:49:26 +02:00
|
|
|
return FilePath::fromString(Core::ICore::installerResourcePath() + QTVERSION_FILENAME);
|
2012-03-23 17:41:45 +01:00
|
|
|
}
|
|
|
|
|
|
2019-05-28 13:49:26 +02:00
|
|
|
static FilePath settingsFileName(const QString &path)
|
2011-05-04 13:14:46 +02:00
|
|
|
{
|
2019-05-28 13:49:26 +02:00
|
|
|
return FilePath::fromString(Core::ICore::userResourcePath() + 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 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;
|
2017-01-12 10:10:00 +01:00
|
|
|
m_configFileWatcher = nullptr;
|
2013-08-29 14:11:29 +02:00
|
|
|
m_fileWatcherTimer = new QTimer(this);
|
2017-01-12 10:10:00 +01:00
|
|
|
m_writer = nullptr;
|
2008-12-02 12:01:29 +01:00
|
|
|
m_idcount = 1;
|
2011-11-25 13:19:58 +01:00
|
|
|
|
2019-05-28 13:49:26 +02:00
|
|
|
qRegisterMetaType<FilePath>();
|
2012-05-09 10:47:12 +00:00
|
|
|
|
|
|
|
|
// Give the file a bit of time to settle before reading it...
|
|
|
|
|
m_fileWatcherTimer->setInterval(2000);
|
2016-06-05 22:22:11 +03:00
|
|
|
connect(m_fileWatcherTimer, &QTimer::timeout, this, [this] { 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
|
|
|
{
|
2016-06-05 22:22:11 +03:00
|
|
|
disconnect(ProjectExplorer::ToolChainManager::instance(), &ProjectExplorer::ToolChainManager::toolChainsLoaded,
|
|
|
|
|
this, &QtVersionManager::triggerQtVersionRestore);
|
2014-03-31 12:20:39 +02:00
|
|
|
|
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
|
|
|
|
2019-05-28 13:49:26 +02:00
|
|
|
const FilePath configFileName = globalSettingsFileName();
|
2014-10-24 13:15:54 +02:00
|
|
|
if (configFileName.exists()) {
|
2013-08-29 14:11:29 +02:00
|
|
|
m_configFileWatcher = new FileSystemWatcher(m_instance);
|
2016-06-05 22:22:11 +03:00
|
|
|
connect(m_configFileWatcher, &FileSystemWatcher::fileChanged,
|
2019-02-26 09:40:49 +01:00
|
|
|
m_fileWatcherTimer, QOverload<>::of(&QTimer::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
|
|
|
updateDocumentation();
|
|
|
|
|
}
|
|
|
|
|
|
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()
|
|
|
|
|
{
|
2016-06-05 22:22:11 +03:00
|
|
|
connect(ProjectExplorer::ToolChainManager::instance(), &ProjectExplorer::ToolChainManager::toolChainsLoaded,
|
|
|
|
|
QtVersionManager::instance(), &QtVersionManager::triggerQtVersionRestore);
|
2014-03-31 12:20:39 +02:00
|
|
|
}
|
|
|
|
|
|
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"));
|
|
|
|
|
|
2017-12-08 17:20:48 +01:00
|
|
|
const QList<QtVersionFactory *> factories = QtVersionFactory::allQtVersionFactories();
|
2011-05-04 13:14:46 +02:00
|
|
|
|
2013-08-29 14:11:29 +02:00
|
|
|
PersistentSettingsReader reader;
|
2019-05-28 13:49:26 +02:00
|
|
|
FilePath filename = settingsFileName(QLatin1String(QTVERSION_FILENAME));
|
2012-06-20 15:49:58 +02:00
|
|
|
|
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;
|
2016-02-03 13:49:53 +01:00
|
|
|
int count = key.midRef(keyPrefix.count()).toInt(&ok);
|
2012-06-20 15:49:58 +02:00
|
|
|
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;
|
2017-12-08 17:20:48 +01:00
|
|
|
for (QtVersionFactory *f : factories) {
|
2011-05-04 13:14:46 +02:00
|
|
|
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();
|
|
|
|
|
|
2019-05-28 13:49:26 +02:00
|
|
|
const FilePath 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;
|
|
|
|
|
|
2017-12-08 17:20:48 +01:00
|
|
|
const QList<QtVersionFactory *> factories = QtVersionFactory::allQtVersionFactories();
|
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;
|
2016-02-03 13:49:53 +01:00
|
|
|
int count = key.midRef(keyPrefix.count()).toInt(&ok);
|
2012-06-20 15:49:58 +02:00
|
|
|
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()
|
2017-01-12 10:10:00 +01:00
|
|
|
QtVersionFactory *factory = nullptr;
|
2011-05-12 11:53:58 +02:00
|
|
|
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;
|
2015-02-18 10:44:57 +01:00
|
|
|
qtversionMap[QLatin1String(Constants::QTVERSIONNAME)] = v->unexpandedDisplayName();
|
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() << "";
|
|
|
|
|
}
|
|
|
|
|
}
|
2015-07-13 13:09:45 +02:00
|
|
|
foreach (BaseQtVersion *qtVersion, m_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-10-16 13:52:28 +02:00
|
|
|
// Executes qtchooser with arguments in a process and returns its output
|
|
|
|
|
static QList<QByteArray> runQtChooser(const QString &qtchooser, const QStringList &arguments)
|
|
|
|
|
{
|
|
|
|
|
QProcess p;
|
|
|
|
|
p.start(qtchooser, arguments);
|
|
|
|
|
p.waitForFinished();
|
|
|
|
|
const bool success = p.exitCode() == 0;
|
|
|
|
|
return success ? p.readAllStandardOutput().split('\n') : QList<QByteArray>();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Asks qtchooser for the qmake path of a given version
|
|
|
|
|
static QString qmakePath(const QString &qtchooser, const QString &version)
|
|
|
|
|
{
|
|
|
|
|
QList<QByteArray> outputs = runQtChooser(qtchooser, QStringList()
|
|
|
|
|
<< QStringLiteral("-qt=%1").arg(version)
|
|
|
|
|
<< QStringLiteral("-print-env"));
|
|
|
|
|
foreach (const QByteArray &output, outputs) {
|
|
|
|
|
if (output.startsWith("QTTOOLDIR=\"")) {
|
|
|
|
|
QByteArray withoutVarName = output.mid(11); // remove QTTOOLDIR="
|
|
|
|
|
withoutVarName.chop(1); // remove trailing quote
|
|
|
|
|
return QStandardPaths::findExecutable(QStringLiteral("qmake"), QStringList()
|
|
|
|
|
<< QString::fromLocal8Bit(withoutVarName));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return QString();
|
|
|
|
|
}
|
|
|
|
|
|
2019-05-28 13:49:26 +02:00
|
|
|
static FilePathList gatherQmakePathsFromQtChooser()
|
2014-10-16 13:52:28 +02:00
|
|
|
{
|
|
|
|
|
const QString qtchooser = QStandardPaths::findExecutable(QStringLiteral("qtchooser"));
|
|
|
|
|
if (qtchooser.isEmpty())
|
2019-05-28 13:49:26 +02:00
|
|
|
return FilePathList();
|
2014-10-16 13:52:28 +02:00
|
|
|
|
2017-02-08 14:06:01 +01:00
|
|
|
QList<QByteArray> versions = runQtChooser(qtchooser, QStringList("-l"));
|
2019-05-28 13:49:26 +02:00
|
|
|
QSet<FilePath> foundQMakes;
|
2014-10-16 13:52:28 +02:00
|
|
|
foreach (const QByteArray &version, versions) {
|
2019-05-28 13:49:26 +02:00
|
|
|
FilePath possibleQMake = FilePath::fromString(
|
2014-10-16 13:52:28 +02:00
|
|
|
qmakePath(qtchooser, QString::fromLocal8Bit(version)));
|
|
|
|
|
if (!possibleQMake.isEmpty())
|
|
|
|
|
foundQMakes << possibleQMake;
|
|
|
|
|
}
|
|
|
|
|
return foundQMakes.toList();
|
|
|
|
|
}
|
|
|
|
|
|
2014-02-19 12:23:11 +01:00
|
|
|
static void findSystemQt()
|
2011-05-04 13:14:46 +02:00
|
|
|
{
|
2019-05-28 13:49:26 +02:00
|
|
|
FilePathList systemQMakes
|
2019-03-15 10:43:35 +01:00
|
|
|
= BuildableHelperLibrary::findQtsInEnvironment(Environment::systemEnvironment());
|
2014-10-16 13:52:28 +02:00
|
|
|
|
|
|
|
|
systemQMakes.append(gatherQmakePathsFromQtChooser());
|
|
|
|
|
|
2019-05-28 13:49:26 +02:00
|
|
|
foreach (const FilePath &qmakePath, Utils::filteredUnique(systemQMakes)) {
|
2014-10-16 13:52:28 +02:00
|
|
|
BaseQtVersion *version
|
|
|
|
|
= QtVersionFactory::createQtVersionFromQMakePath(qmakePath, false, QLatin1String("PATH"));
|
|
|
|
|
if (version) {
|
|
|
|
|
version->setUnexpandedDisplayName(BaseQtVersion::defaultUnexpandedDisplayName(qmakePath, true));
|
|
|
|
|
m_versions.insert(version->uniqueId(), version);
|
|
|
|
|
}
|
2012-09-27 20:31:49 +08:00
|
|
|
}
|
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);
|
2017-01-12 10:10:00 +01:00
|
|
|
QTC_ASSERT(version, 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
|
|
|
{
|
2017-01-12 10:10:00 +01:00
|
|
|
QTC_ASSERT(version, 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) {
|
2017-02-22 15:09:35 +01:00
|
|
|
const QStringList docPaths = QStringList({v->documentationPath() + QChar('/'),
|
|
|
|
|
v->documentationPath() + "/qch/"});
|
2012-11-28 12:04:32 +01:00
|
|
|
foreach (const QString &docPath, docPaths) {
|
|
|
|
|
const QDir versionHelpDir(docPath);
|
|
|
|
|
foreach (const QString &helpFile,
|
2017-02-08 14:06:01 +01:00
|
|
|
versionHelpDir.entryList(QStringList("*.qch"), QDir::Files))
|
2012-11-28 12:04:32 +01:00
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int QtVersionManager::getUniqueId()
|
|
|
|
|
{
|
|
|
|
|
return m_idcount++;
|
|
|
|
|
}
|
|
|
|
|
|
2017-01-12 10:37:29 +01:00
|
|
|
QList<BaseQtVersion *> QtVersionManager::versions(const BaseQtVersion::Predicate &predicate)
|
2015-07-13 13:09:45 +02:00
|
|
|
{
|
|
|
|
|
QList<BaseQtVersion *> versions;
|
|
|
|
|
QTC_ASSERT(isLoaded(), return versions);
|
2017-01-11 14:43:48 +01:00
|
|
|
if (predicate)
|
|
|
|
|
return Utils::filtered(m_versions.values(), predicate);
|
|
|
|
|
else
|
|
|
|
|
return m_versions.values();
|
2015-07-13 13:09:45 +02:00
|
|
|
}
|
|
|
|
|
|
2017-01-12 10:30:47 +01:00
|
|
|
QList<BaseQtVersion *> QtVersionManager::sortVersions(const QList<BaseQtVersion *> &input)
|
|
|
|
|
{
|
|
|
|
|
QList<BaseQtVersion *> result = input;
|
|
|
|
|
Utils::sort(result, qtVersionNumberCompare);
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
{
|
2017-01-12 10:10:00 +01:00
|
|
|
QTC_ASSERT(isLoaded(), return nullptr);
|
2015-04-01 11:19:32 +02:00
|
|
|
QMap<int, BaseQtVersion *>::const_iterator it = m_versions.constFind(id);
|
2011-02-21 12:16:20 +01:00
|
|
|
if (it == m_versions.constEnd())
|
2017-01-12 10:10:00 +01:00
|
|
|
return nullptr;
|
2011-02-21 12:16:20 +01:00
|
|
|
return it.value();
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2017-01-11 14:43:48 +01:00
|
|
|
BaseQtVersion *QtVersionManager::version(const BaseQtVersion::Predicate &predicate)
|
|
|
|
|
{
|
|
|
|
|
return Utils::findOrDefault(m_versions.values(), predicate);
|
|
|
|
|
}
|
|
|
|
|
|
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;
|
2016-08-09 16:32:07 +03:00
|
|
|
Utils::sort(sortedNewVersions, &BaseQtVersion::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
|
|
|
}
|
|
|
|
|
|
2019-05-28 13:49:26 +02:00
|
|
|
BaseQtVersion *QtVersionManager::qtVersionForQMakeBinary(const FilePath &qmakePath)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2017-01-11 14:43:48 +01:00
|
|
|
return version(Utils::equal(&BaseQtVersion::qmakeCommand, qmakePath));
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2013-08-29 14:11:29 +02:00
|
|
|
} // namespace QtVersion
|