2022-08-19 15:59:36 +02:00
|
|
|
// Copyright (C) 2020 The Qt Company Ltd.
|
2022-12-21 10:12:09 +01:00
|
|
|
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
|
2019-08-14 11:48:13 +02:00
|
|
|
|
|
|
|
|
#include "mcusupportplugin.h"
|
2023-01-22 18:02:20 +01:00
|
|
|
|
2022-02-15 11:18:56 +01:00
|
|
|
#include "mcukitinformation.h"
|
2022-03-28 16:42:51 +02:00
|
|
|
#include "mcukitmanager.h"
|
2023-01-19 10:17:21 +02:00
|
|
|
#include "mcuqmlprojectnode.h"
|
2019-08-14 11:48:13 +02:00
|
|
|
#include "mcusupportconstants.h"
|
|
|
|
|
#include "mcusupportdevice.h"
|
2020-03-24 18:58:29 +01:00
|
|
|
#include "mcusupportoptions.h"
|
2019-08-14 11:48:13 +02:00
|
|
|
#include "mcusupportoptionspage.h"
|
|
|
|
|
#include "mcusupportrunconfiguration.h"
|
2023-01-22 18:02:20 +01:00
|
|
|
#include "mcusupporttr.h"
|
2019-08-14 11:48:13 +02:00
|
|
|
|
2022-02-11 13:51:42 +01:00
|
|
|
#if defined(WITH_TESTS) && defined(GOOGLE_TEST_IS_FOUND)
|
|
|
|
|
#include "test/unittest.h"
|
|
|
|
|
#endif
|
|
|
|
|
|
2019-08-14 11:48:13 +02:00
|
|
|
#include <coreplugin/coreconstants.h>
|
|
|
|
|
#include <coreplugin/icontext.h>
|
|
|
|
|
#include <coreplugin/icore.h>
|
2022-02-16 16:48:28 +01:00
|
|
|
#include <coreplugin/messagemanager.h>
|
2019-08-14 11:48:13 +02:00
|
|
|
|
|
|
|
|
#include <projectexplorer/devicesupport/devicemanager.h>
|
|
|
|
|
#include <projectexplorer/jsonwizard/jsonwizardfactory.h>
|
2020-05-04 16:34:38 +02:00
|
|
|
#include <projectexplorer/kitmanager.h>
|
2023-01-19 10:17:21 +02:00
|
|
|
#include <projectexplorer/project.h>
|
2022-06-22 15:43:33 +02:00
|
|
|
#include <projectexplorer/projectexplorerconstants.h>
|
2023-01-19 10:17:21 +02:00
|
|
|
#include <projectexplorer/projecttree.h>
|
|
|
|
|
#include <projectexplorer/session.h>
|
|
|
|
|
#include <projectexplorer/target.h>
|
2019-08-14 11:48:13 +02:00
|
|
|
|
2023-01-19 10:17:21 +02:00
|
|
|
#include <cmakeprojectmanager/cmakeprojectconstants.h>
|
|
|
|
|
|
|
|
|
|
#include <utils/filepath.h>
|
2020-06-17 12:23:44 +02:00
|
|
|
#include <utils/infobar.h>
|
|
|
|
|
|
2020-03-04 17:48:27 +01:00
|
|
|
#include <QTimer>
|
|
|
|
|
|
|
|
|
|
using namespace Core;
|
2019-08-14 11:48:13 +02:00
|
|
|
using namespace ProjectExplorer;
|
|
|
|
|
|
2023-02-09 10:52:16 +01:00
|
|
|
namespace McuSupport::Internal {
|
2022-03-28 16:42:51 +02:00
|
|
|
|
2023-02-09 10:52:16 +01:00
|
|
|
const char setupMcuSupportKits[] = "SetupMcuSupportKits";
|
2019-08-14 11:48:13 +02:00
|
|
|
|
2022-02-16 16:48:28 +01:00
|
|
|
void printMessage(const QString &message, bool important)
|
|
|
|
|
{
|
2023-01-22 18:02:20 +01:00
|
|
|
const QString displayMessage = Tr::tr("Qt for MCUs: %1").arg(message);
|
2022-02-16 16:48:28 +01:00
|
|
|
if (important)
|
|
|
|
|
Core::MessageManager::writeFlashing(displayMessage);
|
|
|
|
|
else
|
|
|
|
|
Core::MessageManager::writeSilently(displayMessage);
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-19 10:17:21 +02:00
|
|
|
void updateMCUProjectTree(ProjectExplorer::Project *p)
|
|
|
|
|
{
|
|
|
|
|
if (!p || !p->rootProjectNode())
|
|
|
|
|
return;
|
|
|
|
|
ProjectExplorer::Target *target = p->activeTarget();
|
|
|
|
|
if (!target || !target->kit()
|
|
|
|
|
|| !target->kit()->hasValue(Constants::KIT_MCUTARGET_KITVERSION_KEY))
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
p->rootProjectNode()->forEachProjectNode([](const ProjectNode *node) {
|
|
|
|
|
if (!node)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
const FilePath projectBuildFolder = FilePath::fromVariant(
|
|
|
|
|
node->data(CMakeProjectManager::Constants::BUILD_FOLDER_ROLE));
|
|
|
|
|
const QString targetName = node->displayName();
|
|
|
|
|
if (targetName.isEmpty())
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
const FilePath inputsJsonFile = projectBuildFolder / "CMakeFiles" / (targetName + ".dir")
|
|
|
|
|
/ "config/input.json";
|
|
|
|
|
|
|
|
|
|
if (!inputsJsonFile.exists())
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
auto qmlProjectNode = std::make_unique<McuQmlProjectNode>(FilePath(node->filePath()),
|
|
|
|
|
inputsJsonFile);
|
|
|
|
|
|
|
|
|
|
auto qmlProjectNodePtr = qmlProjectNode.get();
|
|
|
|
|
const_cast<ProjectNode *>(node)->addNode(std::move(qmlProjectNode));
|
|
|
|
|
ProjectExplorer::ProjectTree::emitSubtreeChanged(qmlProjectNodePtr);
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
2019-08-14 11:48:13 +02:00
|
|
|
class McuSupportPluginPrivate
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
McuSupportDeviceFactory deviceFactory;
|
2019-11-22 16:48:46 +01:00
|
|
|
McuSupportRunConfigurationFactory runConfigurationFactory;
|
2023-01-06 14:39:43 +01:00
|
|
|
FlashRunWorkerFactory flashRunWorkerFactory;
|
2022-06-22 16:11:56 +02:00
|
|
|
SettingsHandler::Ptr m_settingsHandler{new SettingsHandler};
|
2022-04-22 11:41:33 +02:00
|
|
|
McuSupportOptions m_options{m_settingsHandler};
|
|
|
|
|
McuSupportOptionsPage optionsPage{m_options, m_settingsHandler};
|
2021-03-09 18:28:58 +01:00
|
|
|
McuDependenciesKitAspect environmentPathsKitAspect;
|
2022-02-11 13:51:42 +01:00
|
|
|
}; // class McuSupportPluginPrivate
|
2019-08-14 11:48:13 +02:00
|
|
|
|
2022-02-15 11:18:56 +01:00
|
|
|
static McuSupportPluginPrivate *dd{nullptr};
|
2019-08-14 11:48:13 +02:00
|
|
|
|
|
|
|
|
McuSupportPlugin::~McuSupportPlugin()
|
|
|
|
|
{
|
|
|
|
|
delete dd;
|
|
|
|
|
dd = nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-20 12:28:36 +01:00
|
|
|
void McuSupportPlugin::initialize()
|
2019-08-14 11:48:13 +02:00
|
|
|
{
|
2022-02-11 13:51:42 +01:00
|
|
|
setObjectName("McuSupportPlugin");
|
2022-06-22 16:11:56 +02:00
|
|
|
dd = new McuSupportPluginPrivate;
|
2019-08-14 11:48:13 +02:00
|
|
|
|
2023-01-19 10:17:21 +02:00
|
|
|
connect(SessionManager::instance(),
|
|
|
|
|
&SessionManager::projectFinishedParsing,
|
|
|
|
|
updateMCUProjectTree);
|
|
|
|
|
|
2022-04-22 11:41:33 +02:00
|
|
|
dd->m_options.registerQchFiles();
|
|
|
|
|
dd->m_options.registerExamples();
|
2021-08-10 16:19:02 +02:00
|
|
|
ProjectExplorer::JsonWizardFactory::addWizardPath(":/mcusupport/wizards/");
|
2023-02-09 10:52:16 +01:00
|
|
|
|
|
|
|
|
#if defined(WITH_TESTS) && defined(GOOGLE_TEST_IS_FOUND)
|
|
|
|
|
addTest<Test::McuSupportTest>();
|
|
|
|
|
#endif
|
2019-08-14 11:48:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void McuSupportPlugin::extensionsInitialized()
|
|
|
|
|
{
|
|
|
|
|
ProjectExplorer::DeviceManager::instance()->addDevice(McuSupportDevice::create());
|
2020-05-04 16:34:38 +02:00
|
|
|
|
2022-04-22 11:41:33 +02:00
|
|
|
connect(KitManager::instance(), &KitManager::kitsLoaded, [this]() {
|
2022-02-14 18:01:04 +01:00
|
|
|
McuKitManager::removeOutdatedKits();
|
2022-06-22 16:11:56 +02:00
|
|
|
McuKitManager::createAutomaticKits(dd->m_settingsHandler);
|
|
|
|
|
McuKitManager::fixExistingKits(dd->m_settingsHandler);
|
2022-04-22 11:41:33 +02:00
|
|
|
askUserAboutMcuSupportKitsSetup();
|
2023-03-17 12:59:50 +02:00
|
|
|
askUserAboutRemovingUninstalledTargetsKits();
|
2020-03-04 17:48:27 +01:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void McuSupportPlugin::askUserAboutMcuSupportKitsSetup()
|
|
|
|
|
{
|
|
|
|
|
if (!ICore::infoBar()->canInfoBeAdded(setupMcuSupportKits)
|
2022-04-22 11:41:33 +02:00
|
|
|
|| dd->m_options.qulDirFromSettings().isEmpty()
|
2022-02-14 18:01:04 +01:00
|
|
|
|| !McuKitManager::existingKits(nullptr).isEmpty())
|
2020-03-04 17:48:27 +01:00
|
|
|
return;
|
|
|
|
|
|
2020-06-17 12:23:44 +02:00
|
|
|
Utils::InfoBarEntry info(setupMcuSupportKits,
|
2023-01-22 18:02:20 +01:00
|
|
|
Tr::tr("Create Kits for Qt for MCUs? "
|
2022-06-28 10:08:45 +02:00
|
|
|
"To do it later, select Edit > Preferences > Devices > MCU."),
|
2020-06-17 12:23:44 +02:00
|
|
|
Utils::InfoBarEntry::GlobalSuppression::Enabled);
|
2022-02-22 13:36:55 +01:00
|
|
|
// clazy:excludeall=connect-3arg-lambda
|
2023-01-22 18:02:20 +01:00
|
|
|
info.addCustomButton(Tr::tr("Create Kits for Qt for MCUs"), [] {
|
2020-03-04 17:48:27 +01:00
|
|
|
ICore::infoBar()->removeInfo(setupMcuSupportKits);
|
|
|
|
|
QTimer::singleShot(0, []() { ICore::showOptionsDialog(Constants::SETTINGS_ID); });
|
2020-05-04 16:34:38 +02:00
|
|
|
});
|
2020-03-04 17:48:27 +01:00
|
|
|
ICore::infoBar()->addInfo(info);
|
2019-08-14 11:48:13 +02:00
|
|
|
}
|
|
|
|
|
|
2022-04-22 11:41:33 +02:00
|
|
|
void McuSupportPlugin::askUserAboutMcuSupportKitsUpgrade(const SettingsHandler::Ptr &settingsHandler)
|
2021-03-10 16:38:45 +01:00
|
|
|
{
|
|
|
|
|
const char upgradeMcuSupportKits[] = "UpgradeMcuSupportKits";
|
|
|
|
|
|
|
|
|
|
if (!ICore::infoBar()->canInfoBeAdded(upgradeMcuSupportKits))
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
Utils::InfoBarEntry info(upgradeMcuSupportKits,
|
2023-01-22 18:02:20 +01:00
|
|
|
Tr::tr("New version of Qt for MCUs detected. Upgrade existing Kits?"),
|
2021-03-10 16:38:45 +01:00
|
|
|
Utils::InfoBarEntry::GlobalSuppression::Enabled);
|
2022-03-18 11:38:35 +01:00
|
|
|
using McuKitManager::UpgradeOption;
|
|
|
|
|
static UpgradeOption selectedOption = UpgradeOption::Keep;
|
2021-03-10 16:38:45 +01:00
|
|
|
|
2022-03-18 11:38:35 +01:00
|
|
|
const QList<Utils::InfoBarEntry::ComboInfo> infos
|
2023-01-22 18:02:20 +01:00
|
|
|
= {{Tr::tr("Create new kits"), QVariant::fromValue(UpgradeOption::Keep)},
|
|
|
|
|
{Tr::tr("Replace existing kits"), QVariant::fromValue(UpgradeOption::Replace)}};
|
2022-03-18 11:38:35 +01:00
|
|
|
|
|
|
|
|
info.setComboInfo(infos, [](const Utils::InfoBarEntry::ComboInfo &selected) {
|
|
|
|
|
selectedOption = selected.data.value<UpgradeOption>();
|
2021-03-10 16:38:45 +01:00
|
|
|
});
|
|
|
|
|
|
2023-01-22 18:02:20 +01:00
|
|
|
info.addCustomButton(Tr::tr("Proceed"), [upgradeMcuSupportKits, settingsHandler] {
|
2021-03-10 16:38:45 +01:00
|
|
|
ICore::infoBar()->removeInfo(upgradeMcuSupportKits);
|
2022-04-22 11:41:33 +02:00
|
|
|
QTimer::singleShot(0, [settingsHandler]() {
|
|
|
|
|
McuKitManager::upgradeKitsByCreatingNewPackage(settingsHandler, selectedOption);
|
2022-02-14 18:01:04 +01:00
|
|
|
});
|
2021-03-10 16:38:45 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
ICore::infoBar()->addInfo(info);
|
|
|
|
|
}
|
|
|
|
|
|
2023-03-17 12:59:50 +02:00
|
|
|
void McuSupportPlugin::askUserAboutRemovingUninstalledTargetsKits()
|
|
|
|
|
{
|
|
|
|
|
const char removeUninstalledKits[] = "RemoveUninstalledKits";
|
|
|
|
|
QList<Kit *> uninstalledTargetsKits;
|
|
|
|
|
|
|
|
|
|
if (!ICore::infoBar()->canInfoBeAdded(removeUninstalledKits)
|
|
|
|
|
|| (uninstalledTargetsKits = McuKitManager::findUninstalledTargetsKits()).isEmpty())
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
Utils::InfoBarEntry
|
|
|
|
|
info(removeUninstalledKits,
|
|
|
|
|
Tr::tr("Detected %n uninstalled MCU target(s). Remove corresponding kits?",
|
|
|
|
|
nullptr,
|
|
|
|
|
uninstalledTargetsKits.size()),
|
|
|
|
|
Utils::InfoBarEntry::GlobalSuppression::Enabled);
|
|
|
|
|
|
|
|
|
|
info.addCustomButton(Tr::tr("Keep"), [removeUninstalledKits] {
|
|
|
|
|
ICore::infoBar()->removeInfo(removeUninstalledKits);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
info.addCustomButton(Tr::tr("Remove"), [removeUninstalledKits, uninstalledTargetsKits] {
|
|
|
|
|
ICore::infoBar()->removeInfo(removeUninstalledKits);
|
|
|
|
|
QTimer::singleShot(0, [uninstalledTargetsKits]() {
|
|
|
|
|
McuKitManager::removeUninstalledTargetsKits(uninstalledTargetsKits);
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
ICore::infoBar()->addInfo(info);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace McuSupport::Internal
|