McuSupport: generate kits automatically on plugin initialization

Fixes: QTCREATORBUG-24354
Change-Id: I26587102bd24d1678707ca1d9160c84149e77c8e
Reviewed-by: hjk <hjk@qt.io>
Reviewed-by: Alessandro Portale <alessandro.portale@qt.io>
This commit is contained in:
Christiaan Janssen
2020-10-16 15:10:17 +02:00
committed by christiaan.janssen
parent b7c72f8621
commit 9cd5fb927d
5 changed files with 83 additions and 9 deletions

View File

@@ -43,6 +43,7 @@ const char KIT_MCUTARGET_OS_KEY[] = "McuSupport.McuTargetOs";
const char SETTINGS_GROUP[] = "McuSupport"; const char SETTINGS_GROUP[] = "McuSupport";
const char SETTINGS_KEY_PACKAGE_PREFIX[] = "Package_"; const char SETTINGS_KEY_PACKAGE_PREFIX[] = "Package_";
const char SETTINGS_KEY_PACKAGE_QT_FOR_MCUS_SDK[] = "QtForMCUsSdk"; // Key known by SDK installer const char SETTINGS_KEY_PACKAGE_QT_FOR_MCUS_SDK[] = "QtForMCUsSdk"; // Key known by SDK installer
const char SETTINGS_KEY_AUTOMATIC_KIT_CREATION[] = "AutomaticKitCreation";
} // namespace McuSupport } // namespace McuSupport
} // namespace Constants } // namespace Constants

View File

@@ -70,14 +70,22 @@ static QString packagePathFromSettings(const QString &settingsKey,
QSettings::Scope scope = QSettings::UserScope, QSettings::Scope scope = QSettings::UserScope,
const QString &defaultPath = {}) const QString &defaultPath = {})
{ {
QSettings *s = Core::ICore::settings(scope); QSettings *settings = Core::ICore::settings(scope);
s->beginGroup(Constants::SETTINGS_GROUP); const QString key = QLatin1String(Constants::SETTINGS_GROUP) + '/' +
const QString path = s->value(QLatin1String(Constants::SETTINGS_KEY_PACKAGE_PREFIX) QLatin1String(Constants::SETTINGS_KEY_PACKAGE_PREFIX) + settingsKey;
+ settingsKey, defaultPath).toString(); const QString path = settings->value(key, defaultPath).toString();
s->endGroup();
return FilePath::fromFileInfo(path).toString(); return FilePath::fromFileInfo(path).toString();
} }
static bool automaticKitCreationFromSettings(QSettings::Scope scope = QSettings::UserScope)
{
QSettings *settings = Core::ICore::settings(scope);
const QString key = QLatin1String(Constants::SETTINGS_GROUP) + '/' +
QLatin1String(Constants::SETTINGS_KEY_AUTOMATIC_KIT_CREATION);
bool automaticKitCreation = settings->value(key, true).toBool();
return automaticKitCreation;
}
static bool kitNeedsQtVersion() static bool kitNeedsQtVersion()
{ {
// Only on Windows, Qt is linked into the distributed qul Desktop libs. Also, the host tools // Only on Windows, Qt is linked into the distributed qul Desktop libs. Also, the host tools
@@ -93,11 +101,13 @@ McuPackage::McuPackage(const QString &label, const QString &defaultPath,
, m_settingsKey(settingsKey) , m_settingsKey(settingsKey)
{ {
m_path = packagePathFromSettings(settingsKey, QSettings::UserScope, m_defaultPath); m_path = packagePathFromSettings(settingsKey, QSettings::UserScope, m_defaultPath);
m_automaticKitCreation = automaticKitCreationFromSettings(QSettings::UserScope);
} }
QString McuPackage::path() const QString McuPackage::path() const
{ {
return QFileInfo(m_fileChooser->filePath().toString() + m_relativePathModifier).absoluteFilePath(); QString basePath = m_fileChooser != nullptr ? m_fileChooser->filePath().toString() : m_path;
return QFileInfo(basePath + m_relativePathModifier).absoluteFilePath();
} }
QString McuPackage::label() const QString McuPackage::label() const
@@ -187,15 +197,23 @@ bool McuPackage::addToPath() const
return m_addToPath; return m_addToPath;
} }
void McuPackage::writeGeneralSettings() const
{
const QString key = QLatin1String(Constants::SETTINGS_GROUP) + '/' +
QLatin1String(Constants::SETTINGS_KEY_AUTOMATIC_KIT_CREATION);
QSettings *settings = Core::ICore::settings();
settings->setValue(key, m_automaticKitCreation);
}
void McuPackage::writeToSettings() const void McuPackage::writeToSettings() const
{ {
const QString key = QLatin1String(Constants::SETTINGS_GROUP) + '/' + const QString key = QLatin1String(Constants::SETTINGS_GROUP) + '/' +
QLatin1String(Constants::SETTINGS_KEY_PACKAGE_PREFIX) + m_settingsKey; QLatin1String(Constants::SETTINGS_KEY_PACKAGE_PREFIX) + m_settingsKey;
QSettings *uS = Core::ICore::settings(); QSettings *settings = Core::ICore::settings();
if (m_path == m_defaultPath) if (m_path == m_defaultPath)
uS->remove(key); settings->remove(key);
else else
uS->setValue(key, m_path); settings->setValue(key, m_path);
} }
void McuPackage::setRelativePathModifier(const QString &path) void McuPackage::setRelativePathModifier(const QString &path)
@@ -203,6 +221,16 @@ void McuPackage::setRelativePathModifier(const QString &path)
m_relativePathModifier = path; m_relativePathModifier = path;
} }
bool McuPackage::automaticKitCreationEnabled() const
{
return m_automaticKitCreation;
}
void McuPackage::setAutomaticKitCreationEnabled(const bool enabled)
{
m_automaticKitCreation = enabled;
}
void McuPackage::updateStatus() void McuPackage::updateStatus()
{ {
m_path = m_fileChooser->rawPath(); m_path = m_fileChooser->rawPath();
@@ -713,5 +741,29 @@ Kit *McuSupportOptions::newKit(const McuTarget *mcuTarget, const McuPackage *qtF
return KitManager::registerKit(init); return KitManager::registerKit(init);
} }
void McuSupportOptions::createAutomaticKits()
{
if (qulDirFromSettings().isEmpty())
return;
auto qtForMCUsPackage = Sdk::createQtForMCUsPackage();
if (qtForMCUsPackage->automaticKitCreationEnabled()) {
auto dir = FilePath::fromUserInput(qtForMCUsPackage->path());
QVector<McuPackage*> packages;
QVector<McuTarget*> mcuTargets;
Sdk::targetsAndPackages(dir, &packages, &mcuTargets);
for (auto target: qAsConst(mcuTargets))
if (existingKits(target).isEmpty())
newKit(target, qtForMCUsPackage);
qDeleteAll(packages);
qDeleteAll(mcuTargets);
}
delete qtForMCUsPackage;
}
} // Internal } // Internal
} // McuSupport } // McuSupport

View File

@@ -71,9 +71,13 @@ public:
void setEnvironmentVariableName(const QString &name); void setEnvironmentVariableName(const QString &name);
void setAddToPath(bool addToPath); void setAddToPath(bool addToPath);
bool addToPath() const; bool addToPath() const;
void writeGeneralSettings() const;
void writeToSettings() const; void writeToSettings() const;
void setRelativePathModifier(const QString &path); void setRelativePathModifier(const QString &path);
bool automaticKitCreationEnabled() const;
void setAutomaticKitCreationEnabled(const bool enabled);
QWidget *widget(); QWidget *widget();
QString environmentVariableName() const; QString environmentVariableName() const;
@@ -98,6 +102,7 @@ private:
QString m_downloadUrl; QString m_downloadUrl;
QString m_environmentVariableName; QString m_environmentVariableName;
bool m_addToPath = false; bool m_addToPath = false;
bool m_automaticKitCreation = true;
Status m_status = InvalidPath; Status m_status = InvalidPath;
}; };
@@ -190,6 +195,7 @@ public:
static QList<ProjectExplorer::Kit *> outdatedKits(); static QList<ProjectExplorer::Kit *> outdatedKits();
static void removeOutdatedKits(); static void removeOutdatedKits();
static ProjectExplorer::Kit *newKit(const McuTarget *mcuTarget, const McuPackage *qtForMCUsSdk); static ProjectExplorer::Kit *newKit(const McuTarget *mcuTarget, const McuPackage *qtForMCUsSdk);
static void createAutomaticKits();
void populatePackagesAndTargets(); void populatePackagesAndTargets();
static void registerQchFiles(); static void registerQchFiles();
static void registerExamples(); static void registerExamples();

View File

@@ -37,6 +37,7 @@
#include <utils/qtcassert.h> #include <utils/qtcassert.h>
#include <utils/utilsicons.h> #include <utils/utilsicons.h>
#include <QCheckBox>
#include <QComboBox> #include <QComboBox>
#include <QDir> #include <QDir>
#include <QHBoxLayout> #include <QHBoxLayout>
@@ -76,6 +77,7 @@ private:
QGroupBox *m_mcuTargetsGroupBox = nullptr; QGroupBox *m_mcuTargetsGroupBox = nullptr;
QComboBox *m_mcuTargetsComboBox = nullptr; QComboBox *m_mcuTargetsComboBox = nullptr;
QGroupBox *m_kitCreationGroupBox = nullptr; QGroupBox *m_kitCreationGroupBox = nullptr;
QCheckBox *m_kitAutomaticCreationCheckBox = nullptr;
Utils::InfoLabel *m_kitCreationInfoLabel = nullptr; Utils::InfoLabel *m_kitCreationInfoLabel = nullptr;
Utils::InfoLabel *m_statusInfoLabel = nullptr; Utils::InfoLabel *m_statusInfoLabel = nullptr;
QPushButton *m_kitCreationPushButton = nullptr; QPushButton *m_kitCreationPushButton = nullptr;
@@ -126,6 +128,14 @@ McuSupportOptionsWidget::McuSupportOptionsWidget()
m_packagesGroupBox->setLayout(m_packagesLayout); m_packagesGroupBox->setLayout(m_packagesLayout);
} }
{
m_kitAutomaticCreationCheckBox = new QCheckBox(tr("Automatically create kits for all available targets on start"));
connect(m_kitAutomaticCreationCheckBox, &QCheckBox::stateChanged, this, [this] (int state) {
m_options.qtForMCUsSdkPackage->setAutomaticKitCreationEnabled(state == Qt::CheckState::Checked);
});
mainLayout->addWidget(m_kitAutomaticCreationCheckBox);
}
{ {
m_kitCreationGroupBox = new QGroupBox(tr("Create a Kit")); m_kitCreationGroupBox = new QGroupBox(tr("Create a Kit"));
m_kitCreationGroupBox->setFlat(true); m_kitCreationGroupBox->setFlat(true);
@@ -196,6 +206,9 @@ void McuSupportOptionsWidget::updateStatus()
} }
} }
// Automatic Kit creation
m_kitAutomaticCreationCheckBox->setChecked(m_options.qtForMCUsSdkPackage->automaticKitCreationEnabled());
// Status label in the bottom // Status label in the bottom
{ {
m_statusInfoLabel->setVisible(!cMakeAvailable); m_statusInfoLabel->setVisible(!cMakeAvailable);
@@ -246,6 +259,7 @@ void McuSupportOptionsWidget::showEvent(QShowEvent *event)
void McuSupportOptionsWidget::apply() void McuSupportOptionsWidget::apply()
{ {
m_options.qtForMCUsSdkPackage->writeGeneralSettings();
m_options.qtForMCUsSdkPackage->writeToSettings(); m_options.qtForMCUsSdkPackage->writeToSettings();
for (auto package : m_options.packages) for (auto package : m_options.packages)
package->writeToSettings(); package->writeToSettings();

View File

@@ -95,6 +95,7 @@ void McuSupportPlugin::extensionsInitialized()
connect(KitManager::instance(), &KitManager::kitsLoaded, [](){ connect(KitManager::instance(), &KitManager::kitsLoaded, [](){
McuSupportOptions::removeOutdatedKits(); McuSupportOptions::removeOutdatedKits();
McuSupportOptions::createAutomaticKits();
McuSupportPlugin::askUserAboutMcuSupportKitsSetup(); McuSupportPlugin::askUserAboutMcuSupportKitsSetup();
}); });
} }