forked from qt-creator/qt-creator
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:
committed by
christiaan.janssen
parent
b7c72f8621
commit
9cd5fb927d
@@ -43,6 +43,7 @@ const char KIT_MCUTARGET_OS_KEY[] = "McuSupport.McuTargetOs";
|
||||
const char SETTINGS_GROUP[] = "McuSupport";
|
||||
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_AUTOMATIC_KIT_CREATION[] = "AutomaticKitCreation";
|
||||
|
||||
} // namespace McuSupport
|
||||
} // namespace Constants
|
||||
|
||||
@@ -70,14 +70,22 @@ static QString packagePathFromSettings(const QString &settingsKey,
|
||||
QSettings::Scope scope = QSettings::UserScope,
|
||||
const QString &defaultPath = {})
|
||||
{
|
||||
QSettings *s = Core::ICore::settings(scope);
|
||||
s->beginGroup(Constants::SETTINGS_GROUP);
|
||||
const QString path = s->value(QLatin1String(Constants::SETTINGS_KEY_PACKAGE_PREFIX)
|
||||
+ settingsKey, defaultPath).toString();
|
||||
s->endGroup();
|
||||
QSettings *settings = Core::ICore::settings(scope);
|
||||
const QString key = QLatin1String(Constants::SETTINGS_GROUP) + '/' +
|
||||
QLatin1String(Constants::SETTINGS_KEY_PACKAGE_PREFIX) + settingsKey;
|
||||
const QString path = settings->value(key, defaultPath).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()
|
||||
{
|
||||
// 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_path = packagePathFromSettings(settingsKey, QSettings::UserScope, m_defaultPath);
|
||||
m_automaticKitCreation = automaticKitCreationFromSettings(QSettings::UserScope);
|
||||
}
|
||||
|
||||
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
|
||||
@@ -187,15 +197,23 @@ bool McuPackage::addToPath() const
|
||||
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
|
||||
{
|
||||
const QString key = QLatin1String(Constants::SETTINGS_GROUP) + '/' +
|
||||
QLatin1String(Constants::SETTINGS_KEY_PACKAGE_PREFIX) + m_settingsKey;
|
||||
QSettings *uS = Core::ICore::settings();
|
||||
QSettings *settings = Core::ICore::settings();
|
||||
if (m_path == m_defaultPath)
|
||||
uS->remove(key);
|
||||
settings->remove(key);
|
||||
else
|
||||
uS->setValue(key, m_path);
|
||||
settings->setValue(key, m_path);
|
||||
}
|
||||
|
||||
void McuPackage::setRelativePathModifier(const QString &path)
|
||||
@@ -203,6 +221,16 @@ void McuPackage::setRelativePathModifier(const QString &path)
|
||||
m_relativePathModifier = path;
|
||||
}
|
||||
|
||||
bool McuPackage::automaticKitCreationEnabled() const
|
||||
{
|
||||
return m_automaticKitCreation;
|
||||
}
|
||||
|
||||
void McuPackage::setAutomaticKitCreationEnabled(const bool enabled)
|
||||
{
|
||||
m_automaticKitCreation = enabled;
|
||||
}
|
||||
|
||||
void McuPackage::updateStatus()
|
||||
{
|
||||
m_path = m_fileChooser->rawPath();
|
||||
@@ -713,5 +741,29 @@ Kit *McuSupportOptions::newKit(const McuTarget *mcuTarget, const McuPackage *qtF
|
||||
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
|
||||
} // McuSupport
|
||||
|
||||
@@ -71,9 +71,13 @@ public:
|
||||
void setEnvironmentVariableName(const QString &name);
|
||||
void setAddToPath(bool addToPath);
|
||||
bool addToPath() const;
|
||||
void writeGeneralSettings() const;
|
||||
void writeToSettings() const;
|
||||
void setRelativePathModifier(const QString &path);
|
||||
|
||||
bool automaticKitCreationEnabled() const;
|
||||
void setAutomaticKitCreationEnabled(const bool enabled);
|
||||
|
||||
QWidget *widget();
|
||||
|
||||
QString environmentVariableName() const;
|
||||
@@ -98,6 +102,7 @@ private:
|
||||
QString m_downloadUrl;
|
||||
QString m_environmentVariableName;
|
||||
bool m_addToPath = false;
|
||||
bool m_automaticKitCreation = true;
|
||||
|
||||
Status m_status = InvalidPath;
|
||||
};
|
||||
@@ -190,6 +195,7 @@ public:
|
||||
static QList<ProjectExplorer::Kit *> outdatedKits();
|
||||
static void removeOutdatedKits();
|
||||
static ProjectExplorer::Kit *newKit(const McuTarget *mcuTarget, const McuPackage *qtForMCUsSdk);
|
||||
static void createAutomaticKits();
|
||||
void populatePackagesAndTargets();
|
||||
static void registerQchFiles();
|
||||
static void registerExamples();
|
||||
|
||||
@@ -37,6 +37,7 @@
|
||||
#include <utils/qtcassert.h>
|
||||
#include <utils/utilsicons.h>
|
||||
|
||||
#include <QCheckBox>
|
||||
#include <QComboBox>
|
||||
#include <QDir>
|
||||
#include <QHBoxLayout>
|
||||
@@ -76,6 +77,7 @@ private:
|
||||
QGroupBox *m_mcuTargetsGroupBox = nullptr;
|
||||
QComboBox *m_mcuTargetsComboBox = nullptr;
|
||||
QGroupBox *m_kitCreationGroupBox = nullptr;
|
||||
QCheckBox *m_kitAutomaticCreationCheckBox = nullptr;
|
||||
Utils::InfoLabel *m_kitCreationInfoLabel = nullptr;
|
||||
Utils::InfoLabel *m_statusInfoLabel = nullptr;
|
||||
QPushButton *m_kitCreationPushButton = nullptr;
|
||||
@@ -126,6 +128,14 @@ McuSupportOptionsWidget::McuSupportOptionsWidget()
|
||||
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->setFlat(true);
|
||||
@@ -196,6 +206,9 @@ void McuSupportOptionsWidget::updateStatus()
|
||||
}
|
||||
}
|
||||
|
||||
// Automatic Kit creation
|
||||
m_kitAutomaticCreationCheckBox->setChecked(m_options.qtForMCUsSdkPackage->automaticKitCreationEnabled());
|
||||
|
||||
// Status label in the bottom
|
||||
{
|
||||
m_statusInfoLabel->setVisible(!cMakeAvailable);
|
||||
@@ -246,6 +259,7 @@ void McuSupportOptionsWidget::showEvent(QShowEvent *event)
|
||||
|
||||
void McuSupportOptionsWidget::apply()
|
||||
{
|
||||
m_options.qtForMCUsSdkPackage->writeGeneralSettings();
|
||||
m_options.qtForMCUsSdkPackage->writeToSettings();
|
||||
for (auto package : m_options.packages)
|
||||
package->writeToSettings();
|
||||
|
||||
@@ -95,6 +95,7 @@ void McuSupportPlugin::extensionsInitialized()
|
||||
|
||||
connect(KitManager::instance(), &KitManager::kitsLoaded, [](){
|
||||
McuSupportOptions::removeOutdatedKits();
|
||||
McuSupportOptions::createAutomaticKits();
|
||||
McuSupportPlugin::askUserAboutMcuSupportKitsSetup();
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user