Commit cb14fb0d authored by Tobias Hunger's avatar Tobias Hunger

Kits: Save several ToolChains per kit

BREAKS BACKWARD COMPATIBILITY OF TOOLCHAIN SETTINGS!

* Convert old ToolChainKitInformation to new version
* Store several toolchains in one kit (one per language)

Change-Id: Ia59a2ad067c57971ec34ce9b2e43758344443755
Reviewed-by: default avatarTim Jenssen <tim.jenssen@theqtcompany.com>
parent ce9ca1f0
......@@ -1200,8 +1200,8 @@ static bool equalKits(Kit *a, Kit *b)
{
if (QtSupport::QtKitInformation::qtVersion(a) != QtSupport::QtKitInformation::qtVersion(b))
return false;
ToolChain *atc = ToolChainKitInformation::toolChain(a);
ToolChain *btc = ToolChainKitInformation::toolChain(b);
ToolChain *atc = ToolChainKitInformation::toolChain(a, ToolChain::Language::Cxx);
ToolChain *btc = ToolChainKitInformation::toolChain(b, ToolChain::Language::Cxx);
if (atc == btc)
return true;
if (!atc || atc->typeId() != Constants::ANDROID_TOOLCHAIN_ID)
......@@ -1267,7 +1267,7 @@ void AndroidConfigurations::updateAutomaticKitList()
continue;
// Update code for 3.0 beta, which shipped with a bug for the debugger settings
ToolChain *tc =ToolChainKitInformation::toolChain(k);
ToolChain *tc = ToolChainKitInformation::toolChain(k, ToolChain::Language::Cxx);
if (tc && Debugger::DebuggerKitInformation::debuggerCommand(k) != tc->suggestedDebugger()) {
Debugger::DebuggerItem debugger;
debugger.setCommand(tc->suggestedDebugger());
......@@ -1341,7 +1341,7 @@ void AndroidConfigurations::updateAutomaticKitList()
newKits.removeAt(j);
existingKits.at(i)->makeSticky();
existingKits.removeAt(i);
ToolChainKitInformation::setToolChain(existingKit, ToolChainKitInformation::toolChain(newKit));
ToolChainKitInformation::setToolChain(existingKit, ToolChainKitInformation::toolChain(newKit, ToolChain::Language::Cxx));
KitManager::deleteKit(newKit);
j = newKits.count();
}
......@@ -1349,7 +1349,7 @@ void AndroidConfigurations::updateAutomaticKitList()
}
foreach (Kit *k, existingKits) {
ToolChain *tc = ToolChainKitInformation::toolChain(k);
ToolChain *tc = ToolChainKitInformation::toolChain(k, ToolChain::Language::Cxx);
QtSupport::BaseQtVersion *qtVersion = QtSupport::QtKitInformation::qtVersion(k);
if (tc && tc->typeId() == Constants::ANDROID_TOOLCHAIN_ID
&& tc->isValid()
......@@ -1362,7 +1362,7 @@ void AndroidConfigurations::updateAutomaticKitList()
}
foreach (Kit *kit, newKits) {
AndroidToolChain *tc = static_cast<AndroidToolChain *>(ToolChainKitInformation::toolChain(kit));
AndroidToolChain *tc = static_cast<AndroidToolChain *>(ToolChainKitInformation::toolChain(kit, ToolChain::Language::Cxx));
AndroidQtVersion *qt = static_cast<AndroidQtVersion *>(QtSupport::QtKitInformation::qtVersion(kit));
kit->setUnexpandedDisplayName(tr("Android for %1 (GCC %2, Qt %3)")
.arg(qt->targetArch())
......
......@@ -114,7 +114,7 @@ QList<Core::Id> AndroidDeployConfigurationFactory::availableCreationIds(Target *
if (!parent->project()->supportsKit(parent->kit()))
return ids;
ToolChain *tc = ToolChainKitInformation::toolChain(parent->kit());
ToolChain *tc = ToolChainKitInformation::toolChain(parent->kit(), ToolChain::Language::Cxx);
if (!tc || tc->targetAbi().osFlavor() != Abi::AndroidLinuxFlavor)
return ids;
......
......@@ -176,7 +176,7 @@ bool AndroidDeployQtStep::init(QList<const BuildStep *> &earlierSteps)
m_libdir = QLatin1String("lib");
if (info.cpuAbi.contains(QLatin1String("arm64-v8a")) ||
info.cpuAbi.contains(QLatin1String("x86_64"))) {
ProjectExplorer::ToolChain *tc = ProjectExplorer::ToolChainKitInformation::toolChain(target()->kit());
ProjectExplorer::ToolChain *tc = ProjectExplorer::ToolChainKitInformation::toolChain(target()->kit(), ToolChain::Language::Cxx);
if (tc && tc->targetAbi().wordWidth() == 64) {
m_appProcessBinaries << QLatin1String("/system/bin/app_process64");
m_libdir += QLatin1String("64");
......
......@@ -82,7 +82,7 @@ Core::Id AndroidGdbServerKitInformation::id()
bool AndroidGdbServerKitInformation::isAndroidKit(const Kit *kit)
{
QtSupport::BaseQtVersion *qt = QtSupport::QtKitInformation::qtVersion(kit);
ToolChain *tc = ToolChainKitInformation::toolChain(kit);
ToolChain *tc = ToolChainKitInformation::toolChain(kit, ToolChain::Language::Cxx);
if (qt && tc)
return qt->type() == QLatin1String(Constants::ANDROIDQT)
&& tc->typeId() == Constants::ANDROID_TOOLCHAIN_ID;
......@@ -102,7 +102,7 @@ void AndroidGdbServerKitInformation::setGdbSever(Kit *kit, const FileName &gdbSe
FileName AndroidGdbServerKitInformation::autoDetect(const Kit *kit)
{
ToolChain *tc = ToolChainKitInformation::toolChain(kit);
ToolChain *tc = ToolChainKitInformation::toolChain(kit, ToolChain::Language::Cxx);
if (!tc || tc->typeId() != Constants::ANDROID_TOOLCHAIN_ID)
return FileName();
auto atc = static_cast<AndroidToolChain *>(tc);
......
......@@ -68,7 +68,8 @@ void AutoTestUnitTests::initTestCase()
m_isQt4 = qtVersion->qtVersionString().startsWith(QLatin1Char('4'));
else
QSKIP("Could not figure out which Qt version is used for default kit.");
const ToolChain * const toolchain = ToolChainKitInformation::toolChain(allKits.first());
const ToolChain * const toolchain = ToolChainKitInformation::toolChain(allKits.first(),
ToolChain::Language::Cxx);
if (!toolchain)
QSKIP("This test requires that there is a kit with a toolchain.");
......
......@@ -120,11 +120,11 @@ bool MakeStep::init(QList<const BuildStep *> &earlierSteps)
if (!bc)
emit addTask(Task::buildConfigurationMissingTask());
ToolChain *tc = ToolChainKitInformation::toolChain(target()->kit());
if (!tc)
QList<ToolChain *> tcList = ToolChainKitInformation::toolChains(target()->kit());
if (tcList.isEmpty())
emit addTask(Task::compilerMissingTask());
if (!tc || !bc) {
if (tcList.isEmpty() || !bc) {
emitFaultyConfigurationMessage();
return false;
}
......@@ -140,7 +140,7 @@ bool MakeStep::init(QList<const BuildStep *> &earlierSteps)
Utils::Environment::setupEnglishOutput(&env);
pp->setEnvironment(env);
pp->setWorkingDirectory(bc->buildDirectory().toString());
pp->setCommand(tc ? tc->makeCommand(bc->environment()) : QLatin1String("make"));
pp->setCommand(tcList.at(0)->makeCommand(bc->environment()));
pp->setArguments(arguments);
pp->resolveAll();
......@@ -255,9 +255,9 @@ void MakeStepConfigWidget::updateDetails()
BuildConfiguration *bc = m_makeStep->buildConfiguration();
if (!bc)
bc = m_makeStep->target()->activeBuildConfiguration();
ToolChain *tc = ToolChainKitInformation::toolChain(m_makeStep->target()->kit());
QList<ToolChain *> tcList = ToolChainKitInformation::toolChains(m_makeStep->target()->kit());
if (tc) {
if (!tcList.isEmpty()) {
QString arguments = Utils::QtcProcess::joinArgs(m_makeStep->m_buildTargets);
Utils::QtcProcess::addArgs(&arguments, m_makeStep->additionalArguments());
......@@ -265,7 +265,7 @@ void MakeStepConfigWidget::updateDetails()
param.setMacroExpander(bc->macroExpander());
param.setEnvironment(bc->environment());
param.setWorkingDirectory(bc->buildDirectory().toString());
param.setCommand(tc->makeCommand(bc->environment()));
param.setCommand(tcList.at(0)->makeCommand(bc->environment()));
param.setArguments(arguments);
m_summaryText = param.summary(displayName());
} else {
......
......@@ -83,7 +83,7 @@ ClangStaticAnalyzerRunControl::ClangStaticAnalyzerRunControl(
QTC_ASSERT(buildConfiguration, return);
m_environment = buildConfiguration->environment();
ToolChain *toolChain = ToolChainKitInformation::toolChain(target->kit());
ToolChain *toolChain = ToolChainKitInformation::toolChain(target->kit(), ToolChain::Language::Cxx);
QTC_ASSERT(toolChain, return);
m_extraToolChainInfo.wordWidth = toolChain->targetAbi().wordWidth();
m_extraToolChainInfo.targetTriple = toolChain->originalTargetTriple();
......@@ -427,7 +427,7 @@ static QDebug operator<<(QDebug debug, const AnalyzeUnits &analyzeUnits)
static Core::Id toolchainType(ProjectExplorer::RunConfiguration *runConfiguration)
{
QTC_ASSERT(runConfiguration, return Core::Id());
return ToolChainKitInformation::toolChain(runConfiguration->target()->kit())->typeId();
return ToolChainKitInformation::toolChain(runConfiguration->target()->kit(), ToolChain::Language::Cxx)->typeId();
}
void ClangStaticAnalyzerRunControl::start()
......
......@@ -73,7 +73,7 @@ bool ClangStaticAnalyzerRunControlFactory::canRun(RunConfiguration *runConfigura
QTC_ASSERT(target, return false);
Kit *kit = target->kit();
QTC_ASSERT(kit, return false);
ToolChain *toolChain = ToolChainKitInformation::toolChain(kit);
ToolChain *toolChain = ToolChainKitInformation::toolChain(kit, ToolChain::Language::Cxx);
return toolChain;
}
......
......@@ -62,7 +62,8 @@ void ClangStaticAnalyzerUnitTests::initTestCase()
const QList<Kit *> allKits = KitManager::kits();
if (allKits.count() != 1)
QSKIP("This test requires exactly one kit to be present");
const ToolChain * const toolchain = ToolChainKitInformation::toolChain(allKits.first());
const ToolChain * const toolchain = ToolChainKitInformation::toolChain(allKits.first(),
ToolChain::Language::Cxx);
if (!toolchain)
QSKIP("This test requires that there is a kit with a toolchain.");
bool hasClangExecutable;
......
......@@ -187,7 +187,7 @@ QVariant CMakeGeneratorKitInformation::defaultValue(const Kit *k) const
}
if (Utils::HostOsInfo::isWindowsHost()) {
// *sigh* Windows with its zoo of incompatible stuff again...
ToolChain *tc = ToolChainKitInformation::toolChain(k);
ToolChain *tc = ToolChainKitInformation::toolChain(k, ToolChain::Language::Cxx);
if (tc && tc->typeId() == ProjectExplorer::Constants::MINGW_TOOLCHAIN_TYPEID) {
if (it == known.constEnd())
it = std::find_if(known.constBegin(), known.constEnd(),
......@@ -343,7 +343,7 @@ QVariant CMakeConfigurationKitInformation::defaultValue(const Kit *k) const
QList<Task> CMakeConfigurationKitInformation::validate(const Kit *k) const
{
const QtSupport::BaseQtVersion *const version = QtSupport::QtKitInformation::qtVersion(k);
const ToolChain *const tc = ToolChainKitInformation::toolChain(k);
const ToolChain *const tc = ToolChainKitInformation::toolChain(k, ToolChain::Language::Cxx);
const CMakeConfig config = configuration(k);
QByteArray qmakePath;
......
......@@ -251,7 +251,7 @@ void CMakeProject::parseCMakeOutput()
createGeneratedCodeModelSupport();
ToolChain *tc = ProjectExplorer::ToolChainKitInformation::toolChain(k);
ToolChain *tc = ProjectExplorer::ToolChainKitInformation::toolChain(k, ToolChain::Language::Cxx);
if (!tc) {
emit fileListChanged();
return;
......
......@@ -273,7 +273,7 @@ QString targetTriple(ProjectExplorer::Project *project, const Core::Id &toolchai
if (project) {
if (Target *target = project->activeTarget()) {
if (ToolChain *toolChain = ToolChainKitInformation::toolChain(target->kit()))
if (ToolChain *toolChain = ToolChainKitInformation::toolChain(target->kit(), ToolChain::Language::Cxx))
return toolChain->originalTargetTriple();
}
}
......@@ -361,7 +361,7 @@ void ProjectPartBuilder::createProjectPart(const QVector<ProjectFile> &theSource
QTC_ASSERT(part->project, return);
if (ProjectExplorer::Target *activeTarget = part->project->activeTarget()) {
if (ProjectExplorer::Kit *kit = activeTarget->kit()) {
if (ProjectExplorer::ToolChain *toolChain = ProjectExplorer::ToolChainKitInformation::toolChain(kit)) {
if (ProjectExplorer::ToolChain *toolChain = ProjectExplorer::ToolChainKitInformation::toolChain(kit, ProjectExplorer::ToolChain::Language::Cxx)) {
const QStringList flags = languageVersion >= ProjectPart::CXX98 ? m_cxxFlags
: m_cFlags;
evaluateProjectPartToolchain(part.data(),
......
......@@ -110,7 +110,7 @@ DebuggerKitChooser::DebuggerKitChooser(Mode mode, QWidget *parent)
if (!DebuggerKitInformation::isValidDebugger(k))
return false;
if (m_mode == LocalDebugging) {
const ToolChain *tc = ToolChainKitInformation::toolChain(k);
const ToolChain *tc = ToolChainKitInformation::toolChain(k, ToolChain::Language::Cxx);
return tc && tc->targetAbi().os() == m_hostAbi.os();
}
return true;
......
......@@ -57,7 +57,7 @@ DebuggerKitInformation::DebuggerKitInformation()
QVariant DebuggerKitInformation::defaultValue(const Kit *k) const
{
ToolChain *tc = ToolChainKitInformation::toolChain(k);
ToolChain *tc = ToolChainKitInformation::toolChain(k, ToolChain::Language::Cxx);
if (!tc)
return QVariant();
......@@ -87,7 +87,7 @@ void DebuggerKitInformation::setup(Kit *k)
// </valuemap>
const QVariant rawId = k->value(DebuggerKitInformation::id());
const ToolChain *tc = ToolChainKitInformation::toolChain(k);
const ToolChain *tc = ToolChainKitInformation::toolChain(k, ToolChain::Language::Cxx);
// Get the best of the available debugger matching the kit's toolchain.
// The general idea is to find an item that exactly matches what
......@@ -237,7 +237,7 @@ static unsigned debuggerConfigurationErrors(const Kit *k)
else if (!fi.isExecutable())
result |= DebuggerNotExecutable;
const ToolChain *tc = ToolChainKitInformation::toolChain(k);
const ToolChain *tc = ToolChainKitInformation::toolChain(k, ToolChain::Language::Cxx);
if (tc && item->matchTarget(tc->targetAbi()) == DebuggerItem::DoesNotMatch) {
// currently restricting the check to desktop devices, may be extended to all device types
const IDevice::ConstPtr device = DeviceKitInformation::device(k);
......
......@@ -568,7 +568,7 @@ static std::function<bool(const Kit *)> cdbMatcher(char wordWidth = 0)
return false;
}
if (wordWidth) {
const ToolChain *tc = ToolChainKitInformation::toolChain(k);
const ToolChain *tc = ToolChainKitInformation::toolChain(k, ToolChain::Language::Cxx);
return tc && wordWidth == tc->targetAbi().wordWidth();
}
return true;
......@@ -1103,14 +1103,14 @@ static Kit *guessKitFromParameters(const DebuggerRunParameters &rp)
if (!abis.isEmpty()) {
// Try exact abis.
kit = KitManager::find(KitMatcher([abis](const Kit *k) -> bool {
if (const ToolChain *tc = ToolChainKitInformation::toolChain(k))
if (const ToolChain *tc = ToolChainKitInformation::toolChain(k, ToolChain::Language::Cxx))
return abis.contains(tc->targetAbi()) && DebuggerKitInformation::isValidDebugger(k);
return false;
}));
if (!kit) {
// Or something compatible.
kit = KitManager::find(KitMatcher([abis](const Kit *k) -> bool {
if (const ToolChain *tc = ToolChainKitInformation::toolChain(k))
if (const ToolChain *tc = ToolChainKitInformation::toolChain(k, ToolChain::Language::Cxx))
foreach (const Abi &a, abis)
if (a.isCompatibleWith(tc->targetAbi()) && DebuggerKitInformation::isValidDebugger(k))
return true;
......@@ -2081,7 +2081,7 @@ DebuggerRunControl *DebuggerPluginPrivate::attachToRunningProcess(Kit *kit,
}
bool isWindows = false;
if (const ToolChain *tc = ToolChainKitInformation::toolChain(kit))
if (const ToolChain *tc = ToolChainKitInformation::toolChain(kit, ToolChain::Language::Cxx))
isWindows = tc->targetAbi().os() == Abi::WindowsOS;
if (isWindows && isWinProcessBeingDebugged(process.pid)) {
AsynchronousMessageBox::warning(tr("Process Already Under Debugger Control"),
......
......@@ -366,7 +366,7 @@ static DebuggerRunControl *doCreate(DebuggerRunParameters rp, RunConfiguration *
}
}
if (ToolChain *tc = ToolChainKitInformation::toolChain(kit))
if (ToolChain *tc = ToolChainKitInformation::toolChain(kit, ToolChain::Language::Cxx))
rp.toolChainAbi = tc->targetAbi();
if (false) {
......
......@@ -95,7 +95,7 @@ bool GenericMakeStep::init(QList<const BuildStep *> &earlierSteps)
if (!bc)
emit addTask(Task::buildConfigurationMissingTask());
ToolChain *tc = ToolChainKitInformation::toolChain(target()->kit());
ToolChain *tc = ToolChainKitInformation::toolChain(target()->kit(), ToolChain::Language::Cxx);
if (!tc)
emit addTask(Task::compilerMissingTask());
......@@ -170,7 +170,7 @@ QString GenericMakeStep::makeCommand(const Utils::Environment &environment) cons
{
QString command = m_makeCommand;
if (command.isEmpty()) {
ToolChain *tc = ToolChainKitInformation::toolChain(target()->kit());
ToolChain *tc = ToolChainKitInformation::toolChain(target()->kit(), ToolChain::Language::Cxx);
if (tc)
command = tc->makeCommand(environment);
else
......
......@@ -98,7 +98,7 @@ bool IosBuildStep::init(QList<const BuildStep *> &earlierSteps)
if (!bc)
emit addTask(Task::buildConfigurationMissingTask());
ToolChain *tc = ToolChainKitInformation::toolChain(target()->kit());
ToolChain *tc = ToolChainKitInformation::toolChain(target()->kit(), ToolChain::Language::Cxx);
if (!tc)
emit addTask(Task::compilerMissingTask());
......@@ -170,7 +170,7 @@ QStringList IosBuildStep::defaultArguments() const
{
QStringList res;
Kit *kit = target()->kit();
ToolChain *tc = ToolChainKitInformation::toolChain(kit);
ToolChain *tc = ToolChainKitInformation::toolChain(kit, ToolChain::Language::Cxx);
switch (target()->activeBuildConfiguration()->buildType()) {
case BuildConfiguration::Debug :
res << QLatin1String("-configuration") << QLatin1String("Debug");
......
......@@ -238,7 +238,7 @@ void IosConfigurations::updateAutomaticKitList()
// we do not compare the sdk (thus automatically upgrading it in place if a
// new Xcode is used). Change?
return DeviceTypeKitInformation::deviceTypeId(kit) == pDeviceType
&& ToolChainKitInformation::toolChain(kit) == pToolchain
&& ToolChainKitInformation::toolChain(kit, ToolChain::Language::Cxx) == pToolchain
&& QtKitInformation::qtVersion(kit) == qtVersion;
});
QTC_ASSERT(!resultingKits.contains(kit), continue);
......
......@@ -144,28 +144,20 @@ ToolChainKitInformation::ToolChainKitInformation()
QVariant ToolChainKitInformation::defaultValue(const Kit *k) const
{
Q_UNUSED(k);
QList<ToolChain *> tcList = ToolChainManager::toolChains();
if (tcList.isEmpty())
return QString();
Abi abi = Abi::hostAbi();
ToolChain *tc = Utils::findOr(tcList, tcList.first(),
Utils::equal(&ToolChain::targetAbi, abi));
return tc->id();
return defaultValue();
}
QList<Task> ToolChainKitInformation::validate(const Kit *k) const
{
QList<Task> result;
const ToolChain* toolchain = toolChain(k);
if (!toolchain) {
const QList<ToolChain*> tcList = toolChains(k);
if (tcList.isEmpty()) {
result << Task(Task::Error, ToolChainKitInformation::msgNoToolChainInTarget(),
Utils::FileName(), -1, Core::Id(Constants::TASK_CATEGORY_BUILDSYSTEM));
} else {
result << toolchain->validateKit(k);
foreach (ToolChain *tc, tcList)
result << tc->validateKit(k);
}
return result;
}
......@@ -173,12 +165,13 @@ QList<Task> ToolChainKitInformation::validate(const Kit *k) const
void ToolChainKitInformation::fix(Kit *k)
{
QTC_ASSERT(ToolChainManager::isLoaded(), return);
if (toolChain(k))
return;
qWarning("No tool chain set from kit \"%s\".",
qPrintable(k->displayName()));
setToolChain(k, 0); // make sure to clear out no longer known tool chains
foreach (ToolChain::Language l, ToolChain::allLanguages()) {
if (!toolChain(k, l)) {
qWarning("No tool chain set from kit \"%s\".",
qPrintable(k->displayName()));
setToolChain(k, l, nullptr); // make sure to clear out no longer known tool chains
}
}
}
void ToolChainKitInformation::setup(Kit *k)
......@@ -206,19 +199,19 @@ KitConfigWidget *ToolChainKitInformation::createConfigWidget(Kit *k) const
QString ToolChainKitInformation::displayNamePostfix(const Kit *k) const
{
ToolChain *tc = toolChain(k);
ToolChain *tc = toolChain(k, ToolChain::Language::Cxx);
return tc ? tc->displayName() : QString();
}
KitInformation::ItemList ToolChainKitInformation::toUserOutput(const Kit *k) const
{
ToolChain *tc = toolChain(k);
ToolChain *tc = toolChain(k, ToolChain::Language::Cxx);
return ItemList() << qMakePair(tr("Compiler"), tc ? tc->displayName() : tr("None"));
}
void ToolChainKitInformation::addToEnvironment(const Kit *k, Utils::Environment &env) const
{
ToolChain *tc = toolChain(k);
ToolChain *tc = toolChain(k, ToolChain::Language::Cxx);
if (tc)
tc->addToEnvironment(env);
}
......@@ -228,13 +221,13 @@ void ToolChainKitInformation::addToMacroExpander(Kit *kit, Utils::MacroExpander
// FIXME: Use better strings
expander->registerVariable("Compiler:Name", tr("Compiler"),
[this, kit]() -> QString {
const ToolChain *tc = toolChain(kit);
const ToolChain *tc = toolChain(kit, ToolChain::Language::Cxx);
return tc ? tc->displayName() : tr("None");
});
expander->registerVariable("Compiler:Executable", tr("Path to the compiler executable"),
[this, kit]() -> QString {
const ToolChain *tc = toolChain(kit);
const ToolChain *tc = toolChain(kit, ToolChain::Language::Cxx);
return tc ? tc->compilerCommand().toString() : QString();
});
}
......@@ -242,7 +235,7 @@ void ToolChainKitInformation::addToMacroExpander(Kit *kit, Utils::MacroExpander
IOutputParser *ToolChainKitInformation::createOutputParser(const Kit *k) const
{
ToolChain *tc = toolChain(k);
ToolChain *tc = toolChain(k, ToolChain::Language::Cxx);
if (tc)
return tc->outputParser();
return 0;
......@@ -253,17 +246,41 @@ Core::Id ToolChainKitInformation::id()
return "PE.Profile.ToolChain";
}
ToolChain *ToolChainKitInformation::toolChain(const Kit *k)
ToolChain *ToolChainKitInformation::toolChain(const Kit *k, ToolChain::Language l)
{
QTC_ASSERT(ToolChainManager::isLoaded(), return 0);
if (!k)
return 0;
return ToolChainManager::findToolChain(k->value(ToolChainKitInformation::id()).toByteArray());
QVariantMap value = readValue(k);
const QByteArray id = value.value(ToolChain::languageId(l), QByteArray()).toByteArray();
return ToolChainManager::findToolChain(id);
}
QList<ToolChain *> ToolChainKitInformation::toolChains(const Kit *k)
{
const QVariantMap value = readValue(k);
const QList<ToolChain *> tcList
= Utils::transform(ToolChain::allLanguages().toList(),
[&value](ToolChain::Language l) -> ToolChain * {
return ToolChainManager::findToolChain(value.value(ToolChain::languageId(l)).toByteArray());
});
return Utils::filtered(tcList, [](ToolChain *tc) { return tc; });
}
void ToolChainKitInformation::setToolChain(Kit *k, ToolChain *tc)
{
k->setValue(ToolChainKitInformation::id(), tc ? QString::fromUtf8(tc->id()) : QString());
QTC_ASSERT(tc, return);
setToolChain(k, tc->language(), tc);
}
void ToolChainKitInformation::setToolChain(Kit *k, ToolChain::Language l, ToolChain *tc)
{
if (l == ToolChain::Language::None)
return;
QVariantMap result = readValue(k);
result.insert(ToolChain::languageId(l), tc ? tc->id() : QByteArray());
k->setValue(id(), result);
}
QString ToolChainKitInformation::msgNoToolChainInTarget()
......@@ -271,6 +288,33 @@ QString ToolChainKitInformation::msgNoToolChainInTarget()
return tr("No compiler set in kit.");
}
QVariantMap ToolChainKitInformation::readValue(const Kit *k)
{
QVariant value = k->value(ToolChainKitInformation::id());
if (value.isNull())
value = defaultValue();
else if (value.type() == QVariant::String) {
// Legacy value: Convert...
QVariantMap tmp;
tmp.insert(ToolChain::languageDisplayName(ToolChain::Language::Cxx), value.toString());
value = tmp;
}
return value.toMap();
}
QVariant ToolChainKitInformation::defaultValue()
{
Abi abi = Abi::hostAbi();
QList<ToolChain *> tcList = Utils::filtered(ToolChainManager::toolChains(),
Utils::equal(&ToolChain::targetAbi, abi));
QVariantMap result;
foreach (ToolChain::Language l, ToolChain::allLanguages()) {
ToolChain *tc = Utils::findOrDefault(tcList, Utils::equal(&ToolChain::language, l));
result.insert(ToolChain::languageId(l), tc ? tc->id() : QByteArray());
}
return result;
}
void ToolChainKitInformation::kitsWereLoaded()
{
foreach (Kit *k, KitManager::kits())
......@@ -284,7 +328,7 @@ void ToolChainKitInformation::kitsWereLoaded()
void ToolChainKitInformation::toolChainUpdated(ToolChain *tc)
{
auto matcher = KitMatcher([tc, this](const Kit *k) { return toolChain(k) == tc; });
auto matcher = KitMatcher([tc, this](const Kit *k) { return toolChain(k, ToolChain::Language::Cxx) == tc; });
foreach (Kit *k, KitManager::matchingKits(matcher))
notifyAboutUpdate(k);
}
......
......@@ -25,17 +25,17 @@
#pragma once
#include "devicesupport/idevice.h"
#include "kitmanager.h"
#include "kit.h"
#include "toolchain.h"
#include "devicesupport/idevice.h"
#include <utils/environment.h>
#include <QVariant>
namespace ProjectExplorer {
class ToolChain;
class KitConfigWidget;
// --------------------------------------------------------------------------
......@@ -92,12 +92,16 @@ public:
IOutputParser *createOutputParser(const Kit *k) const override;
static Core::Id id();
static ToolChain *toolChain(const Kit *k);
static ToolChain *toolChain(const Kit *k, ToolChain::Language l);
static QList<ToolChain *> toolChains(const Kit *k);
static void setToolChain(Kit *k, ToolChain *tc);
static void setToolChain(Kit *k, ToolChain::Language l, ToolChain *tc);
static QString msgNoToolChainInTarget();
private:
static QVariantMap readValue(const Kit *k);
static QVariant defaultValue();
void kitsWereLoaded();
void toolChainUpdated(ProjectExplorer::ToolChain *tc);
void toolChainRemoved(ProjectExplorer::ToolChain *tc);
......
......@@ -171,7 +171,7 @@ void ToolChainInformationConfigWidget::refresh()
m_comboBox->setEnabled(m_comboBox->count() > 1 && !m_isReadOnly);
const int index = indexOf(ToolChainKitInformation::toolChain(m_kit));
const int index = indexOf(ToolChainKitInformation::toolChain(m_kit, ToolChain::Language::Cxx));
m_comboBox->setCurrentIndex(index);
m_ignoreChanges = false;
}
......@@ -203,7 +203,7 @@ void ToolChainInformationConfigWidget::currentToolChainChanged(int idx)