diff --git a/src/plugins/mcusupport/mcusupportoptionspage.cpp b/src/plugins/mcusupport/mcusupportoptionspage.cpp index 4d577ebdd38..c7e714856a3 100644 --- a/src/plugins/mcusupport/mcusupportoptionspage.cpp +++ b/src/plugins/mcusupport/mcusupportoptionspage.cpp @@ -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())); } } diff --git a/src/plugins/mcusupport/mcusupportsdk.cpp b/src/plugins/mcusupport/mcusupportsdk.cpp index db7a83dcaa2..0f424adec53 100644 --- a/src/plugins/mcusupport/mcusupportsdk.cpp +++ b/src/plugins/mcusupport/mcusupportsdk.cpp @@ -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 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 *packages, QVector *mcuTargets) { @@ -621,11 +645,16 @@ void targetsAndPackages(const Utils::FilePath &dir, QVector *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 *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. diff --git a/src/plugins/mcusupport/mcusupportsdk.h b/src/plugins/mcusupport/mcusupportsdk.h index da471196122..f7519919e5f 100644 --- a/src/plugins/mcusupport/mcusupportsdk.h +++ b/src/plugins/mcusupport/mcusupportsdk.h @@ -40,6 +40,8 @@ namespace Sdk { McuPackage *createQtForMCUsPackage(); +bool checkDeprecatedSdkError(const Utils::FilePath &qulDir, QString &message); + void targetsAndPackages(const Utils::FilePath &qulDir, QVector *packages, QVector *mcuTargets); diff --git a/src/plugins/mcusupport/mcusupportversiondetection.cpp b/src/plugins/mcusupport/mcusupportversiondetection.cpp index e1b10d30ac4..1266202ef84 100644 --- a/src/plugins/mcusupport/mcusupportversiondetection.cpp +++ b/src/plugins/mcusupport/mcusupportversiondetection.cpp @@ -33,6 +33,15 @@ namespace McuSupport { namespace Internal { +QString matchRegExp(const QString &text, const QString ®Exp) +{ + 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 diff --git a/src/plugins/mcusupport/mcusupportversiondetection.h b/src/plugins/mcusupport/mcusupportversiondetection.h index ecf60296908..0ab01d8b06e 100644 --- a/src/plugins/mcusupport/mcusupportversiondetection.h +++ b/src/plugins/mcusupport/mcusupportversiondetection.h @@ -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