McuSupport: Move McuDependenciesKitAspectWidget into its own file

Change-Id: I41a2a6ec48c5c02ca655cb09ad08080d73d336fe
Reviewed-by: Alessandro Portale <alessandro.portale@qt.io>
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
This commit is contained in:
Erik Verbruggen
2022-02-01 16:51:27 +01:00
committed by piotr.mucko
parent 6472e8c5bb
commit 250f4fb72f
7 changed files with 193 additions and 119 deletions

View File

@@ -2,6 +2,7 @@ add_qtc_plugin(McuSupport
DEPENDS Qt5::Core DEPENDS Qt5::Core
PLUGIN_DEPENDS Core BareMetal ProjectExplorer Debugger CMakeProjectManager QtSupport PLUGIN_DEPENDS Core BareMetal ProjectExplorer Debugger CMakeProjectManager QtSupport
SOURCES SOURCES
mcukitinformation.cpp mcukitinformation.h
mcusupport.qrc mcusupport.qrc
mcusupport_global.h mcusupport_global.h
mcusupportconstants.h mcusupportconstants.h

View File

@@ -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 <utils/qtcassert.h>
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

View File

@@ -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 <projectexplorer/kitinformation.h>
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

View File

@@ -35,6 +35,8 @@ QtcPlugin {
"mcusupportversiondetection.cpp", "mcusupportversiondetection.cpp",
"mcusupportversiondetection.h", "mcusupportversiondetection.h",
"mcusupportcmakemapper.h", "mcusupportcmakemapper.h",
"mcusupportcmakemapper.cpp" "mcusupportcmakemapper.cpp",
"mcukitinformation.cpp",
"mcukitinformation.h"
] ]
} }

View File

@@ -23,6 +23,7 @@
** **
****************************************************************************/ ****************************************************************************/
#include "mcukitinformation.h"
#include "mcupackage.h" #include "mcupackage.h"
#include "mcusupportconstants.h" #include "mcusupportconstants.h"
#include "mcusupportoptions.h" #include "mcusupportoptions.h"
@@ -1065,100 +1066,5 @@ void McuSupportOptions::fixExistingKits()
delete qtForMCUsPackage; 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 } // 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 } // McuSupport

View File

@@ -1,6 +1,6 @@
/**************************************************************************** /****************************************************************************
** **
** Copyright (C) 2020 The Qt Company Ltd. ** Copyright (C) 2021 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/ ** Contact: https://www.qt.io/licensing/
** **
** This file is part of Qt Creator. ** This file is part of Qt Creator.
@@ -27,8 +27,6 @@
#include "mcusupport_global.h" #include "mcusupport_global.h"
#include <projectexplorer/kitinformation.h>
#include <QObject> #include <QObject>
#include <QVector> #include <QVector>
#include <QVersionNumber> #include <QVersionNumber>
@@ -155,24 +153,4 @@ signals:
}; };
} // namespace Internal } // 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 } // namespace McuSupport

View File

@@ -23,6 +23,7 @@
** **
****************************************************************************/ ****************************************************************************/
#include "mcukitinformation.h"
#include "mcusupportplugin.h" #include "mcusupportplugin.h"
#include "mcusupportconstants.h" #include "mcusupportconstants.h"
#include "mcusupportdevice.h" #include "mcusupportdevice.h"