2011-02-01 18:36:00 +01:00
|
|
|
/**************************************************************************
|
|
|
|
|
**
|
|
|
|
|
** This file is part of Qt Creator
|
|
|
|
|
**
|
2012-01-26 18:33:46 +01:00
|
|
|
** Copyright (c) 2012 Nokia Corporation and/or its subsidiary(-ies).
|
2011-02-01 18:36:00 +01:00
|
|
|
**
|
2011-11-02 15:59:12 +01:00
|
|
|
** Contact: Nokia Corporation (qt-info@nokia.com)
|
2011-02-01 18:36:00 +01:00
|
|
|
**
|
|
|
|
|
**
|
|
|
|
|
** GNU Lesser General Public License Usage
|
|
|
|
|
**
|
2011-04-13 08:42:33 +02:00
|
|
|
** 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.
|
2011-02-01 18:36:00 +01:00
|
|
|
**
|
|
|
|
|
** In addition, as a special exception, Nokia gives you certain additional
|
2011-04-13 08:42:33 +02:00
|
|
|
** rights. These rights are described in the Nokia Qt LGPL Exception
|
2011-02-01 18:36:00 +01:00
|
|
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
|
|
|
**
|
2011-04-13 08:42:33 +02:00
|
|
|
** Other Usage
|
|
|
|
|
**
|
|
|
|
|
** Alternatively, this file may be used in accordance with the terms and
|
|
|
|
|
** conditions contained in a signed written agreement between you and Nokia.
|
|
|
|
|
**
|
2011-02-01 18:36:00 +01:00
|
|
|
** If you have questions regarding the use of this file, please contact
|
2011-11-02 15:59:12 +01:00
|
|
|
** Nokia at qt-info@nokia.com.
|
2011-02-01 18:36:00 +01:00
|
|
|
**
|
|
|
|
|
**************************************************************************/
|
|
|
|
|
|
|
|
|
|
#include "toolchainmanager.h"
|
2011-08-18 13:46:52 +02:00
|
|
|
#include "abi.h"
|
2011-02-01 18:36:00 +01:00
|
|
|
#include "toolchain.h"
|
|
|
|
|
|
2011-02-28 17:32:01 +01:00
|
|
|
#include <coreplugin/icore.h>
|
|
|
|
|
|
2011-02-01 18:36:00 +01:00
|
|
|
#include <extensionsystem/pluginmanager.h>
|
|
|
|
|
|
2011-08-16 10:45:23 +02:00
|
|
|
#include <utils/persistentsettings.h>
|
|
|
|
|
|
2011-02-01 18:36:00 +01:00
|
|
|
#include <QtCore/QCoreApplication>
|
2011-02-25 11:17:54 +01:00
|
|
|
#include <QtCore/QDir>
|
2011-02-28 17:32:01 +01:00
|
|
|
#include <QtCore/QSettings>
|
2011-03-30 15:15:15 +02:00
|
|
|
#include <QtGui/QMainWindow>
|
2011-02-28 17:32:01 +01:00
|
|
|
|
2011-05-10 15:19:38 +02:00
|
|
|
static const char TOOLCHAIN_DATA_KEY[] = "ToolChain.";
|
|
|
|
|
static const char TOOLCHAIN_COUNT_KEY[] = "ToolChain.Count";
|
|
|
|
|
static const char TOOLCHAIN_FILE_VERSION_KEY[] = "Version";
|
|
|
|
|
static const char DEFAULT_DEBUGGER_COUNT_KEY[] = "DefaultDebugger.Count";
|
|
|
|
|
static const char DEFAULT_DEBUGGER_ABI_KEY[] = "DefaultDebugger.Abi.";
|
|
|
|
|
static const char DEFAULT_DEBUGGER_PATH_KEY[] = "DefaultDebugger.Path.";
|
|
|
|
|
static const char TOOLCHAIN_FILENAME[] = "/toolChains.xml";
|
2011-02-01 18:36:00 +01:00
|
|
|
|
2011-08-16 10:45:23 +02:00
|
|
|
using Utils::PersistentSettingsWriter;
|
|
|
|
|
using Utils::PersistentSettingsReader;
|
|
|
|
|
|
2011-02-28 17:32:01 +01:00
|
|
|
static QString settingsFileName()
|
|
|
|
|
{
|
|
|
|
|
ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance();
|
|
|
|
|
QFileInfo settingsLocation(pm->settings()->fileName());
|
2011-03-01 16:34:02 +01:00
|
|
|
return settingsLocation.absolutePath() + QLatin1String(TOOLCHAIN_FILENAME);
|
2011-02-28 17:32:01 +01:00
|
|
|
}
|
2011-02-01 18:36:00 +01:00
|
|
|
|
|
|
|
|
namespace ProjectExplorer {
|
|
|
|
|
|
|
|
|
|
ToolChainManager *ToolChainManager::m_instance = 0;
|
|
|
|
|
|
|
|
|
|
namespace Internal {
|
|
|
|
|
|
|
|
|
|
// --------------------------------------------------------------------------
|
|
|
|
|
// ToolChainManagerPrivate
|
|
|
|
|
// --------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
class ToolChainManagerPrivate
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
QList<ToolChain *> m_toolChains;
|
2012-01-13 14:56:58 +01:00
|
|
|
QMap<QString, Utils::FileName> m_abiToDebugger;
|
2011-02-01 18:36:00 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
} // namespace Internal
|
|
|
|
|
|
|
|
|
|
// --------------------------------------------------------------------------
|
|
|
|
|
// ToolChainManager
|
|
|
|
|
// --------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
ToolChainManager *ToolChainManager::instance()
|
|
|
|
|
{
|
|
|
|
|
Q_ASSERT(m_instance);
|
|
|
|
|
return m_instance;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ToolChainManager::ToolChainManager(QObject *parent) :
|
|
|
|
|
QObject(parent),
|
2011-09-16 13:10:06 +02:00
|
|
|
d(new Internal::ToolChainManagerPrivate)
|
2011-02-01 18:36:00 +01:00
|
|
|
{
|
|
|
|
|
Q_ASSERT(!m_instance);
|
|
|
|
|
m_instance = this;
|
2011-02-28 17:32:01 +01:00
|
|
|
connect(Core::ICore::instance(), SIGNAL(saveSettingsRequested()),
|
|
|
|
|
this, SLOT(saveToolChains()));
|
2011-04-12 10:53:42 +02:00
|
|
|
connect(this, SIGNAL(toolChainAdded(ProjectExplorer::ToolChain*)),
|
|
|
|
|
this, SIGNAL(toolChainsChanged()));
|
|
|
|
|
connect(this, SIGNAL(toolChainRemoved(ProjectExplorer::ToolChain*)),
|
|
|
|
|
this, SIGNAL(toolChainsChanged()));
|
|
|
|
|
connect(this, SIGNAL(toolChainUpdated(ProjectExplorer::ToolChain*)),
|
|
|
|
|
this, SIGNAL(toolChainsChanged()));
|
2011-02-01 18:36:00 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ToolChainManager::restoreToolChains()
|
|
|
|
|
{
|
2011-03-31 10:13:35 +02:00
|
|
|
// Restore SDK settings first
|
2012-01-24 15:36:40 +01:00
|
|
|
QFileInfo systemSettingsFile(Core::ICore::settings(QSettings::SystemScope)->fileName());
|
2011-11-23 16:56:50 +01:00
|
|
|
restoreToolChains(systemSettingsFile.absolutePath() + QLatin1String(TOOLCHAIN_FILENAME), true);
|
2011-03-31 10:13:35 +02:00
|
|
|
|
|
|
|
|
// Then auto detect
|
2011-02-28 17:32:01 +01:00
|
|
|
ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance();
|
|
|
|
|
QList<ToolChainFactory *> factories = pm->getObjects<ToolChainFactory>();
|
2011-03-16 17:59:43 +01:00
|
|
|
// Autodetect tool chains:
|
2011-02-01 18:36:00 +01:00
|
|
|
foreach (ToolChainFactory *f, factories) {
|
|
|
|
|
QList<ToolChain *> tcs = f->autoDetect();
|
|
|
|
|
foreach (ToolChain *tc, tcs)
|
|
|
|
|
registerToolChain(tc);
|
|
|
|
|
}
|
|
|
|
|
|
2011-03-31 10:13:35 +02:00
|
|
|
// Then restore user settings
|
2011-03-01 16:34:02 +01:00
|
|
|
restoreToolChains(settingsFileName(), false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ToolChainManager::~ToolChainManager()
|
|
|
|
|
{
|
2011-03-16 17:59:43 +01:00
|
|
|
// Deregister tool chains
|
2011-09-16 13:10:06 +02:00
|
|
|
QList<ToolChain *> copy = d->m_toolChains;
|
2011-03-01 16:34:02 +01:00
|
|
|
foreach (ToolChain *tc, copy)
|
|
|
|
|
deregisterToolChain(tc);
|
|
|
|
|
|
2011-09-16 13:10:06 +02:00
|
|
|
delete d;
|
2011-03-01 16:34:02 +01:00
|
|
|
m_instance = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ToolChainManager::saveToolChains()
|
|
|
|
|
{
|
|
|
|
|
PersistentSettingsWriter writer;
|
|
|
|
|
writer.saveValue(QLatin1String(TOOLCHAIN_FILE_VERSION_KEY), 1);
|
|
|
|
|
|
|
|
|
|
int count = 0;
|
2011-09-16 13:10:06 +02:00
|
|
|
foreach (ToolChain *tc, d->m_toolChains) {
|
2011-03-01 16:34:02 +01:00
|
|
|
if (!tc->isAutoDetected() && tc->isValid()) {
|
|
|
|
|
QVariantMap tmp = tc->toMap();
|
|
|
|
|
if (tmp.isEmpty())
|
|
|
|
|
continue;
|
|
|
|
|
writer.saveValue(QString::fromLatin1(TOOLCHAIN_DATA_KEY) + QString::number(count), tmp);
|
|
|
|
|
++count;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
writer.saveValue(QLatin1String(TOOLCHAIN_COUNT_KEY), count);
|
2012-01-24 15:36:40 +01:00
|
|
|
writer.save(settingsFileName(), QLatin1String("QtCreatorToolChains"), Core::ICore::mainWindow());
|
2011-03-31 10:13:35 +02:00
|
|
|
|
|
|
|
|
// Do not save default debuggers! Those are set by the SDK!
|
2011-03-01 16:34:02 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ToolChainManager::restoreToolChains(const QString &fileName, bool autoDetected)
|
|
|
|
|
{
|
2011-02-28 17:32:01 +01:00
|
|
|
PersistentSettingsReader reader;
|
|
|
|
|
if (!reader.load(fileName))
|
|
|
|
|
return;
|
|
|
|
|
QVariantMap data = reader.restoreValues();
|
|
|
|
|
|
|
|
|
|
// Check version:
|
|
|
|
|
int version = data.value(QLatin1String(TOOLCHAIN_FILE_VERSION_KEY), 0).toInt();
|
|
|
|
|
if (version < 1)
|
2011-02-01 18:36:00 +01:00
|
|
|
return;
|
|
|
|
|
|
2011-03-31 10:13:35 +02:00
|
|
|
// Read default debugger settings (if any)
|
|
|
|
|
int count = data.value(QLatin1String(DEFAULT_DEBUGGER_COUNT_KEY)).toInt();
|
|
|
|
|
for (int i = 0; i < count; ++i) {
|
|
|
|
|
const QString abiKey = QString::fromLatin1(DEFAULT_DEBUGGER_ABI_KEY) + QString::number(i);
|
|
|
|
|
if (!data.contains(abiKey))
|
|
|
|
|
continue;
|
|
|
|
|
const QString pathKey = QString::fromLatin1(DEFAULT_DEBUGGER_PATH_KEY) + QString::number(i);
|
2011-05-13 12:25:28 +02:00
|
|
|
if (!data.contains(pathKey))
|
2011-03-31 10:13:35 +02:00
|
|
|
continue;
|
2012-01-13 14:56:58 +01:00
|
|
|
d->m_abiToDebugger.insert(data.value(abiKey).toString(),
|
|
|
|
|
Utils::FileName::fromString(data.value(pathKey).toString()));
|
2011-03-31 10:13:35 +02:00
|
|
|
}
|
|
|
|
|
|
2011-03-01 16:34:02 +01:00
|
|
|
ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance();
|
|
|
|
|
QList<ToolChainFactory *> factories = pm->getObjects<ToolChainFactory>();
|
|
|
|
|
|
2011-03-31 10:13:35 +02:00
|
|
|
count = data.value(QLatin1String(TOOLCHAIN_COUNT_KEY), 0).toInt();
|
2011-02-28 17:32:01 +01:00
|
|
|
for (int i = 0; i < count; ++i) {
|
|
|
|
|
const QString key = QString::fromLatin1(TOOLCHAIN_DATA_KEY) + QString::number(i);
|
|
|
|
|
if (!data.contains(key))
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
const QVariantMap tcMap = data.value(key).toMap();
|
|
|
|
|
|
2011-02-25 11:17:54 +01:00
|
|
|
bool restored = false;
|
2011-02-01 18:36:00 +01:00
|
|
|
foreach (ToolChainFactory *f, factories) {
|
2011-02-28 17:32:01 +01:00
|
|
|
if (f->canRestore(tcMap)) {
|
|
|
|
|
if (ToolChain *tc = f->restore(tcMap)) {
|
2011-03-01 16:34:02 +01:00
|
|
|
tc->setAutoDetected(autoDetected);
|
|
|
|
|
|
2011-02-25 11:17:54 +01:00
|
|
|
registerToolChain(tc);
|
|
|
|
|
restored = true;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2011-02-01 18:36:00 +01:00
|
|
|
}
|
2011-02-25 11:17:54 +01:00
|
|
|
if (!restored)
|
2011-03-16 17:59:43 +01:00
|
|
|
qWarning("Warning: Unable to restore manual tool chain '%s' stored in %s.",
|
2011-02-28 17:32:01 +01:00
|
|
|
qPrintable(ToolChainFactory::idFromMap(tcMap)),
|
|
|
|
|
qPrintable(QDir::toNativeSeparators(fileName)));
|
2011-02-01 18:36:00 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QList<ToolChain *> ToolChainManager::toolChains() const
|
|
|
|
|
{
|
2011-09-16 13:10:06 +02:00
|
|
|
return d->m_toolChains;
|
2011-02-01 18:36:00 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QList<ToolChain *> ToolChainManager::findToolChains(const Abi &abi) const
|
|
|
|
|
{
|
|
|
|
|
QList<ToolChain *> result;
|
2011-09-16 13:10:06 +02:00
|
|
|
foreach (ToolChain *tc, d->m_toolChains) {
|
2011-02-01 18:36:00 +01:00
|
|
|
Abi targetAbi = tc->targetAbi();
|
|
|
|
|
if (targetAbi.isCompatibleWith(abi))
|
|
|
|
|
result.append(tc);
|
|
|
|
|
}
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ToolChain *ToolChainManager::findToolChain(const QString &id) const
|
|
|
|
|
{
|
2011-09-16 13:10:06 +02:00
|
|
|
foreach (ToolChain *tc, d->m_toolChains) {
|
2011-02-01 18:36:00 +01:00
|
|
|
if (tc->id() == id)
|
|
|
|
|
return tc;
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2012-01-13 14:56:58 +01:00
|
|
|
Utils::FileName ToolChainManager::defaultDebugger(const Abi &abi) const
|
2011-03-31 10:13:35 +02:00
|
|
|
{
|
2011-09-16 13:10:06 +02:00
|
|
|
return d->m_abiToDebugger.value(abi.toString());
|
2011-03-31 10:13:35 +02:00
|
|
|
}
|
|
|
|
|
|
2011-03-24 13:27:26 +01:00
|
|
|
void ToolChainManager::notifyAboutUpdate(ProjectExplorer::ToolChain *tc)
|
|
|
|
|
{
|
2011-09-16 13:10:06 +02:00
|
|
|
if (!tc || !d->m_toolChains.contains(tc))
|
2011-03-24 13:27:26 +01:00
|
|
|
return;
|
|
|
|
|
emit toolChainUpdated(tc);
|
|
|
|
|
}
|
|
|
|
|
|
2011-03-25 17:28:42 +01:00
|
|
|
bool ToolChainManager::registerToolChain(ToolChain *tc)
|
2011-02-01 18:36:00 +01:00
|
|
|
{
|
2011-09-16 13:10:06 +02:00
|
|
|
if (!tc || d->m_toolChains.contains(tc))
|
2011-03-25 17:28:42 +01:00
|
|
|
return true;
|
2011-09-16 13:10:06 +02:00
|
|
|
foreach (ToolChain *current, d->m_toolChains) {
|
2011-02-01 18:36:00 +01:00
|
|
|
if (*tc == *current)
|
2011-03-25 17:28:42 +01:00
|
|
|
return false;
|
2011-02-01 18:36:00 +01:00
|
|
|
}
|
|
|
|
|
|
2011-09-16 13:10:06 +02:00
|
|
|
d->m_toolChains.append(tc);
|
2011-02-01 18:36:00 +01:00
|
|
|
emit toolChainAdded(tc);
|
2011-03-25 17:28:42 +01:00
|
|
|
return true;
|
2011-02-01 18:36:00 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ToolChainManager::deregisterToolChain(ToolChain *tc)
|
|
|
|
|
{
|
2011-09-16 13:10:06 +02:00
|
|
|
if (!tc || !d->m_toolChains.contains(tc))
|
2011-02-01 18:36:00 +01:00
|
|
|
return;
|
2011-09-16 13:10:06 +02:00
|
|
|
d->m_toolChains.removeOne(tc);
|
2011-02-01 18:36:00 +01:00
|
|
|
emit toolChainRemoved(tc);
|
|
|
|
|
delete tc;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace ProjectExplorer
|