forked from qt-creator/qt-creator
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>
This commit is contained in:
@@ -42,12 +42,12 @@ McuPackage::McuPackage(const SettingsHandler::Ptr &settingsHandler,
|
|||||||
const QString &downloadUrl,
|
const QString &downloadUrl,
|
||||||
const McuPackageVersionDetector *versionDetector,
|
const McuPackageVersionDetector *versionDetector,
|
||||||
const bool addToSystemPath,
|
const bool addToSystemPath,
|
||||||
const Utils::PathChooser::Kind &valueType)
|
const Utils::PathChooser::Kind &valueType,
|
||||||
|
const bool useNewestVersionKey)
|
||||||
: settingsHandler(settingsHandler)
|
: settingsHandler(settingsHandler)
|
||||||
, m_label(label)
|
, m_label(label)
|
||||||
, m_defaultPath(settingsHandler->getPath(settingsKey, QSettings::SystemScope, defaultPath))
|
|
||||||
, m_detectionPaths(detectionPaths)
|
, m_detectionPaths(detectionPaths)
|
||||||
, m_settingsKey(settingsKey)
|
, m_settingsKey(settingsHandler->getVersionedKey(settingsKey, QSettings::SystemScope, versions, useNewestVersionKey))
|
||||||
, m_versionDetector(versionDetector)
|
, m_versionDetector(versionDetector)
|
||||||
, m_versions(versions)
|
, m_versions(versions)
|
||||||
, m_cmakeVariableName(cmakeVarName)
|
, m_cmakeVariableName(cmakeVarName)
|
||||||
@@ -56,7 +56,8 @@ McuPackage::McuPackage(const SettingsHandler::Ptr &settingsHandler,
|
|||||||
, m_addToSystemPath(addToSystemPath)
|
, m_addToSystemPath(addToSystemPath)
|
||||||
, m_valueType(valueType)
|
, 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()) {
|
if (m_path.isEmpty()) {
|
||||||
m_path = FilePath::fromUserInput(qtcEnvironmentVariable(m_environmentVariableName));
|
m_path = FilePath::fromUserInput(qtcEnvironmentVariable(m_environmentVariableName));
|
||||||
}
|
}
|
||||||
|
@@ -40,7 +40,8 @@ public:
|
|||||||
const McuPackageVersionDetector *versionDetector = nullptr,
|
const McuPackageVersionDetector *versionDetector = nullptr,
|
||||||
const bool addToPath = false,
|
const bool addToPath = false,
|
||||||
const Utils::PathChooser::Kind &valueType
|
const Utils::PathChooser::Kind &valueType
|
||||||
= Utils::PathChooser::Kind::ExistingDirectory);
|
= Utils::PathChooser::Kind::ExistingDirectory,
|
||||||
|
const bool useNewestVersionKey = false);
|
||||||
|
|
||||||
~McuPackage() override = default;
|
~McuPackage() override = default;
|
||||||
|
|
||||||
|
@@ -54,7 +54,13 @@ McuPackagePtr createQtForMCUsPackage(const SettingsHandler::Ptr &settingsHandler
|
|||||||
.withExecutableSuffix()}, // detectionPaths
|
.withExecutableSuffix()}, // detectionPaths
|
||||||
Constants::SETTINGS_KEY_PACKAGE_QT_FOR_MCUS_SDK, // settingsKey
|
Constants::SETTINGS_KEY_PACKAGE_QT_FOR_MCUS_SDK, // settingsKey
|
||||||
Legacy::Constants::QUL_CMAKE_VAR,
|
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 {
|
namespace Legacy {
|
||||||
|
@@ -10,6 +10,9 @@
|
|||||||
#include <utils/filepath.h>
|
#include <utils/filepath.h>
|
||||||
#include <utils/store.h>
|
#include <utils/store.h>
|
||||||
|
|
||||||
|
#include <QRegularExpression>
|
||||||
|
#include <QVersionNumber>
|
||||||
|
|
||||||
using namespace Utils;
|
using namespace Utils;
|
||||||
|
|
||||||
namespace McuSupport::Internal {
|
namespace McuSupport::Internal {
|
||||||
@@ -27,6 +30,68 @@ static FilePath packagePathFromSettings(const Key &settingsKey,
|
|||||||
return FilePath::fromUserInput(path);
|
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,
|
FilePath SettingsHandler::getPath(const Key &settingsKey,
|
||||||
QSettings::Scope scope,
|
QSettings::Scope scope,
|
||||||
const FilePath &defaultPath) const
|
const FilePath &defaultPath) const
|
||||||
|
@@ -18,6 +18,10 @@ public:
|
|||||||
virtual Utils::FilePath getPath(const Utils::Key &settingsKey,
|
virtual Utils::FilePath getPath(const Utils::Key &settingsKey,
|
||||||
QSettings::Scope scope,
|
QSettings::Scope scope,
|
||||||
const Utils::FilePath &m_defaultPath) const;
|
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,
|
virtual bool write(const Utils::Key &settingsKey,
|
||||||
const Utils::FilePath &path,
|
const Utils::FilePath &path,
|
||||||
|
Reference in New Issue
Block a user