CompilationDBPM: Prefer kit toolchain

If there was no exact match of the compiler executable in the JSON
database with one of our toolchains, we used to use a random toolchain
that was of the same basic type as the compiler given in the JSON file,
with no regards to target ABI etc.
Instead, we now use the kit toolchain in that case if it has a matching
type, as that one is assumed to be the user's preference.

Fixes: QTCREATORBUG-31001
Change-Id: I2c69a7fb328a034fdf097d306f9673a245bf4772
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
Christian Kandeler
2024-06-05 14:23:02 +02:00
parent 451de5adb8
commit 2006ab3d23

View File

@@ -106,8 +106,10 @@ QString compilerPath(QString pathFlag)
Toolchain *toolchainFromFlags(const Kit *kit, const QStringList &flags, const Utils::Id &language) Toolchain *toolchainFromFlags(const Kit *kit, const QStringList &flags, const Utils::Id &language)
{ {
Toolchain * const kitToolchain = ToolchainKitAspect::toolchain(kit, language);
if (flags.empty()) if (flags.empty())
return ToolchainKitAspect::toolchain(kit, language); return kitToolchain;
// Try exact compiler match. // Try exact compiler match.
const Utils::FilePath compiler = Utils::FilePath::fromUserInput(compilerPath(flags.front())); const Utils::FilePath compiler = Utils::FilePath::fromUserInput(compilerPath(flags.front()));
@@ -118,6 +120,8 @@ Toolchain *toolchainFromFlags(const Kit *kit, const QStringList &flags, const Ut
return toolchain; return toolchain;
Utils::Id compilerId = getCompilerId(compiler.fileName()); Utils::Id compilerId = getCompilerId(compiler.fileName());
if (kitToolchain->isValid() && kitToolchain->typeId() == compilerId)
return kitToolchain;
if ((toolchain = toolchainFromCompilerId(compilerId, language))) if ((toolchain = toolchainFromCompilerId(compilerId, language)))
return toolchain; return toolchain;
@@ -126,13 +130,14 @@ Toolchain *toolchainFromFlags(const Kit *kit, const QStringList &flags, const Ut
compilerId = Utils::HostOsInfo::isWindowsHost() compilerId = Utils::HostOsInfo::isWindowsHost()
? ProjectExplorer::Constants::CLANG_CL_TOOLCHAIN_TYPEID ? ProjectExplorer::Constants::CLANG_CL_TOOLCHAIN_TYPEID
: ProjectExplorer::Constants::CLANG_TOOLCHAIN_TYPEID; : ProjectExplorer::Constants::CLANG_TOOLCHAIN_TYPEID;
if (kitToolchain->isValid() && kitToolchain->typeId() == compilerId)
return kitToolchain;
if ((toolchain = toolchainFromCompilerId(compilerId, language))) if ((toolchain = toolchainFromCompilerId(compilerId, language)))
return toolchain; return toolchain;
} }
toolchain = ToolchainKitAspect::toolchain(kit, language);
qWarning() << "No matching toolchain found, use the default."; qWarning() << "No matching toolchain found, use the default.";
return toolchain; return kitToolchain;
} }
void addDriverModeFlagIfNeeded(const Toolchain *toolchain, void addDriverModeFlagIfNeeded(const Toolchain *toolchain,