Commit f2122583 authored by Tobias Hunger's avatar Tobias Hunger

Kits: Reduce magic while improving setup

Task-number: QTCREATORBUG-8576
Task-number: QTCREATORBUG-8081

Change-Id: I9a6675a8ae97517f78bca026c4aa0edca82d606d
Reviewed-by: default avatarKai Koehne <kai.koehne@digia.com>
Reviewed-by: default avatarTobias Hunger <tobias.hunger@digia.com>
parent 4d775ac5
......@@ -199,6 +199,11 @@ DebuggerKitInformation::DebuggerItem DebuggerKitInformation::autoDetectItem(cons
return result;
}
void DebuggerKitInformation::setup(Kit *k)
{
setDebuggerItem(k, autoDetectItem(k));
}
// Check the configuration errors and return a flag mask. Provide a quick check and
// a verbose one with a list of errors.
......
......@@ -65,6 +65,8 @@ public:
QList<ProjectExplorer::Task> validate(const ProjectExplorer::Kit *k) const
{ return DebuggerKitInformation::validateDebugger(k); }
void setup(ProjectExplorer::Kit *k);
static QList<ProjectExplorer::Task> validateDebugger(const ProjectExplorer::Kit *k);
static bool isValidDebugger(const ProjectExplorer::Kit *k);
......
......@@ -197,6 +197,21 @@ void Kit::fix()
i->fix(this);
}
void Kit::setup()
{
KitGuard g(this);
QHash<Core::Id, QVariant> data = d->m_data;
for (int i = 0; i < 5; ++i) {
// Allow for some retries to settle down in a good configuration
// This is necessary for the Qt version to pick its preferred tool chain
// and that to pick a working debugger afterwards.
foreach (KitInformation *i, KitManager::instance()->kitInformation())
i->setup(this);
if (d->m_data == data)
break;
}
}
QString Kit::displayName() const
{
return d->m_displayName;
......
......@@ -66,7 +66,8 @@ public:
bool isValid() const;
QList<Task> validate() const;
void fix();
void fix(); // Fix the individual kit information.
void setup(); // Apply advanced magic(TM). Used only once on each kit during initial setup.
QString displayName() const;
void setDisplayName(const QString &name);
......
......@@ -181,6 +181,23 @@ void ToolChainKitInformation::fix(Kit *k)
setToolChain(k, 0); // make sure to clear out no longer known tool chains
}
void ToolChainKitInformation::setup(Kit *k)
{
const QString id = k->value(Core::Id(TOOLCHAIN_INFORMATION)).toString();
if (id.isEmpty())
return;
ToolChain *tc = ToolChainManager::instance()->findToolChain(id);
if (tc)
return;
// ID is not found: Might be an ABI string...
foreach (ToolChain *current, ToolChainManager::instance()->toolChains()) {
if (current->targetAbi().toString() == id)
return setToolChain(k, current);
}
}
KitConfigWidget *ToolChainKitInformation::createConfigWidget(Kit *k) const
{
return new Internal::ToolChainInformationConfigWidget(k);
......@@ -209,20 +226,8 @@ ToolChain *ToolChainKitInformation::toolChain(const Kit *k)
{
if (!k)
return 0;
const QString id = k->value(Core::Id(TOOLCHAIN_INFORMATION)).toString();
if (id.isEmpty())
return 0;
ToolChain *tc = ToolChainManager::instance()->findToolChain(id);
if (tc)
return tc;
// ID is not found: Might be an ABI string...
foreach (ToolChain *current, ToolChainManager::instance()->toolChains()) {
if (current->targetAbi().toString() == id)
return current;
}
return 0;
return ToolChainManager::instance()
->findToolChain(k->value(Core::Id(TOOLCHAIN_INFORMATION)).toString());
}
void ToolChainKitInformation::setToolChain(Kit *k, ToolChain *tc)
......
......@@ -104,6 +104,7 @@ public:
QList<Task> validate(const Kit *k) const;
void fix(Kit *k);
void setup(Kit *k);
KitConfigWidget *createConfigWidget(Kit *k) const;
......
......@@ -148,9 +148,11 @@ void KitManager::restoreKits()
QFileInfo kitFile(systemSettingsFile.absolutePath() + QLatin1String(KIT_FILENAME));
if (kitFile.exists()) {
KitList system = restoreKits(Utils::FileName(kitFile));
// make sure we mark these as autodetected!
foreach (Kit *k, system.kits)
// make sure we mark these as autodetected and run additional setup logic
foreach (Kit *k, system.kits) {
k->setAutoDetected(true);
k->setup();
}
// SDK kits are always considered to be up for validation since they might have been
// extended with additional information by creator in the meantime:
......@@ -202,6 +204,8 @@ void KitManager::restoreKits()
defaultKit->setAutoDetected(false);
defaultKit->setIconPath(QLatin1String(":///DESKTOP///"));
defaultKit->setup();
addKit(defaultKit);
}
......
......@@ -74,8 +74,12 @@ public:
virtual bool visibleIn(Kit *) { return true; }
virtual QVariant defaultValue(Kit *) const = 0;
// called to find issues with the kit
virtual QList<Task> validate(const Kit *) const = 0;
// called to fix issues with this kitinformation. Does not modify the rest of the kit.
virtual void fix(Kit *) { return; }
// called on initial setup of a kit.
virtual void setup(Kit *) { return; }
virtual ItemList toUserOutput(Kit *) const = 0;
......
......@@ -322,12 +322,14 @@ Kit *KitModel::markForAddition(Kit *baseKit)
beginInsertRows(index(m_manualRoot), pos, pos);
KitNode *node = createNode(m_manualRoot, 0);
Kit *k = node->widget->workingCopy();
KitGuard g(k);
if (baseKit) {
Kit *k = node->widget->workingCopy();
KitGuard g(k);
k->copyFrom(baseKit);
k->setAutoDetected(false); // Make sure we have a manual kit!
k->setDisplayName(tr("Clone of %1").arg(k->displayName()));
} else {
k->setup();
}
if (!m_defaultNode)
......@@ -335,7 +337,7 @@ Kit *KitModel::markForAddition(Kit *baseKit)
endInsertRows();
return node->widget->workingCopy();
return k;
}
QModelIndex KitModel::index(KitNode *node, int column) const
......
......@@ -84,7 +84,7 @@ QList<ProjectExplorer::Task> QmakeKitInformation::validate(const ProjectExplorer
return result;
}
void QmakeKitInformation::fix(ProjectExplorer::Kit *k)
void QmakeKitInformation::setup(ProjectExplorer::Kit *k)
{
QtSupport::BaseQtVersion *version = QtSupport::QtKitInformation::qtVersion(k);
if (!version)
......
......@@ -50,7 +50,7 @@ public:
QVariant defaultValue(ProjectExplorer::Kit *k) const;
QList<ProjectExplorer::Task> validate(const ProjectExplorer::Kit *k) const;
void fix(ProjectExplorer::Kit *k);
void setup(ProjectExplorer::Kit *k);
ProjectExplorer::KitConfigWidget *createConfigWidget(ProjectExplorer::Kit *k) const;
......
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