McuSupport: Better management of older Qt for Mcu SDKs

Task-number: QTCREATORBUG-25337
Change-Id: Ib0b2f6c75a41a2a897c128455c7b6f761832f5d4
Reviewed-by: Dawid Śliwa <dawid.sliwa@qt.io>
Reviewed-by: hjk <hjk@qt.io>
Reviewed-by: Alessandro Portale <alessandro.portale@qt.io>
This commit is contained in:
Christiaan Janssen
2021-03-01 11:07:44 +01:00
committed by christiaan.janssen
parent e3d95ac094
commit 65215b01e8
5 changed files with 94 additions and 24 deletions

View File

@@ -193,8 +193,13 @@ void McuSupportOptionsWidget::updateStatus()
m_mcuTargetsInfoLabel->setVisible(valid && m_options.mcuTargets.isEmpty());
if (m_mcuTargetsInfoLabel->isVisible()) {
m_mcuTargetsInfoLabel->setType(Utils::InfoLabel::NotOk);
auto displayKitsPath = Sdk::kitsPath(Utils::FilePath::fromString(m_options.qtForMCUsSdkPackage->basePath())).toUserOutput();
m_mcuTargetsInfoLabel->setText(tr("No valid kit descriptions found at %1.").arg(displayKitsPath));
const auto sdkPath = Utils::FilePath::fromString(m_options.qtForMCUsSdkPackage->basePath());
QString deprecationMessage;
if (Sdk::checkDeprecatedSdkError(sdkPath, deprecationMessage))
m_mcuTargetsInfoLabel->setText(deprecationMessage);
else
m_mcuTargetsInfoLabel->setText(tr("No valid kit descriptions found at %1.")
.arg(Sdk::kitsPath(sdkPath).toUserOutput()));
}
}

View File

@@ -63,8 +63,7 @@ static QString findInProgramFiles(const QString &folder)
McuPackage *createQtForMCUsPackage()
{
auto result = new McuPackage(
McuPackage::tr("Qt for MCUs %1+ SDK").arg(
McuSupportOptions::minimalQulVersion().toString()),
McuPackage::tr("Qt for MCUs SDK"),
QDir::homePath(),
Utils::HostOsInfo::withExecutableSuffix("bin/qmltocpp"),
Constants::SETTINGS_KEY_PACKAGE_QT_FOR_MCUS_SDK);
@@ -497,7 +496,8 @@ protected:
boardSdkPkgs.insert(desc.boardSdkEnvVar, boardSdkPkg);
}
auto boardSdkPkg = boardSdkPkgs.value(desc.boardSdkEnvVar);
boardSdkPkg->setVersions(desc.boardSdkVersions);
if (QVersionNumber::fromString(desc.qulVersion) >= QVersionNumber({1,8}))
boardSdkPkg->setVersions(desc.boardSdkVersions);
boardSdkDefaultPath = boardSdkPkg->defaultPath();
required3rdPartyPkgs.append(boardSdkPkg);
}
@@ -609,6 +609,30 @@ static McuTargetDescription parseDescriptionJson(const QByteArray &data)
};
}
const QHash<QString, QString> oldSdkQtcRequiredVersion = {
{{"1.0"}, {"4.11.x"}},
{{"1.1"}, {"4.12.0 or 4.12.1"}},
{{"1.2"}, {"4.12.2 or 4.12.3"}},
};
bool checkDeprecatedSdkError(const Utils::FilePath &qulDir, QString &message)
{
const McuPackagePathVersionDetector versionDetector("(?<=\\bQtMCUs.)(\\d+\\.\\d+)");
const QString sdkDetectedVersion = versionDetector.parseVersion(qulDir.toString());
if (oldSdkQtcRequiredVersion.contains(sdkDetectedVersion)) {
message = McuTarget::tr("Qt for MCUs SDK version %1 detected, "
"only supported by QtCreator version %2. "
"SDK version %3 or greater required."
).arg(sdkDetectedVersion,
oldSdkQtcRequiredVersion.value(sdkDetectedVersion),
McuSupportOptions::minimalQulVersion().toString());
return true;
}
return false;
}
void targetsAndPackages(const Utils::FilePath &dir, QVector<McuPackage *> *packages,
QVector<McuTarget *> *mcuTargets)
{
@@ -621,11 +645,16 @@ void targetsAndPackages(const Utils::FilePath &dir, QVector<McuPackage *> *packa
continue;
const McuTargetDescription desc = parseDescriptionJson(file.readAll());
if (QVersionNumber::fromString(desc.qulVersion) < McuSupportOptions::minimalQulVersion()) {
auto pth = Utils::FilePath::fromString(fileInfo.filePath());
printMessage(McuTarget::tr("Skipped %1 - Unsupported version \"%2\" (should be >= %3)")
const auto pth = Utils::FilePath::fromString(fileInfo.filePath());
const QString qtcSupportText = oldSdkQtcRequiredVersion.contains(desc.qulVersion) ?
McuTarget::tr("Detected version \"%1\", only supported by Qt Creator %2.")
.arg(desc.qulVersion, oldSdkQtcRequiredVersion.value(desc.qulVersion))
: McuTarget::tr("Unsupported version \"%1\".")
.arg(desc.qulVersion);
printMessage(McuTarget::tr("Skipped %1. %2 Qt for MCUs version >= %3 required.")
.arg(
QDir::toNativeSeparators(pth.fileNameWithPathComponents(1)),
desc.qulVersion,
qtcSupportText,
McuSupportOptions::minimalQulVersion().toString()),
false);
continue;
@@ -633,10 +662,19 @@ void targetsAndPackages(const Utils::FilePath &dir, QVector<McuPackage *> *packa
descriptions.append(desc);
}
// No valid description means invalid SDK installation.
if (descriptions.empty() && kitsPath(dir).exists()) {
printMessage(McuTarget::tr("No valid kit descriptions found at %1.").arg(kitsPath(dir).toUserOutput()), true);
return;
// No valid description means invalid or old SDK installation.
if (descriptions.empty()) {
if (kitsPath(dir).exists()) {
printMessage(McuTarget::tr("No valid kit descriptions found at %1.")
.arg(kitsPath(dir).toUserOutput()), true);
return;
} else {
QString deprecationMessage;
if (checkDeprecatedSdkError(dir, deprecationMessage)) {
printMessage(deprecationMessage, true);
return;
}
}
}
// Workaround for missing JSON file for Desktop target.

View File

@@ -40,6 +40,8 @@ namespace Sdk {
McuPackage *createQtForMCUsPackage();
bool checkDeprecatedSdkError(const Utils::FilePath &qulDir, QString &message);
void targetsAndPackages(const Utils::FilePath &qulDir,
QVector<McuPackage*> *packages, QVector<McuTarget*> *mcuTargets);

View File

@@ -33,6 +33,15 @@
namespace McuSupport {
namespace Internal {
QString matchRegExp(const QString &text, const QString &regExp)
{
const QRegularExpression regularExpression(regExp);
const QRegularExpressionMatch match = regularExpression.match(text);
if (match.hasMatch())
return match.captured(regularExpression.captureCount());
return QString();
}
McuPackageVersionDetector::McuPackageVersionDetector()
{
}
@@ -57,7 +66,6 @@ QString McuPackageExecutableVersionDetector::parseVersion(const QString &package
if (!Utils::FilePath::fromString(binaryPath).exists())
return QString();
const QRegularExpression regExp(m_detectionRegExp);
const int execTimeout = 3000; // usually runs below 1s, but we want to be on the safe side
QProcess binaryProcess;
@@ -69,12 +77,10 @@ QString McuPackageExecutableVersionDetector::parseVersion(const QString &package
const QString processOutput = QString::fromUtf8(
binaryProcess.readAllStandardOutput().append(
binaryProcess.readAllStandardError()));
const QRegularExpressionMatch match = regExp.match(processOutput);
if (match.hasMatch())
return match.captured(regExp.captureCount());
return matchRegExp(processOutput, m_detectionRegExp);
}
// Fail gracefully: return empty string if execution failed or regexp did not match
// Fail gracefully: return empty string if execution failed
return QString();
}
@@ -91,7 +97,6 @@ McuPackageXmlVersionDetector::McuPackageXmlVersionDetector(const QString &filePa
QString McuPackageXmlVersionDetector::parseVersion(const QString &packagePath) const
{
const QRegularExpression regExp(m_versionRegExp);
const auto files = QDir(packagePath, m_filePattern).entryInfoList();
for (const auto &xmlFile: files) {
QFile sdkXmlFile = QFile(xmlFile.absoluteFilePath());
@@ -100,8 +105,8 @@ QString McuPackageXmlVersionDetector::parseVersion(const QString &packagePath) c
while (xmlReader.readNext()) {
if (xmlReader.name() == m_versionElement) {
const QString versionString = xmlReader.attributes().value(m_versionAttribute).toString();
const QRegularExpressionMatch match = regExp.match(versionString);
return match.hasMatch() ? match.captured(regExp.captureCount()) : versionString;
const QString matched = matchRegExp(versionString, m_versionRegExp);
return !matched.isEmpty() ? matched : versionString;
}
}
}
@@ -123,13 +128,24 @@ QString McuPackageDirectoryVersionDetector::parseVersion(const QString &packageP
const auto files = QDir(packagePath, m_filePattern)
.entryInfoList(m_isFile ? QDir::Filter::Files : QDir::Filter::Dirs);
for (const auto &entry: files) {
const QRegularExpression regExp(m_versionRegExp);
const QRegularExpressionMatch match = regExp.match(entry.fileName());
if (match.hasMatch())
return match.captured(regExp.captureCount());
const QString matched = matchRegExp(entry.fileName(), m_versionRegExp);
if (!matched.isEmpty())
return matched;
}
return QString();
}
McuPackagePathVersionDetector::McuPackagePathVersionDetector(const QString &versionRegExp)
: m_versionRegExp(versionRegExp)
{
}
QString McuPackagePathVersionDetector::parseVersion(const QString &packagePath) const
{
if (!Utils::FilePath::fromString(packagePath).exists())
return QString();
return matchRegExp(packagePath, m_versionRegExp);
}
} // Internal
} // McuSupport

View File

@@ -78,6 +78,15 @@ private:
const bool m_isFile;
};
// Get version from the path of the package itself
class McuPackagePathVersionDetector : public McuPackageVersionDetector {
public:
McuPackagePathVersionDetector(const QString &versionRegExp);
QString parseVersion(const QString &packagePath) const;
private:
const QString m_versionRegExp;
};
} // Internal
} // McuSupport