Improve detection of toolchain and debugger for desktop kits

In the situation where a cross-compilation tool chain has the same ABI
as the host.
Prefer toolchains and debuggers in PATH if the ABI matches. This is just
a short-term hack. It is not fail-safe, because either both tool chains
could be found somewhere in the PATH, or the "right" desktop tool chain
could not be in PATH, but manually added.
Anyhow, in many default setups this should improve the result. (In case
of failure the user can still change the kit manually.)
A better long term solution would be to make our ABI settings more
flexible.

Change-Id: I6ec5aaf45ef0b983cd949895dacdd5190f786219
Reviewed-by: hjk <hjk@qt.io>
Reviewed-by: Tobias Hunger <tobias.hunger@qt.io>
This commit is contained in:
Eike Ziller
2018-02-21 16:20:05 +01:00
parent 4adf04c79f
commit 16d1561794
3 changed files with 26 additions and 7 deletions

View File

@@ -88,7 +88,7 @@ public:
void setAbis(const QList<ProjectExplorer::Abi> &abis); void setAbis(const QList<ProjectExplorer::Abi> &abis);
void setAbi(const ProjectExplorer::Abi &abi); void setAbi(const ProjectExplorer::Abi &abi);
enum MatchLevel { DoesNotMatch, MatchesSomewhat, MatchesWell, MatchesPerfectly }; enum MatchLevel { DoesNotMatch, MatchesSomewhat, MatchesWell, MatchesPerfectly, MatchesPerfectlyInPath };
MatchLevel matchTarget(const ProjectExplorer::Abi &targetAbi) const; MatchLevel matchTarget(const ProjectExplorer::Abi &targetAbi) const;
QStringList abiNames() const; QStringList abiNames() const;

View File

@@ -101,13 +101,20 @@ void DebuggerKitInformation::setup(Kit *k)
DebuggerItem bestItem; DebuggerItem bestItem;
DebuggerItem::MatchLevel bestLevel = DebuggerItem::DoesNotMatch; DebuggerItem::MatchLevel bestLevel = DebuggerItem::DoesNotMatch;
const Environment systemEnvironment = Environment::systemEnvironment();
foreach (const DebuggerItem &item, DebuggerItemManager::debuggers()) { foreach (const DebuggerItem &item, DebuggerItemManager::debuggers()) {
DebuggerItem::MatchLevel level = DebuggerItem::DoesNotMatch; DebuggerItem::MatchLevel level = DebuggerItem::DoesNotMatch;
if (rawId.isNull()) { if (rawId.isNull()) {
// Initial setup of a kit. // Initial setup of a kit.
level = item.matchTarget(tcAbi); level = item.matchTarget(tcAbi);
// Hack to prefer a debugger from PATH (e.g. autodetected) over other matches.
// This improves the situation a bit if a cross-compilation tool chain has the
// same ABI as the host.
if (level == DebuggerItem::MatchesPerfectly
&& systemEnvironment.path().contains(item.command().parentDir().toString())) {
level = DebuggerItem::MatchesPerfectlyInPath;
}
} else if (rawId.type() == QVariant::String) { } else if (rawId.type() == QVariant::String) {
// New structure. // New structure.
if (item.id() == rawId) { if (item.id() == rawId) {

View File

@@ -92,11 +92,23 @@ void QmakeKitInformation::setup(Kit *k)
&& version->qtAbis().contains(t->targetAbi()); && version->qtAbis().contains(t->targetAbi());
}); });
if (!possibleTcs.isEmpty()) { if (!possibleTcs.isEmpty()) {
ToolChain *possibleTc const QList<ToolChain *> goodTcs = Utils::filtered(possibleTcs,
= Utils::findOr(possibleTcs, possibleTcs.last(), [&spec](const ToolChain *t) {
[&spec](const ToolChain *t) { return t->suggestedMkspecList().contains(spec); }); return t->suggestedMkspecList().contains(spec);
if (possibleTc) });
ToolChainKitInformation::setAllToolChainsToMatch(k, possibleTc); // Hack to prefer a tool chain from PATH (e.g. autodetected) over other matches.
// This improves the situation a bit if a cross-compilation tool chain has the
// same ABI as the host.
const Environment systemEnvironment = Environment::systemEnvironment();
ToolChain *bestTc = Utils::findOrDefault(goodTcs,
[&systemEnvironment](const ToolChain *t) {
return systemEnvironment.path().contains(t->compilerCommand().parentDir().toString());
});
if (!bestTc) {
bestTc = goodTcs.isEmpty() ? possibleTcs.last() : goodTcs.last();
}
if (bestTc)
ToolChainKitInformation::setAllToolChainsToMatch(k, bestTc);
} }
} }
} }