QtSupport: Re-use ToolchainManager::isBetterToolchain()

... and upstream the additional check.

Change-Id: I6443987174f39e0953238cf2e8e07b4b1d8129bd
Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
Christian Kandeler
2024-08-08 15:47:24 +02:00
parent b6299edf1f
commit 7c28f17481
2 changed files with 24 additions and 20 deletions

View File

@@ -11,10 +11,11 @@
#include <coreplugin/icore.h>
#include <utils/algorithm.h>
#include <utils/environment.h>
#include <utils/fileutils.h>
#include <utils/persistentsettings.h>
#include <utils/qtcassert.h>
#include <utils/algorithm.h>
#include <nanotrace/nanotrace.h>
@@ -362,6 +363,26 @@ bool ToolchainManager::isBetterToolchain(
if (b2IsCcache)
return false;
// 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.
if (!bundle1.get(&Toolchain::compilerCommand).needsDevice()) {
const FilePaths envPathVar = Environment::systemEnvironment().path();
const auto toolchainIsInPath = [&envPathVar](const ToolchainBundle &b) {
return Utils::contains(b.toolchains(), [&envPathVar](const Toolchain *tc) {
return envPathVar.contains(tc->compilerCommand().parentDir());
});
};
const bool tc1IsInPath = toolchainIsInPath(bundle1);
const bool tc2IsInPath = toolchainIsInPath(bundle2);
if (tc1IsInPath) {
if (!tc2IsInPath)
return true;
} else if (tc2IsInPath) {
return false;
}
}
return path1.size() < path2.size();
}