McuSupport: Use FilePath in version detector

Change-Id: I54d04881c0b759caeaa83156c606a539369f482b
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
Reviewed-by: Christiaan Janssen <christiaan.janssen@qt.io>
Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
Piotr Mućko
2022-04-21 12:27:51 +02:00
parent 6e5415e95f
commit 1587896537
6 changed files with 27 additions and 25 deletions

View File

@@ -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())

View File

@@ -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();
}

View File

@@ -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();
}

View File

@@ -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()) {

View File

@@ -46,19 +46,21 @@ QString matchRegExp(const QString &text, const QString &regExp)
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

View File

@@ -25,8 +25,8 @@
#pragma once
#include <QObject>
#include <utils/filepath.h>
#include <QObject>
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;