ProjectExplorer: Introduce new ToolChainFactory::Candidate class

... to unify the bare-metal toolchains auto-detection algorithms.

Change-Id: I669420eac61fe1f0ab3f88ffaf2aa8e6bbad2102
Reviewed-by: hjk <hjk@qt.io>
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
This commit is contained in:
Denis Shienkov
2019-05-08 22:54:01 +03:00
parent a659cbc680
commit 5cf087ac5d
7 changed files with 26 additions and 25 deletions

View File

@@ -497,7 +497,7 @@ QList<ToolChain *> IarToolChainFactory::autoDetectToolchains(
const QList<ToolChain *> filtered = Utils::filtered(
alreadyKnown, [candidate](ToolChain *tc) {
return tc->typeId() == Constants::IAREW_TOOLCHAIN_TYPEID
&& tc->compilerCommand() == candidate.first
&& tc->compilerCommand() == candidate.compilerPath
&& (tc->language() == ProjectExplorer::Constants::C_LANGUAGE_ID
|| tc->language() == ProjectExplorer::Constants::CXX_LANGUAGE_ID);
});
@@ -519,16 +519,16 @@ QList<ToolChain *> IarToolChainFactory::autoDetectToolchain(
const Candidate &candidate, Core::Id language) const
{
const auto env = Environment::systemEnvironment();
const Macros macros = dumpPredefinedMacros(candidate.first, env.toStringList());
const Macros macros = dumpPredefinedMacros(candidate.compilerPath, env.toStringList());
if (macros.isEmpty())
return {};
const Abi abi = guessAbi(macros);
const auto tc = new IarToolChain(ToolChain::AutoDetection);
tc->setLanguage(language);
tc->setCompilerCommand(candidate.first);
tc->setCompilerCommand(candidate.compilerPath);
tc->setTargetAbi(abi);
tc->setDisplayName(buildDisplayName(abi.architecture(), language, candidate.second));
tc->setDisplayName(buildDisplayName(abi.architecture(), language, candidate.compilerVersion));
const auto languageVersion = ToolChain::languageVersion(language, macros);
tc->predefinedMacrosCache()->insert({}, {macros, languageVersion});

View File

@@ -119,10 +119,6 @@ public:
ProjectExplorer::ToolChain *restore(const QVariantMap &data) final;
private:
// File path + version.
using Candidate = QPair<Utils::FileName, QString>;
using Candidates = QVector<Candidate>;
QList<ProjectExplorer::ToolChain *> autoDetectToolchains(const Candidates &candidates,
const QList<ProjectExplorer::ToolChain *> &alreadyKnown) const;
QList<ProjectExplorer::ToolChain *> autoDetectToolchain(

View File

@@ -501,7 +501,7 @@ QList<ToolChain *> KeilToolchainFactory::autoDetectToolchains(
const QList<ToolChain *> filtered = Utils::filtered(
alreadyKnown, [candidate](ToolChain *tc) {
return tc->typeId() == Constants::IAREW_TOOLCHAIN_TYPEID
&& tc->compilerCommand() == candidate.first
&& tc->compilerCommand() == candidate.compilerPath
&& (tc->language() == ProjectExplorer::Constants::C_LANGUAGE_ID
|| tc->language() == ProjectExplorer::Constants::CXX_LANGUAGE_ID);
});
@@ -523,16 +523,16 @@ QList<ToolChain *> KeilToolchainFactory::autoDetectToolchain(
const Candidate &candidate, Core::Id language) const
{
const auto env = Environment::systemEnvironment();
const Macros macros = dumpPredefinedMacros(candidate.first, env.toStringList());
const Macros macros = dumpPredefinedMacros(candidate.compilerPath, env.toStringList());
if (macros.isEmpty())
return {};
const Abi abi = guessAbi(macros);
const auto tc = new KeilToolchain(ToolChain::AutoDetection);
tc->setLanguage(language);
tc->setCompilerCommand(candidate.first);
tc->setCompilerCommand(candidate.compilerPath);
tc->setTargetAbi(abi);
tc->setDisplayName(buildDisplayName(abi.architecture(), language, candidate.second));
tc->setDisplayName(buildDisplayName(abi.architecture(), language, candidate.compilerVersion));
const auto languageVersion = ToolChain::languageVersion(language, macros);
tc->predefinedMacrosCache()->insert({}, {macros, languageVersion});

View File

@@ -119,10 +119,6 @@ public:
ProjectExplorer::ToolChain *restore(const QVariantMap &data) final;
private:
// File path + version.
using Candidate = QPair<Utils::FileName, QString>;
using Candidates = QVector<Candidate>;
QList<ProjectExplorer::ToolChain *> autoDetectToolchains(const Candidates &candidates,
const QList<ProjectExplorer::ToolChain *> &alreadyKnown) const;
QList<ProjectExplorer::ToolChain *> autoDetectToolchain(

View File

@@ -436,7 +436,7 @@ QList<ToolChain *> SdccToolChainFactory::autoDetect(const QList<ToolChain *> &al
const auto env = Environment::systemEnvironment();
const auto macros = dumpPredefinedMacros(fn, env.toStringList(), {});
const QString version = guessVersion(macros);
const Candidate candidate(fn, version);
const Candidate candidate = {fn, version};
if (!candidates.contains(candidate))
candidates.push_back(candidate);
}
@@ -478,7 +478,7 @@ QList<ToolChain *> SdccToolChainFactory::autoDetectToolchains(
const QList<ToolChain *> filtered = Utils::filtered(
alreadyKnown, [candidate](ToolChain *tc) {
return tc->typeId() == Constants::SDCC_TOOLCHAIN_TYPEID
&& tc->compilerCommand() == candidate.first
&& tc->compilerCommand() == candidate.compilerPath
&& (tc->language() == ProjectExplorer::Constants::C_LANGUAGE_ID);
});
@@ -498,16 +498,16 @@ QList<ToolChain *> SdccToolChainFactory::autoDetectToolchain(
const Candidate &candidate, Core::Id language) const
{
const auto env = Environment::systemEnvironment();
const Macros macros = dumpPredefinedMacros(candidate.first, env.toStringList(), {});
const Macros macros = dumpPredefinedMacros(candidate.compilerPath, env.toStringList(), {});
if (macros.isEmpty())
return {};
const Abi abi = guessAbi(macros);
const auto tc = new SdccToolChain(ToolChain::AutoDetection);
tc->setLanguage(language);
tc->setCompilerCommand(candidate.first);
tc->setCompilerCommand(candidate.compilerPath);
tc->setTargetAbi(abi);
tc->setDisplayName(buildDisplayName(abi.architecture(), language, candidate.second));
tc->setDisplayName(buildDisplayName(abi.architecture(), language, candidate.compilerVersion));
const auto languageVersion = ToolChain::languageVersion(language, macros);
tc->predefinedMacrosCache()->insert({}, {macros, languageVersion});

View File

@@ -119,10 +119,6 @@ public:
ProjectExplorer::ToolChain *restore(const QVariantMap &data) final;
private:
// File path + version.
using Candidate = QPair<Utils::FileName, QString>;
using Candidates = QVector<Candidate>;
QList<ProjectExplorer::ToolChain *> autoDetectToolchains(const Candidates &candidates,
const QList<ProjectExplorer::ToolChain *> &alreadyKnown) const;
QList<ProjectExplorer::ToolChain *> autoDetectToolchain(

View File

@@ -211,6 +211,19 @@ public:
protected:
void setDisplayName(const QString &name) { m_displayName = name; }
class Candidate {
public:
Utils::FileName compilerPath;
QString compilerVersion;
bool operator==(const ToolChainFactory::Candidate &other) const {
return compilerPath == other.compilerPath
&& compilerVersion == other.compilerVersion;
}
};
using Candidates = QVector<Candidate>;
private:
QString m_displayName;
};