From 15878965373b58402ebde73d01e0b1ee32f3c6c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Mu=C4=87ko?= Date: Thu, 21 Apr 2022 12:27:51 +0200 Subject: [PATCH] McuSupport: Use FilePath in version detector Change-Id: I54d04881c0b759caeaa83156c606a539369f482b Reviewed-by: Reviewed-by: Christiaan Janssen Reviewed-by: hjk --- src/plugins/mcusupport/mcukitmanager.cpp | 2 +- src/plugins/mcusupport/mcupackage.cpp | 12 +++++----- src/plugins/mcusupport/mcusupportoptions.cpp | 2 +- src/plugins/mcusupport/mcusupportsdk.cpp | 2 +- .../mcusupport/mcusupportversiondetection.cpp | 22 ++++++++++--------- .../mcusupport/mcusupportversiondetection.h | 12 +++++----- 6 files changed, 27 insertions(+), 25 deletions(-) diff --git a/src/plugins/mcusupport/mcukitmanager.cpp b/src/plugins/mcusupport/mcukitmanager.cpp index 551f8751776..b9048fe4d4f 100644 --- a/src/plugins/mcusupport/mcukitmanager.cpp +++ b/src/plugins/mcusupport/mcukitmanager.cpp @@ -213,7 +213,7 @@ public: // feature of the run configuration. Otherwise, we just prepend the path, here. if (mcuTarget->toolChainPackage()->isDesktopToolchain() && !CMakeProjectManager::CMakeToolManager::defaultCMakeTool()->hasFileApi()) - pathAdditions.append(qtForMCUsSdkPackage->path().pathAppended("bin").toUserOutput()); + pathAdditions.append((qtForMCUsSdkPackage->path() / "bin").toUserOutput()); auto processPackage = [&pathAdditions](const McuPackagePtr &package) { if (package->isAddToSystemPath()) diff --git a/src/plugins/mcusupport/mcupackage.cpp b/src/plugins/mcusupport/mcupackage.cpp index 05f3230688b..6de0cac48c1 100644 --- a/src/plugins/mcusupport/mcupackage.cpp +++ b/src/plugins/mcusupport/mcupackage.cpp @@ -110,7 +110,7 @@ FilePath McuPackage::basePath() const FilePath McuPackage::path() const { - return basePath().pathAppended(m_relativePathModifier.path()).absoluteFilePath(); + return (basePath() / m_relativePathModifier.path()).absoluteFilePath().cleanPath(); } FilePath McuPackage::defaultPath() const @@ -133,10 +133,10 @@ void McuPackage::updatePath() void McuPackage::updateStatus() { bool validPath = !m_path.isEmpty() && m_path.exists(); - const FilePath detectionPath = basePath().pathAppended(m_detectionPath.path()); + const FilePath detectionPath = basePath() / m_detectionPath.path(); const bool validPackage = m_detectionPath.isEmpty() || detectionPath.exists(); m_detectedVersion = validPath && validPackage && m_versionDetector - ? m_versionDetector->parseVersion(basePath().toString()) + ? m_versionDetector->parseVersion(basePath()) : QString(); const bool validVersion = m_detectedVersion.isEmpty() || m_versions.isEmpty() || m_versions.contains(m_detectedVersion); @@ -394,7 +394,7 @@ ToolChain *McuToolChainPackage::toolChain(Id language) const case ToolChainType::GCC: return gccToolChain(language); case ToolChainType::IAR: { - const FilePath compiler = path().pathAppended("/bin/iccarm").withExecutableSuffix(); + const FilePath compiler = (path() / "/bin/iccarm").withExecutableSuffix(); return iarToolChain(compiler, language); } case ToolChainType::ArmGcc: @@ -407,7 +407,7 @@ ToolChain *McuToolChainPackage::toolChain(Id language) const const QString comp = QLatin1String(m_type == ToolChainType::ArmGcc ? "/bin/arm-none-eabi-%1" : "/bar/foo-keil-%1") .arg(compilerName); - const FilePath compiler = path().pathAppended(comp).withExecutableSuffix(); + const FilePath compiler = (path() / comp).withExecutableSuffix(); return armGccToolChain(compiler, language); } @@ -469,7 +469,7 @@ QVariant McuToolChainPackage::debuggerId() const return QVariant(); } - const FilePath command = path().pathAppended(sub).withExecutableSuffix(); + const FilePath command = (path() / sub).withExecutableSuffix(); if (const DebuggerItem *debugger = DebuggerItemManager::findByCommand(command)) { return debugger->id(); } diff --git a/src/plugins/mcusupport/mcusupportoptions.cpp b/src/plugins/mcusupport/mcusupportoptions.cpp index 51a30723853..d303781935d 100644 --- a/src/plugins/mcusupport/mcusupportoptions.cpp +++ b/src/plugins/mcusupport/mcusupportoptions.cpp @@ -77,7 +77,7 @@ static FilePath qulDocsDir() const FilePath qulDir = McuSupportOptions::qulDirFromSettings(); if (qulDir.isEmpty() || !qulDir.exists()) return {}; - const FilePath docsDir = qulDir.pathAppended("docs"); + const FilePath docsDir = qulDir / "docs"; return docsDir.exists() ? docsDir : FilePath(); } diff --git a/src/plugins/mcusupport/mcusupportsdk.cpp b/src/plugins/mcusupport/mcusupportsdk.cpp index 8d3dbf177dd..f2a6836d88c 100644 --- a/src/plugins/mcusupport/mcusupportsdk.cpp +++ b/src/plugins/mcusupport/mcusupportsdk.cpp @@ -571,7 +571,7 @@ static const QString legacySupportVersionFor(const QString &sdkVersion) bool checkDeprecatedSdkError(const Utils::FilePath &qulDir, QString &message) { const McuPackagePathVersionDetector versionDetector("(?<=\\bQtMCUs.)(\\d+\\.\\d+)"); - const QString sdkDetectedVersion = versionDetector.parseVersion(qulDir.toString()); + const QString sdkDetectedVersion = versionDetector.parseVersion(qulDir); const QString legacyVersion = legacySupportVersionFor(sdkDetectedVersion); if (!legacyVersion.isEmpty()) { diff --git a/src/plugins/mcusupport/mcusupportversiondetection.cpp b/src/plugins/mcusupport/mcusupportversiondetection.cpp index b0db7638015..992d50f29b8 100644 --- a/src/plugins/mcusupport/mcusupportversiondetection.cpp +++ b/src/plugins/mcusupport/mcusupportversiondetection.cpp @@ -46,19 +46,21 @@ QString matchRegExp(const QString &text, const QString ®Exp) McuPackageVersionDetector::McuPackageVersionDetector() {} McuPackageExecutableVersionDetector::McuPackageExecutableVersionDetector( - const Utils::FilePath &detectionPath, const QStringList &detectionArgs, const QString &detectionRegExp) + const Utils::FilePath &detectionPath, + const QStringList &detectionArgs, + const QString &detectionRegExp) : McuPackageVersionDetector() , m_detectionPath(detectionPath) , m_detectionArgs(detectionArgs) , m_detectionRegExp(detectionRegExp) {} -QString McuPackageExecutableVersionDetector::parseVersion(const QString &packagePath) const +QString McuPackageExecutableVersionDetector::parseVersion(const Utils::FilePath &packagePath) const { if (m_detectionPath.isEmpty() || m_detectionRegExp.isEmpty()) return QString(); - const Utils::FilePath binaryPath = Utils::FilePath::fromString(packagePath).pathAppended(m_detectionPath.path()); + const Utils::FilePath binaryPath = packagePath / m_detectionPath.path(); if (!binaryPath.exists()) return QString(); @@ -89,9 +91,9 @@ McuPackageXmlVersionDetector::McuPackageXmlVersionDetector(const QString &filePa , m_versionRegExp(versionRegExp) {} -QString McuPackageXmlVersionDetector::parseVersion(const QString &packagePath) const +QString McuPackageXmlVersionDetector::parseVersion(const Utils::FilePath &packagePath) const { - const auto files = QDir(packagePath, m_filePattern).entryInfoList(); + const auto files = QDir(packagePath.toString(), m_filePattern).entryInfoList(); for (const auto &xmlFile : files) { QFile sdkXmlFile = QFile(xmlFile.absoluteFilePath()); sdkXmlFile.open(QFile::OpenModeFlag::ReadOnly); @@ -117,9 +119,9 @@ McuPackageDirectoryVersionDetector::McuPackageDirectoryVersionDetector(const QSt , m_isFile(isFile) {} -QString McuPackageDirectoryVersionDetector::parseVersion(const QString &packagePath) const +QString McuPackageDirectoryVersionDetector::parseVersion(const Utils::FilePath &packagePath) const { - const auto files = QDir(packagePath, m_filePattern) + const auto files = QDir(packagePath.toString(), m_filePattern) .entryInfoList(m_isFile ? QDir::Filter::Files : QDir::Filter::Dirs); for (const auto &entry : files) { const QString matched = matchRegExp(entry.fileName(), m_versionRegExp); @@ -133,11 +135,11 @@ McuPackagePathVersionDetector::McuPackagePathVersionDetector(const QString &vers : m_versionRegExp(versionRegExp) {} -QString McuPackagePathVersionDetector::parseVersion(const QString &packagePath) const +QString McuPackagePathVersionDetector::parseVersion(const Utils::FilePath &packagePath) const { - if (!Utils::FilePath::fromString(packagePath).exists()) + if (!packagePath.exists()) return QString(); - return matchRegExp(packagePath, m_versionRegExp); + return matchRegExp(packagePath.toString(), m_versionRegExp); } } // namespace Internal diff --git a/src/plugins/mcusupport/mcusupportversiondetection.h b/src/plugins/mcusupport/mcusupportversiondetection.h index c5f25875d0d..53aaad1e931 100644 --- a/src/plugins/mcusupport/mcusupportversiondetection.h +++ b/src/plugins/mcusupport/mcusupportversiondetection.h @@ -25,8 +25,8 @@ #pragma once -#include #include +#include namespace McuSupport { namespace Internal { @@ -37,7 +37,7 @@ class McuPackageVersionDetector : public QObject public: McuPackageVersionDetector(); virtual ~McuPackageVersionDetector() = default; - virtual QString parseVersion(const QString &packagePath) const = 0; + virtual QString parseVersion(const Utils::FilePath &packagePath) const = 0; }; // Get version from the output of an executable @@ -47,7 +47,7 @@ public: McuPackageExecutableVersionDetector(const Utils::FilePath &detectionPath, const QStringList &detectionArgs, const QString &detectionRegExp); - QString parseVersion(const QString &packagePath) const final; + QString parseVersion(const Utils::FilePath &packagePath) const final; private: const Utils::FilePath m_detectionPath; @@ -63,7 +63,7 @@ public: const QString &elementName, const QString &versionAttribute, const QString &versionRegExp); - QString parseVersion(const QString &packagePath) const final; + QString parseVersion(const Utils::FilePath &packagePath) const final; private: const QString m_filePattern; @@ -79,7 +79,7 @@ public: McuPackageDirectoryVersionDetector(const QString &filePattern, const QString &versionRegExp, const bool isFile); - QString parseVersion(const QString &packagePath) const final; + QString parseVersion(const Utils::FilePath &packagePath) const final; private: const QString m_filePattern; @@ -92,7 +92,7 @@ class McuPackagePathVersionDetector : public McuPackageVersionDetector { public: McuPackagePathVersionDetector(const QString &versionRegExp); - QString parseVersion(const QString &packagePath) const final; + QString parseVersion(const Utils::FilePath &packagePath) const final; private: const QString m_versionRegExp;