From 250f4fb72f9706a0af29e78e4ab2142f22c65b57 Mon Sep 17 00:00:00 2001 From: Erik Verbruggen Date: Tue, 1 Feb 2022 16:51:27 +0100 Subject: [PATCH] McuSupport: Move McuDependenciesKitAspectWidget into its own file Change-Id: I41a2a6ec48c5c02ca655cb09ad08080d73d336fe Reviewed-by: Alessandro Portale Reviewed-by: --- src/plugins/mcusupport/CMakeLists.txt | 1 + src/plugins/mcusupport/mcukitinformation.cpp | 133 +++++++++++++++++++ src/plugins/mcusupport/mcukitinformation.h | 53 ++++++++ src/plugins/mcusupport/mcusupport.qbs | 4 +- src/plugins/mcusupport/mcusupportoptions.cpp | 96 +------------ src/plugins/mcusupport/mcusupportoptions.h | 24 +--- src/plugins/mcusupport/mcusupportplugin.cpp | 1 + 7 files changed, 193 insertions(+), 119 deletions(-) create mode 100644 src/plugins/mcusupport/mcukitinformation.cpp create mode 100644 src/plugins/mcusupport/mcukitinformation.h diff --git a/src/plugins/mcusupport/CMakeLists.txt b/src/plugins/mcusupport/CMakeLists.txt index bb2b98738de..261dd6e0b52 100644 --- a/src/plugins/mcusupport/CMakeLists.txt +++ b/src/plugins/mcusupport/CMakeLists.txt @@ -2,6 +2,7 @@ add_qtc_plugin(McuSupport DEPENDS Qt5::Core PLUGIN_DEPENDS Core BareMetal ProjectExplorer Debugger CMakeProjectManager QtSupport SOURCES + mcukitinformation.cpp mcukitinformation.h mcusupport.qrc mcusupport_global.h mcusupportconstants.h diff --git a/src/plugins/mcusupport/mcukitinformation.cpp b/src/plugins/mcusupport/mcukitinformation.cpp new file mode 100644 index 00000000000..f72fef1f2e7 --- /dev/null +++ b/src/plugins/mcusupport/mcukitinformation.cpp @@ -0,0 +1,133 @@ +/**************************************************************************** +** +** Copyright (C) 2021 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of Qt Creator. +** +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 as published by the Free Software +** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +****************************************************************************/ + +#include "mcukitinformation.h" + +#include + +using namespace ProjectExplorer; + +namespace { + +class McuDependenciesKitAspectWidget final : public KitAspectWidget +{ +public: + McuDependenciesKitAspectWidget(Kit *workingCopy, const KitAspect *ki) + : KitAspectWidget(workingCopy, ki) + {} + + void makeReadOnly() override {} + void refresh() override {} + void addToLayout(Utils::LayoutBuilder &) override {} +}; + +} // anonymous namespace + +namespace McuSupport { +namespace Internal { + +McuDependenciesKitAspect::McuDependenciesKitAspect() +{ + setObjectName(QLatin1String("McuDependenciesKitAspect")); + setId(McuDependenciesKitAspect::id()); + setDisplayName(tr("MCU Dependencies")); + setDescription(tr("Paths to 3rd party dependencies")); + setPriority(28500); +} + +Tasks McuDependenciesKitAspect::validate(const Kit *k) const +{ + Tasks result; + QTC_ASSERT(k, return result); + + const QVariant checkFormat = k->value(McuDependenciesKitAspect::id()); + if (!checkFormat.isNull() && !checkFormat.canConvert(QVariant::List)) + return { BuildSystemTask(Task::Error, tr("The MCU dependencies setting value is invalid.")) }; + + const QVariant envStringList = k->value(EnvironmentKitAspect::id()); + if (!envStringList.isNull() && !envStringList.canConvert(QVariant::List)) + return { BuildSystemTask(Task::Error, tr("The environment setting value is invalid.")) }; + + const auto environment = Utils::NameValueDictionary(envStringList.toStringList()); + for (const auto &dependency: dependencies(k)) { + if (!environment.hasKey(dependency.name)) { + result << BuildSystemTask(Task::Warning, tr("Environment variable %1 not defined.").arg(dependency.name)); + } else { + const auto path = Utils::FilePath::fromUserInput( + environment.value(dependency.name) + "/" + dependency.value); + if (!path.exists()) { + result << BuildSystemTask(Task::Warning, tr("%1 not found.").arg(path.toUserOutput())); + } + } + } + + return result; +} + +void McuDependenciesKitAspect::fix(Kit *k) +{ + QTC_ASSERT(k, return); + + const QVariant variant = k->value(McuDependenciesKitAspect::id()); + if (!variant.isNull() && !variant.canConvert(QVariant::List)) { + qWarning("Kit \"%s\" has a wrong mcu dependencies value set.", qPrintable(k->displayName())); + setDependencies(k, Utils::NameValueItems()); + } +} + +KitAspectWidget *McuDependenciesKitAspect::createConfigWidget(Kit *k) const +{ + QTC_ASSERT(k, return nullptr); + return new McuDependenciesKitAspectWidget(k, this); +} + +KitAspect::ItemList McuDependenciesKitAspect::toUserOutput(const Kit *k) const +{ + Q_UNUSED(k) + + return {}; +} + +Utils::Id McuDependenciesKitAspect::id() +{ + return "PE.Profile.McuDependencies"; +} + + +Utils::NameValueItems McuDependenciesKitAspect::dependencies(const Kit *k) +{ + if (k) + return Utils::NameValueItem::fromStringList(k->value(McuDependenciesKitAspect::id()).toStringList()); + return Utils::NameValueItems(); +} + +void McuDependenciesKitAspect::setDependencies(Kit *k, const Utils::NameValueItems &dependencies) +{ + if (k) + k->setValue(McuDependenciesKitAspect::id(), Utils::NameValueItem::toStringList(dependencies)); +} + +} // namespace Internal +} // namespace McuSupport diff --git a/src/plugins/mcusupport/mcukitinformation.h b/src/plugins/mcusupport/mcukitinformation.h new file mode 100644 index 00000000000..85c811ad668 --- /dev/null +++ b/src/plugins/mcusupport/mcukitinformation.h @@ -0,0 +1,53 @@ +/**************************************************************************** +** +** Copyright (C) 2021 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of Qt Creator. +** +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 as published by the Free Software +** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +****************************************************************************/ + +#pragma once + +#include + +namespace McuSupport { +namespace Internal { + +class McuDependenciesKitAspect final : public ProjectExplorer::KitAspect +{ + Q_OBJECT + +public: + McuDependenciesKitAspect(); + + ProjectExplorer::Tasks validate(const ProjectExplorer::Kit *k) const override; + void fix(ProjectExplorer::Kit *k) override; + + ProjectExplorer::KitAspectWidget *createConfigWidget(ProjectExplorer::Kit *k) const override; + + ItemList toUserOutput(const ProjectExplorer::Kit *k) const override; + + static Utils::Id id(); + static Utils::NameValueItems dependencies(const ProjectExplorer::Kit *k); + static void setDependencies(ProjectExplorer::Kit *k, const Utils::NameValueItems &dependencies); +}; + +} // namespace Internal +} // namespace McuSupport diff --git a/src/plugins/mcusupport/mcusupport.qbs b/src/plugins/mcusupport/mcusupport.qbs index f18f13a52ea..e8529e24649 100644 --- a/src/plugins/mcusupport/mcusupport.qbs +++ b/src/plugins/mcusupport/mcusupport.qbs @@ -35,6 +35,8 @@ QtcPlugin { "mcusupportversiondetection.cpp", "mcusupportversiondetection.h", "mcusupportcmakemapper.h", - "mcusupportcmakemapper.cpp" + "mcusupportcmakemapper.cpp", + "mcukitinformation.cpp", + "mcukitinformation.h" ] } diff --git a/src/plugins/mcusupport/mcusupportoptions.cpp b/src/plugins/mcusupport/mcusupportoptions.cpp index ec23b7ad084..d7ef38fdd1d 100644 --- a/src/plugins/mcusupport/mcusupportoptions.cpp +++ b/src/plugins/mcusupport/mcusupportoptions.cpp @@ -23,6 +23,7 @@ ** ****************************************************************************/ +#include "mcukitinformation.h" #include "mcupackage.h" #include "mcusupportconstants.h" #include "mcusupportoptions.h" @@ -1065,100 +1066,5 @@ void McuSupportOptions::fixExistingKits() delete qtForMCUsPackage; } -class McuDependenciesKitAspectWidget final : public KitAspectWidget -{ - Q_DECLARE_TR_FUNCTIONS(McuSupport::McuDependenciesKitAspect) - -public: - McuDependenciesKitAspectWidget(Kit *workingCopy, const KitAspect *ki) - : KitAspectWidget(workingCopy, ki) - {} - - void makeReadOnly() override {} - void refresh() override {} - void addToLayout(Utils::LayoutBuilder &) override {} -}; - } // Internal - -McuDependenciesKitAspect::McuDependenciesKitAspect() -{ - setObjectName(QLatin1String("McuDependenciesKitAspect")); - setId(McuDependenciesKitAspect::id()); - setDisplayName(tr("MCU Dependencies")); - setDescription(tr("Paths to 3rd party dependencies")); - setPriority(28500); -} - -Tasks McuDependenciesKitAspect::validate(const Kit *k) const -{ - Tasks result; - QTC_ASSERT(k, return result); - - const QVariant checkFormat = k->value(McuDependenciesKitAspect::id()); - if (!checkFormat.isNull() && !checkFormat.canConvert(QVariant::List)) - return { BuildSystemTask(Task::Error, tr("The MCU dependencies setting value is invalid.")) }; - - const QVariant envStringList = k->value(EnvironmentKitAspect::id()); - if (!envStringList.isNull() && !envStringList.canConvert(QVariant::List)) - return { BuildSystemTask(Task::Error, tr("The environment setting value is invalid.")) }; - - const auto environment = Utils::NameValueDictionary(envStringList.toStringList()); - for (const auto &dependency: dependencies(k)) { - if (!environment.hasKey(dependency.name)) { - result << BuildSystemTask(Task::Warning, tr("Environment variable %1 not defined.").arg(dependency.name)); - } else { - const auto path = Utils::FilePath::fromUserInput( - environment.value(dependency.name) + "/" + dependency.value); - if (!path.exists()) { - result << BuildSystemTask(Task::Warning, tr("%1 not found.").arg(path.toUserOutput())); - } - } - } - - return result; -} - -void McuDependenciesKitAspect::fix(Kit *k) -{ - QTC_ASSERT(k, return); - - const QVariant variant = k->value(McuDependenciesKitAspect::id()); - if (!variant.isNull() && !variant.canConvert(QVariant::List)) { - qWarning("Kit \"%s\" has a wrong mcu dependencies value set.", qPrintable(k->displayName())); - setDependencies(k, Utils::NameValueItems()); - } -} - -KitAspectWidget *McuDependenciesKitAspect::createConfigWidget(Kit *k) const -{ - QTC_ASSERT(k, return nullptr); - return new Internal::McuDependenciesKitAspectWidget(k, this); -} - -KitAspect::ItemList McuDependenciesKitAspect::toUserOutput(const Kit *k) const -{ - Q_UNUSED(k); - return {}; -} - -Utils::Id McuDependenciesKitAspect::id() -{ - return "PE.Profile.McuDependencies"; -} - - -Utils::NameValueItems McuDependenciesKitAspect::dependencies(const Kit *k) -{ - if (k) - return Utils::NameValueItem::fromStringList(k->value(McuDependenciesKitAspect::id()).toStringList()); - return Utils::NameValueItems(); -} - -void McuDependenciesKitAspect::setDependencies(Kit *k, const Utils::NameValueItems &dependencies) -{ - if (k) - k->setValue(McuDependenciesKitAspect::id(), Utils::NameValueItem::toStringList(dependencies)); -} - } // McuSupport diff --git a/src/plugins/mcusupport/mcusupportoptions.h b/src/plugins/mcusupport/mcusupportoptions.h index 1b957d4e169..faec8b3ccb6 100644 --- a/src/plugins/mcusupport/mcusupportoptions.h +++ b/src/plugins/mcusupport/mcusupportoptions.h @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2020 The Qt Company Ltd. +** Copyright (C) 2021 The Qt Company Ltd. ** Contact: https://www.qt.io/licensing/ ** ** This file is part of Qt Creator. @@ -27,8 +27,6 @@ #include "mcusupport_global.h" -#include - #include #include #include @@ -155,24 +153,4 @@ signals: }; } // namespace Internal - -class MCUSUPPORTSHARED_EXPORT McuDependenciesKitAspect : public ProjectExplorer::KitAspect -{ - Q_OBJECT - -public: - McuDependenciesKitAspect(); - - ProjectExplorer::Tasks validate(const ProjectExplorer::Kit *k) const override; - void fix(ProjectExplorer::Kit *k) override; - - ProjectExplorer::KitAspectWidget *createConfigWidget(ProjectExplorer::Kit *k) const override; - - ItemList toUserOutput(const ProjectExplorer::Kit *k) const override; - - static Utils::Id id(); - static Utils::NameValueItems dependencies(const ProjectExplorer::Kit *k); - static void setDependencies(ProjectExplorer::Kit *k, const Utils::NameValueItems &dependencies); -}; - } // namespace McuSupport diff --git a/src/plugins/mcusupport/mcusupportplugin.cpp b/src/plugins/mcusupport/mcusupportplugin.cpp index 3e7db5e0ad7..21d8878645b 100644 --- a/src/plugins/mcusupport/mcusupportplugin.cpp +++ b/src/plugins/mcusupport/mcusupportplugin.cpp @@ -23,6 +23,7 @@ ** ****************************************************************************/ +#include "mcukitinformation.h" #include "mcusupportplugin.h" #include "mcusupportconstants.h" #include "mcusupportdevice.h"