aboutsummaryrefslogtreecommitdiffstats
path: root/src/plugins/mcusupport
diff options
context:
space:
mode:
authorSivert Krøvel <sivert.krovel@qt.io>2024-03-06 19:00:35 +0100
committerSivert Krøvel <sivert.krovel@qt.io>2024-03-11 14:37:57 +0000
commit68e178c041b0079e38874558b462d7f705e8d83f (patch)
tree9c26fb00def096861d87caf0f7d6d80a0138cdf2 /src/plugins/mcusupport
parent18e1c366488979fa4c892ebaf5600e14407aadd7 (diff)
McuSupport: Read versioned settings keys for MCU dependencies
In an accompanying change, the installer writes versioned settings keys. The version string will be appended to the existing key, after a single underscore character. When reading from the settings, the plugin first looks for keys matching one of the requested versions from the kit. Optionally, if no key for a matching version is found, the key for the newest version available is chosen. This only applies to the Qul SDK package for the time being. If no suitable versioned key is found, the plain unversioned settings key is picked Task-number: QTCREATORBUG-29194 Change-Id: I2db888390cfb64a4b7c78ebcf795543251cb7a1b Reviewed-by: Eike Ziller <eike.ziller@qt.io>
Diffstat (limited to 'src/plugins/mcusupport')
-rw-r--r--src/plugins/mcusupport/mcupackage.cpp9
-rw-r--r--src/plugins/mcusupport/mcupackage.h3
-rw-r--r--src/plugins/mcusupport/mcusupportsdk.cpp8
-rw-r--r--src/plugins/mcusupport/settingshandler.cpp65
-rw-r--r--src/plugins/mcusupport/settingshandler.h4
5 files changed, 83 insertions, 6 deletions
diff --git a/src/plugins/mcusupport/mcupackage.cpp b/src/plugins/mcusupport/mcupackage.cpp
index 15b6b589859..2ff913c680e 100644
--- a/src/plugins/mcusupport/mcupackage.cpp
+++ b/src/plugins/mcusupport/mcupackage.cpp
@@ -42,12 +42,12 @@ McuPackage::McuPackage(const SettingsHandler::Ptr &settingsHandler,
const QString &downloadUrl,
const McuPackageVersionDetector *versionDetector,
const bool addToSystemPath,
- const Utils::PathChooser::Kind &valueType)
+ const Utils::PathChooser::Kind &valueType,
+ const bool useNewestVersionKey)
: settingsHandler(settingsHandler)
, m_label(label)
- , m_defaultPath(settingsHandler->getPath(settingsKey, QSettings::SystemScope, defaultPath))
, m_detectionPaths(detectionPaths)
- , m_settingsKey(settingsKey)
+ , m_settingsKey(settingsHandler->getVersionedKey(settingsKey, QSettings::SystemScope, versions, useNewestVersionKey))
, m_versionDetector(versionDetector)
, m_versions(versions)
, m_cmakeVariableName(cmakeVarName)
@@ -56,7 +56,8 @@ McuPackage::McuPackage(const SettingsHandler::Ptr &settingsHandler,
, m_addToSystemPath(addToSystemPath)
, m_valueType(valueType)
{
- m_path = this->settingsHandler->getPath(settingsKey, QSettings::UserScope, m_defaultPath);
+ m_defaultPath = settingsHandler->getPath(m_settingsKey, QSettings::SystemScope, defaultPath);
+ m_path = settingsHandler->getPath(m_settingsKey, QSettings::UserScope, m_defaultPath);
if (m_path.isEmpty()) {
m_path = FilePath::fromUserInput(qtcEnvironmentVariable(m_environmentVariableName));
}
diff --git a/src/plugins/mcusupport/mcupackage.h b/src/plugins/mcusupport/mcupackage.h
index 2efeb5e127f..a74c08bcf2d 100644
--- a/src/plugins/mcusupport/mcupackage.h
+++ b/src/plugins/mcusupport/mcupackage.h
@@ -40,7 +40,8 @@ public:
const McuPackageVersionDetector *versionDetector = nullptr,
const bool addToPath = false,
const Utils::PathChooser::Kind &valueType
- = Utils::PathChooser::Kind::ExistingDirectory);
+ = Utils::PathChooser::Kind::ExistingDirectory,
+ const bool useNewestVersionKey = false);
~McuPackage() override = default;
diff --git a/src/plugins/mcusupport/mcusupportsdk.cpp b/src/plugins/mcusupport/mcusupportsdk.cpp
index 689ab875b42..18d62f41e91 100644
--- a/src/plugins/mcusupport/mcusupportsdk.cpp
+++ b/src/plugins/mcusupport/mcusupportsdk.cpp
@@ -54,7 +54,13 @@ McuPackagePtr createQtForMCUsPackage(const SettingsHandler::Ptr &settingsHandler
.withExecutableSuffix()}, // detectionPaths
Constants::SETTINGS_KEY_PACKAGE_QT_FOR_MCUS_SDK, // settingsKey
Legacy::Constants::QUL_CMAKE_VAR,
- Legacy::Constants::QUL_ENV_VAR)};
+ Legacy::Constants::QUL_ENV_VAR,
+ {}, // versions
+ {}, // downloadUrl
+ nullptr, // versionDetector
+ false, // addToPath
+ Utils::PathChooser::Kind::ExistingDirectory, // valueType
+ true)}; // useNewestVersionKey
}
namespace Legacy {
diff --git a/src/plugins/mcusupport/settingshandler.cpp b/src/plugins/mcusupport/settingshandler.cpp
index 2bae687cfc8..1ecec030b45 100644
--- a/src/plugins/mcusupport/settingshandler.cpp
+++ b/src/plugins/mcusupport/settingshandler.cpp
@@ -10,6 +10,9 @@
#include <utils/filepath.h>
#include <utils/store.h>
+#include <QRegularExpression>
+#include <QVersionNumber>
+
using namespace Utils;
namespace McuSupport::Internal {
@@ -27,6 +30,68 @@ static FilePath packagePathFromSettings(const Key &settingsKey,
return FilePath::fromUserInput(path);
}
+static Key getKeyForNewestVersion(const Key &plainKey,
+ QtcSettings &settings)
+{
+ const Key baseKey = Key(Constants::SETTINGS_KEY_PACKAGE_PREFIX + plainKey);
+
+ // Versioned keys have their version string after the last underscore character
+ // Only version strings on the format x[.y.z] are considered.
+ settings.beginGroup(Constants::SETTINGS_GROUP);
+ const QRegularExpression re(QString("%1_\\d+(\\.\\d+){0,2}$").arg(stringFromKey(baseKey)));
+ const QStringList matchingKeys = stringsFromKeys(settings.childKeys()).filter(re);
+ settings.endGroup();
+
+ if (matchingKeys.isEmpty()) {
+ return plainKey;
+ }
+ QVersionNumber newestVersion;
+ for (const auto &k: matchingKeys) {
+ const QString currentVersionStr = k.mid(k.lastIndexOf("_") + 1);
+ const auto currentVersion = QVersionNumber::fromString(currentVersionStr);
+ if (newestVersion.isNull() || newestVersion < currentVersion) {
+ newestVersion = currentVersion;
+ }
+ }
+ const QString newestVersionStr = QString("_%1").arg(newestVersion.toString());
+ return Key(plainKey + newestVersionStr.toLocal8Bit());
+}
+
+
+static Key getVersionedKeyFromSettings(const Key &plainKey,
+ QtcSettings &settings,
+ const QStringList &versions,
+ bool allowNewerVersions = false)
+{
+ const Key keyBase = Key(Constants::SETTINGS_GROUP) + '/'
+ + Constants::SETTINGS_KEY_PACKAGE_PREFIX;
+
+ // Always prefer one of the versions listed in the kit
+ for (const auto &versionString: versions) {
+ const Key versionedKey = plainKey + QString("_%1").arg(versionString).toLocal8Bit();
+
+ if (settings.contains(keyBase + versionedKey)) {
+ return versionedKey;
+ }
+ }
+
+ // Maybe find the newest version listed in the settings
+ if (allowNewerVersions) {
+ return getKeyForNewestVersion(plainKey, settings);
+ }
+
+ // Fall back to the plain key if no versioned key is found
+ return plainKey;
+}
+
+Key SettingsHandler::getVersionedKey(const Key &plainKey,
+ QSettings::Scope scope,
+ const QStringList &versions,
+ bool allowNewer) const
+{
+ return getVersionedKeyFromSettings(plainKey, *Core::ICore::settings(scope), versions, allowNewer);
+}
+
FilePath SettingsHandler::getPath(const Key &settingsKey,
QSettings::Scope scope,
const FilePath &defaultPath) const
diff --git a/src/plugins/mcusupport/settingshandler.h b/src/plugins/mcusupport/settingshandler.h
index c50dcde1e3c..c5ed62c6428 100644
--- a/src/plugins/mcusupport/settingshandler.h
+++ b/src/plugins/mcusupport/settingshandler.h
@@ -18,6 +18,10 @@ public:
virtual Utils::FilePath getPath(const Utils::Key &settingsKey,
QSettings::Scope scope,
const Utils::FilePath &m_defaultPath) const;
+ Utils::Key getVersionedKey(const Utils::Key &plainKey,
+ QSettings::Scope scope,
+ const QStringList &versions,
+ bool allowNewer) const;
virtual bool write(const Utils::Key &settingsKey,
const Utils::FilePath &path,