Commit 9b465749 authored by Tobias Hunger's avatar Tobias Hunger
Browse files

Add toolchain autodetection based on config file

Add toolchains found in share/qtcreator/Nokia/toolChains.xml as
autodetected.
parent 5daa732e
......@@ -145,6 +145,11 @@ void ToolChain::setId(const QString &id)
m_d->m_id = id;
}
void ToolChain::setAutoDetected(bool autodetect)
{
m_d->m_autodetect = autodetect;
}
bool ToolChain::fromMap(const QVariantMap &data)
{
Q_ASSERT(!isAutoDetected());
......
......@@ -51,10 +51,11 @@ class ToolChainPrivate;
}
class Abi;
class HeaderPath;
class IOutputParser;
class ToolChainConfigWidget;
class ToolChainFactory;
class HeaderPath;
class ToolChainManager;
// --------------------------------------------------------------------------
// ToolChain
......@@ -109,8 +110,11 @@ protected:
virtual bool fromMap(const QVariantMap &data);
private:
void setAutoDetected(bool);
Internal::ToolChainPrivate *const m_d;
friend class ToolChainManager;
friend class ToolChainFactory;
};
......
......@@ -47,12 +47,13 @@
static const char *const TOOLCHAIN_DATA_KEY = "ToolChain.";
static const char *const TOOLCHAIN_COUNT_KEY = "ToolChain.Count";
static const char *const TOOLCHAIN_FILE_VERSION_KEY = "Version";
static const char *const TOOLCHAIN_FILENAME = "/toolChains.xml";
static QString settingsFileName()
{
ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance();
QFileInfo settingsLocation(pm->settings()->fileName());
return settingsLocation.absolutePath() + QLatin1String("/toolChains.xml");
return settingsLocation.absolutePath() + QLatin1String(TOOLCHAIN_FILENAME);
}
namespace ProjectExplorer {
......@@ -104,9 +105,44 @@ void ToolChainManager::restoreToolChains()
registerToolChain(tc);
}
// Restore user generated ToolChains:
restoreToolChains(settingsFileName(), false);
restoreToolChains(Core::ICore::instance()->resourcePath()
+ QLatin1String("/Nokia") + QLatin1String(TOOLCHAIN_FILENAME), true);
}
ToolChainManager::~ToolChainManager()
{
// Deregister toolchains
QList<ToolChain *> copy = m_d->m_toolChains;
foreach (ToolChain *tc, copy)
deregisterToolChain(tc);
delete m_d;
m_instance = 0;
}
void ToolChainManager::saveToolChains()
{
PersistentSettingsWriter writer;
writer.saveValue(QLatin1String(TOOLCHAIN_FILE_VERSION_KEY), 1);
int count = 0;
foreach (ToolChain *tc, m_d->m_toolChains) {
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);
writer.save(settingsFileName(), "QtCreatorToolChains");
}
void ToolChainManager::restoreToolChains(const QString &fileName, bool autoDetected)
{
PersistentSettingsReader reader;
const QString fileName = settingsFileName();
if (!reader.load(fileName))
return;
QVariantMap data = reader.restoreValues();
......@@ -116,6 +152,9 @@ void ToolChainManager::restoreToolChains()
if (version < 1)
return;
ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance();
QList<ToolChainFactory *> factories = pm->getObjects<ToolChainFactory>();
int count = data.value(QLatin1String(TOOLCHAIN_COUNT_KEY), 0).toInt();
for (int i = 0; i < count; ++i) {
const QString key = QString::fromLatin1(TOOLCHAIN_DATA_KEY) + QString::number(i);
......@@ -128,6 +167,8 @@ void ToolChainManager::restoreToolChains()
foreach (ToolChainFactory *f, factories) {
if (f->canRestore(tcMap)) {
if (ToolChain *tc = f->restore(tcMap)) {
tc->setAutoDetected(autoDetected);
registerToolChain(tc);
restored = true;
break;
......@@ -141,36 +182,6 @@ void ToolChainManager::restoreToolChains()
}
}
ToolChainManager::~ToolChainManager()
{
// Deregister toolchains
QList<ToolChain *> copy = m_d->m_toolChains;
foreach (ToolChain *tc, copy)
deregisterToolChain(tc);
delete m_d;
m_instance = 0;
}
void ToolChainManager::saveToolChains()
{
PersistentSettingsWriter writer;
writer.saveValue(QLatin1String(TOOLCHAIN_FILE_VERSION_KEY), 1);
int count = 0;
foreach (ToolChain *tc, m_d->m_toolChains) {
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);
writer.save(settingsFileName(), "QtCreatorToolChains");
}
QList<ToolChain *> ToolChainManager::toolChains() const
{
return m_d->m_toolChains;
......
......@@ -85,6 +85,8 @@ private:
// Make sure the this is only called after all
// ToolChain Factories are registered!
void restoreToolChains();
void restoreToolChains(const QString &fileName, bool autoDetected = false);
Internal::ToolChainManagerPrivate *const m_d;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment