2019-08-14 11:48:13 +02:00
|
|
|
/****************************************************************************
|
|
|
|
|
**
|
2020-07-02 16:04:31 +02:00
|
|
|
** Copyright (C) 2020 The Qt Company Ltd.
|
2019-08-14 11:48:13 +02:00
|
|
|
** 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 "mcusupportplugin.h"
|
2022-02-15 11:18:56 +01:00
|
|
|
#include "mcukitinformation.h"
|
2022-03-28 16:42:51 +02:00
|
|
|
#include "mcukitmanager.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"
|
|
|
|
|
|
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>
|
2019-08-14 11:48:13 +02:00
|
|
|
|
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;
|
|
|
|
|
|
2022-03-28 16:42:51 +02:00
|
|
|
namespace {
|
|
|
|
|
constexpr char setupMcuSupportKits[]{"SetupMcuSupportKits"};
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-14 11:48:13 +02:00
|
|
|
namespace McuSupport {
|
|
|
|
|
namespace Internal {
|
|
|
|
|
|
2022-02-16 16:48:28 +01:00
|
|
|
void printMessage(const QString &message, bool important)
|
|
|
|
|
{
|
|
|
|
|
const QString displayMessage = QCoreApplication::translate("QtForMCUs", "Qt for MCUs: %1")
|
|
|
|
|
.arg(message);
|
|
|
|
|
if (important)
|
|
|
|
|
Core::MessageManager::writeFlashing(displayMessage);
|
|
|
|
|
else
|
|
|
|
|
Core::MessageManager::writeSilently(displayMessage);
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-14 11:48:13 +02:00
|
|
|
class McuSupportPluginPrivate
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
McuSupportDeviceFactory deviceFactory;
|
2019-11-22 16:48:46 +01:00
|
|
|
McuSupportRunConfigurationFactory runConfigurationFactory;
|
2022-02-15 11:18:56 +01:00
|
|
|
RunWorkerFactory runWorkerFactory{makeFlashAndRunWorker(),
|
|
|
|
|
{ProjectExplorer::Constants::NORMAL_RUN_MODE},
|
|
|
|
|
{Constants::RUNCONFIGURATION}};
|
2019-08-14 11:48:13 +02:00
|
|
|
McuSupportOptionsPage optionsPage;
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
2022-02-15 11:18:56 +01:00
|
|
|
bool McuSupportPlugin::initialize(const QStringList &arguments, QString *errorString)
|
2019-08-14 11:48:13 +02:00
|
|
|
{
|
|
|
|
|
Q_UNUSED(arguments)
|
|
|
|
|
Q_UNUSED(errorString)
|
|
|
|
|
|
2022-02-11 13:51:42 +01:00
|
|
|
setObjectName("McuSupportPlugin");
|
2019-08-14 11:48:13 +02:00
|
|
|
dd = new McuSupportPluginPrivate;
|
|
|
|
|
|
2020-03-24 18:58:29 +01:00
|
|
|
McuSupportOptions::registerQchFiles();
|
2020-04-02 19:31:52 +02:00
|
|
|
McuSupportOptions::registerExamples();
|
2021-08-10 16:19:02 +02:00
|
|
|
ProjectExplorer::JsonWizardFactory::addWizardPath(":/mcusupport/wizards/");
|
2019-08-14 11:48:13 +02:00
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void McuSupportPlugin::extensionsInitialized()
|
|
|
|
|
{
|
|
|
|
|
ProjectExplorer::DeviceManager::instance()->addDevice(McuSupportDevice::create());
|
2020-05-04 16:34:38 +02:00
|
|
|
|
2022-02-15 11:18:56 +01:00
|
|
|
connect(KitManager::instance(), &KitManager::kitsLoaded, []() {
|
2022-02-14 18:01:04 +01:00
|
|
|
McuKitManager::removeOutdatedKits();
|
|
|
|
|
McuKitManager::createAutomaticKits();
|
|
|
|
|
McuKitManager::fixExistingKits();
|
2020-03-04 17:48:27 +01:00
|
|
|
McuSupportPlugin::askUserAboutMcuSupportKitsSetup();
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void McuSupportPlugin::askUserAboutMcuSupportKitsSetup()
|
|
|
|
|
{
|
|
|
|
|
if (!ICore::infoBar()->canInfoBeAdded(setupMcuSupportKits)
|
|
|
|
|
|| McuSupportOptions::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,
|
|
|
|
|
tr("Create Kits for Qt for MCUs? "
|
|
|
|
|
"To do it later, select Options > Devices > MCU."),
|
|
|
|
|
Utils::InfoBarEntry::GlobalSuppression::Enabled);
|
2022-02-22 13:36:55 +01:00
|
|
|
// clazy:excludeall=connect-3arg-lambda
|
2022-03-28 16:42:51 +02:00
|
|
|
info.addCustomButton(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
|
|
|
}
|
|
|
|
|
|
2021-03-10 16:38:45 +01:00
|
|
|
void McuSupportPlugin::askUserAboutMcuSupportKitsUpgrade()
|
|
|
|
|
{
|
|
|
|
|
const char upgradeMcuSupportKits[] = "UpgradeMcuSupportKits";
|
|
|
|
|
|
|
|
|
|
if (!ICore::infoBar()->canInfoBeAdded(upgradeMcuSupportKits))
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
Utils::InfoBarEntry info(upgradeMcuSupportKits,
|
|
|
|
|
tr("New version of Qt for MCUs detected. Upgrade existing Kits?"),
|
|
|
|
|
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
|
|
|
|
|
= {{tr("Create new kits"), QVariant::fromValue(UpgradeOption::Keep)},
|
|
|
|
|
{tr("Replace existing kits"), QVariant::fromValue(UpgradeOption::Replace)}};
|
|
|
|
|
|
|
|
|
|
info.setComboInfo(infos, [](const Utils::InfoBarEntry::ComboInfo &selected) {
|
|
|
|
|
selectedOption = selected.data.value<UpgradeOption>();
|
2021-03-10 16:38:45 +01:00
|
|
|
});
|
|
|
|
|
|
2022-01-17 16:47:31 +01:00
|
|
|
info.addCustomButton(tr("Proceed"), [upgradeMcuSupportKits] {
|
2021-03-10 16:38:45 +01:00
|
|
|
ICore::infoBar()->removeInfo(upgradeMcuSupportKits);
|
2022-02-14 18:01:04 +01:00
|
|
|
QTimer::singleShot(0, []() {
|
|
|
|
|
McuKitManager::upgradeKitsByCreatingNewPackage(selectedOption);
|
|
|
|
|
});
|
2021-03-10 16:38:45 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
ICore::infoBar()->addInfo(info);
|
|
|
|
|
}
|
|
|
|
|
|
2022-02-11 13:51:42 +01:00
|
|
|
QVector<QObject *> McuSupportPlugin::createTestObjects() const
|
|
|
|
|
{
|
|
|
|
|
QVector<QObject *> tests;
|
|
|
|
|
#if defined(WITH_TESTS) && defined(GOOGLE_TEST_IS_FOUND)
|
|
|
|
|
tests << new Test::McuSupportTest;
|
|
|
|
|
#endif
|
|
|
|
|
return tests;
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-14 11:48:13 +02:00
|
|
|
} // namespace Internal
|
|
|
|
|
} // namespace McuSupport
|