McuSupport: Fix crash when there is no proper desktop toolchain

Desktop toolchain is picked up from the registered toolchains
in Qt Creator, but it can be failed, for instance when there
is no toolchain for MinGW, and it causes crash for now. An
error handling is added to avoid it and inform to a user.

Task-number: QTCREATORBUG-28296
Change-Id: Ie16cd6c75df9be510bb49b765ad61ddf189a41db
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
Kwangsub Kim
2022-10-20 17:14:09 +02:00
committed by Rainer Keller
parent 642ba31f8b
commit d1a9cecf59

View File

@@ -10,6 +10,7 @@
#include "mcusupportconstants.h" #include "mcusupportconstants.h"
#include "mcusupportplugin.h" #include "mcusupportplugin.h"
#include "mcusupportsdk.h" #include "mcusupportsdk.h"
#include "mcusupporttr.h"
#include "mcutarget.h" #include "mcutarget.h"
#include <cmakeprojectmanager/cmakekitinformation.h> #include <cmakeprojectmanager/cmakekitinformation.h>
@@ -247,10 +248,19 @@ public:
auto cxxToolchain = toolchainPackage->toolChain( auto cxxToolchain = toolchainPackage->toolChain(
ProjectExplorer::Constants::CXX_LANGUAGE_ID); ProjectExplorer::Constants::CXX_LANGUAGE_ID);
configMap.insert("CMAKE_CXX_COMPILER", if (cToolchain && cxxToolchain) {
cxxToolchain->compilerCommand().toString().toLatin1()); configMap.insert("CMAKE_CXX_COMPILER",
configMap.insert("CMAKE_C_COMPILER", cxxToolchain->compilerCommand().toString().toLatin1());
cToolchain->compilerCommand().toString().toLatin1()); configMap.insert("CMAKE_C_COMPILER",
cToolchain->compilerCommand().toString().toLatin1());
} else {
printMessage(Tr::tr("Warning for target %1: invalid toolchain path (%2). "
"Update the toolchain in Edit > Preferences > Kits.")
.arg(generateKitNameFromTarget(mcuTarget),
toolchainPackage->path().toUserOutput()),
true);
}
} else { } else {
const FilePath cMakeToolchainFile = mcuTarget->toolChainFilePackage()->path(); const FilePath cMakeToolchainFile = mcuTarget->toolChainFilePackage()->path();