From 7c28f17481a24b4b0f50a27e09f4d33f1d460804 Mon Sep 17 00:00:00 2001 From: Christian Kandeler Date: Thu, 8 Aug 2024 15:47:24 +0200 Subject: [PATCH] QtSupport: Re-use ToolchainManager::isBetterToolchain() ... and upstream the additional check. Change-Id: I6443987174f39e0953238cf2e8e07b4b1d8129bd Reviewed-by: hjk --- .../projectexplorer/toolchainmanager.cpp | 23 ++++++++++++++++++- src/plugins/qtsupport/qtkitaspect.cpp | 21 ++--------------- 2 files changed, 24 insertions(+), 20 deletions(-) diff --git a/src/plugins/projectexplorer/toolchainmanager.cpp b/src/plugins/projectexplorer/toolchainmanager.cpp index d93817b9f0b..89d952a4f9f 100644 --- a/src/plugins/projectexplorer/toolchainmanager.cpp +++ b/src/plugins/projectexplorer/toolchainmanager.cpp @@ -11,10 +11,11 @@ #include +#include +#include #include #include #include -#include #include @@ -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(); } diff --git a/src/plugins/qtsupport/qtkitaspect.cpp b/src/plugins/qtsupport/qtkitaspect.cpp index e4dd95761be..3eaaecb7988 100644 --- a/src/plugins/qtsupport/qtkitaspect.cpp +++ b/src/plugins/qtsupport/qtkitaspect.cpp @@ -247,10 +247,7 @@ void QtKitAspectFactory::fix(Kit *k) return; // Prefer exact matches. - // TODO: We should probably prefer the compiler with the highest version number instead, - // but this information is currently not exposed by the Toolchain class. - const FilePaths envPathVar = Environment::systemEnvironment().path(); - sort(bundles, [version, &envPathVar](const ToolchainBundle &b1, const ToolchainBundle &b2) { + sort(bundles, [version](const ToolchainBundle &b1, const ToolchainBundle &b2) { const QVector &qtAbis = version->qtAbis(); const bool tc1ExactMatch = qtAbis.contains(b1.targetAbi()); const bool tc2ExactMatch = qtAbis.contains(b2.targetAbi()); @@ -270,21 +267,7 @@ void QtKitAspectFactory::fix(Kit *k) return false; } - const int prio1 = b1.get(&Toolchain::priority); - const int prio2 = b2.get(&Toolchain::priority); - if (prio1 > prio2) - return true; - if (prio1 < prio2) - 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. - const bool tc1IsInPath = envPathVar.contains( - b1.compilerCommand(CXX_LANGUAGE_ID).parentDir()); - const bool tc2IsInPath = envPathVar.contains( - b2.compilerCommand(CXX_LANGUAGE_ID).parentDir()); - return tc1IsInPath && !tc2IsInPath; + return ToolchainManager::isBetterToolchain(b1, b2); }); // TODO: Why is this not done during sorting?