From 925a8a7a198692bd8abf0c66579c306ef88e3799 Mon Sep 17 00:00:00 2001 From: Rainer Keller Date: Fri, 14 Oct 2022 09:26:53 +0200 Subject: [PATCH] McuSupport: Give a reason for the toolchain being declared unsupported Change-Id: I95eb399cbaa199b442ce0d9596477a039dce4f30 Reviewed-by: Christian Stenger --- src/plugins/mcusupport/mcutargetfactory.cpp | 41 +++++++++++++++++---- src/plugins/mcusupport/mcutargetfactory.h | 2 +- 2 files changed, 34 insertions(+), 9 deletions(-) diff --git a/src/plugins/mcusupport/mcutargetfactory.cpp b/src/plugins/mcusupport/mcutargetfactory.cpp index 275a158e7f6..b7a8cffd054 100644 --- a/src/plugins/mcusupport/mcutargetfactory.cpp +++ b/src/plugins/mcusupport/mcutargetfactory.cpp @@ -4,6 +4,7 @@ #include "mcutargetfactory.h" #include "mcuhelpers.h" #include "mcupackage.h" +#include "mcusupportplugin.h" #include "mcusupportversiondetection.h" #include "mcutarget.h" #include "mcutargetdescription.h" @@ -16,11 +17,6 @@ namespace McuSupport::Internal { -bool isToolchainDescriptionValid(const McuTargetDescription::Toolchain &t) -{ - return !t.id.isEmpty() && !t.compiler.cmakeVar.isEmpty() && !t.file.cmakeVar.isEmpty(); -} - bool isDesktopToolchain(McuToolChainPackage::ToolChainType type) { return type == McuToolChainPackage::ToolChainType::MSVC @@ -80,7 +76,7 @@ QPair McuTargetFactory::createTargets(const McuTargetDescript const McuTarget::Platform platform( {desc.platform.id, desc.platform.name, desc.platform.vendor}); - auto *toolchain = createToolchain(desc.toolchain); + auto *toolchain = createToolchain(desc.toolchain, desc.sourceFile); McuPackagePtr toolchainFile{createPackage(desc.toolchain.file)}; //Skip target with incorrect toolchain dir or toolchain file. if (!toolchain || !toolchainFile) @@ -146,7 +142,9 @@ McuPackagePtr McuTargetFactory::createPackage(const PackageDescription &pkgDesc) } McuToolChainPackage *McuTargetFactory::createToolchain( - const McuTargetDescription::Toolchain &toolchain) + const McuTargetDescription::Toolchain &toolchain, + const Utils::FilePath &sourceFile + ) { const static QMap toolchainTypeMapping{ {"iar", McuToolChainPackage::ToolChainType::IAR}, @@ -175,9 +173,36 @@ McuToolChainPackage *McuTargetFactory::createToolchain( compilerDescription.cmakeVar, {}, createVersionDetection(compilerDescription.versionDetection)}; - } else if (!isToolchainDescriptionValid(toolchain)) + } + + // Validate toolchain and provide a proper error message + QString errorMessage; + + if (toolchain.id.isEmpty()) { + errorMessage = McuPackage::tr("the toolchain.id JSON entry is empty"); + } else if (!toolchainTypeMapping.contains(toolchain.id)) { + errorMessage = McuPackage::tr("the given toolchain \"%1\" is not supported").arg(toolchain.id); + } else if (toolchain.compiler.cmakeVar.isEmpty()) { + errorMessage = McuPackage::tr("the toolchain.compiler.cmakeVar JSON entry is empty"); + } else if (toolchain.file.cmakeVar.isEmpty()) { + errorMessage = McuPackage::tr("the toolchain.file.cmakeVar JSON entry is empty"); + } + + if (!errorMessage.isEmpty()) { toolchainType = McuToolChainPackage::ToolChainType::Unsupported; + if (toolchain.id.isEmpty()) { + printMessage(McuPackage::tr("Toolchain is invalid because %2 in file \"%3\".") + .arg(errorMessage).arg(sourceFile.toUserOutput()), + true); + } else { + printMessage(McuPackage::tr("Toolchain description for \"%1\" is invalid because %2 in file \"%3\".") + .arg(toolchain.id).arg(errorMessage).arg(sourceFile.toUserOutput()), + true); + } + + } + return new McuToolChainPackage{settingsHandler, compilerDescription.label, compilerDescription.defaultPath, diff --git a/src/plugins/mcusupport/mcutargetfactory.h b/src/plugins/mcusupport/mcutargetfactory.h index 16d09acef56..94451b4c07f 100644 --- a/src/plugins/mcusupport/mcutargetfactory.h +++ b/src/plugins/mcusupport/mcutargetfactory.h @@ -20,7 +20,7 @@ public: QPair createTargets(const McuTargetDescription &, const McuPackagePtr &qtForMCUsPackage) override; Packages createPackages(const McuTargetDescription &); - McuToolChainPackage *createToolchain(const McuTargetDescription::Toolchain &); + McuToolChainPackage *createToolchain(const McuTargetDescription::Toolchain &, const Utils::FilePath &sourceFile = Utils::FilePath()); McuPackagePtr createPackage(const PackageDescription &); private: