forked from qt-creator/qt-creator
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:
@@ -213,7 +213,7 @@ public:
|
|||||||
// feature of the run configuration. Otherwise, we just prepend the path, here.
|
// feature of the run configuration. Otherwise, we just prepend the path, here.
|
||||||
if (mcuTarget->toolChainPackage()->isDesktopToolchain()
|
if (mcuTarget->toolChainPackage()->isDesktopToolchain()
|
||||||
&& !CMakeProjectManager::CMakeToolManager::defaultCMakeTool()->hasFileApi())
|
&& !CMakeProjectManager::CMakeToolManager::defaultCMakeTool()->hasFileApi())
|
||||||
pathAdditions.append(qtForMCUsSdkPackage->path().pathAppended("bin").toUserOutput());
|
pathAdditions.append((qtForMCUsSdkPackage->path() / "bin").toUserOutput());
|
||||||
|
|
||||||
auto processPackage = [&pathAdditions](const McuPackagePtr &package) {
|
auto processPackage = [&pathAdditions](const McuPackagePtr &package) {
|
||||||
if (package->isAddToSystemPath())
|
if (package->isAddToSystemPath())
|
||||||
|
@@ -110,7 +110,7 @@ FilePath McuPackage::basePath() const
|
|||||||
|
|
||||||
FilePath McuPackage::path() const
|
FilePath McuPackage::path() const
|
||||||
{
|
{
|
||||||
return basePath().pathAppended(m_relativePathModifier.path()).absoluteFilePath();
|
return (basePath() / m_relativePathModifier.path()).absoluteFilePath().cleanPath();
|
||||||
}
|
}
|
||||||
|
|
||||||
FilePath McuPackage::defaultPath() const
|
FilePath McuPackage::defaultPath() const
|
||||||
@@ -133,10 +133,10 @@ void McuPackage::updatePath()
|
|||||||
void McuPackage::updateStatus()
|
void McuPackage::updateStatus()
|
||||||
{
|
{
|
||||||
bool validPath = !m_path.isEmpty() && m_path.exists();
|
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();
|
const bool validPackage = m_detectionPath.isEmpty() || detectionPath.exists();
|
||||||
m_detectedVersion = validPath && validPackage && m_versionDetector
|
m_detectedVersion = validPath && validPackage && m_versionDetector
|
||||||
? m_versionDetector->parseVersion(basePath().toString())
|
? m_versionDetector->parseVersion(basePath())
|
||||||
: QString();
|
: QString();
|
||||||
const bool validVersion = m_detectedVersion.isEmpty() || m_versions.isEmpty()
|
const bool validVersion = m_detectedVersion.isEmpty() || m_versions.isEmpty()
|
||||||
|| m_versions.contains(m_detectedVersion);
|
|| m_versions.contains(m_detectedVersion);
|
||||||
@@ -394,7 +394,7 @@ ToolChain *McuToolChainPackage::toolChain(Id language) const
|
|||||||
case ToolChainType::GCC:
|
case ToolChainType::GCC:
|
||||||
return gccToolChain(language);
|
return gccToolChain(language);
|
||||||
case ToolChainType::IAR: {
|
case ToolChainType::IAR: {
|
||||||
const FilePath compiler = path().pathAppended("/bin/iccarm").withExecutableSuffix();
|
const FilePath compiler = (path() / "/bin/iccarm").withExecutableSuffix();
|
||||||
return iarToolChain(compiler, language);
|
return iarToolChain(compiler, language);
|
||||||
}
|
}
|
||||||
case ToolChainType::ArmGcc:
|
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"
|
const QString comp = QLatin1String(m_type == ToolChainType::ArmGcc ? "/bin/arm-none-eabi-%1"
|
||||||
: "/bar/foo-keil-%1")
|
: "/bar/foo-keil-%1")
|
||||||
.arg(compilerName);
|
.arg(compilerName);
|
||||||
const FilePath compiler = path().pathAppended(comp).withExecutableSuffix();
|
const FilePath compiler = (path() / comp).withExecutableSuffix();
|
||||||
|
|
||||||
return armGccToolChain(compiler, language);
|
return armGccToolChain(compiler, language);
|
||||||
}
|
}
|
||||||
@@ -469,7 +469,7 @@ QVariant McuToolChainPackage::debuggerId() const
|
|||||||
return QVariant();
|
return QVariant();
|
||||||
}
|
}
|
||||||
|
|
||||||
const FilePath command = path().pathAppended(sub).withExecutableSuffix();
|
const FilePath command = (path() / sub).withExecutableSuffix();
|
||||||
if (const DebuggerItem *debugger = DebuggerItemManager::findByCommand(command)) {
|
if (const DebuggerItem *debugger = DebuggerItemManager::findByCommand(command)) {
|
||||||
return debugger->id();
|
return debugger->id();
|
||||||
}
|
}
|
||||||
|
@@ -77,7 +77,7 @@ static FilePath qulDocsDir()
|
|||||||
const FilePath qulDir = McuSupportOptions::qulDirFromSettings();
|
const FilePath qulDir = McuSupportOptions::qulDirFromSettings();
|
||||||
if (qulDir.isEmpty() || !qulDir.exists())
|
if (qulDir.isEmpty() || !qulDir.exists())
|
||||||
return {};
|
return {};
|
||||||
const FilePath docsDir = qulDir.pathAppended("docs");
|
const FilePath docsDir = qulDir / "docs";
|
||||||
return docsDir.exists() ? docsDir : FilePath();
|
return docsDir.exists() ? docsDir : FilePath();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -571,7 +571,7 @@ static const QString legacySupportVersionFor(const QString &sdkVersion)
|
|||||||
bool checkDeprecatedSdkError(const Utils::FilePath &qulDir, QString &message)
|
bool checkDeprecatedSdkError(const Utils::FilePath &qulDir, QString &message)
|
||||||
{
|
{
|
||||||
const McuPackagePathVersionDetector versionDetector("(?<=\\bQtMCUs.)(\\d+\\.\\d+)");
|
const McuPackagePathVersionDetector versionDetector("(?<=\\bQtMCUs.)(\\d+\\.\\d+)");
|
||||||
const QString sdkDetectedVersion = versionDetector.parseVersion(qulDir.toString());
|
const QString sdkDetectedVersion = versionDetector.parseVersion(qulDir);
|
||||||
const QString legacyVersion = legacySupportVersionFor(sdkDetectedVersion);
|
const QString legacyVersion = legacySupportVersionFor(sdkDetectedVersion);
|
||||||
|
|
||||||
if (!legacyVersion.isEmpty()) {
|
if (!legacyVersion.isEmpty()) {
|
||||||
|
@@ -46,19 +46,21 @@ QString matchRegExp(const QString &text, const QString ®Exp)
|
|||||||
McuPackageVersionDetector::McuPackageVersionDetector() {}
|
McuPackageVersionDetector::McuPackageVersionDetector() {}
|
||||||
|
|
||||||
McuPackageExecutableVersionDetector::McuPackageExecutableVersionDetector(
|
McuPackageExecutableVersionDetector::McuPackageExecutableVersionDetector(
|
||||||
const Utils::FilePath &detectionPath, const QStringList &detectionArgs, const QString &detectionRegExp)
|
const Utils::FilePath &detectionPath,
|
||||||
|
const QStringList &detectionArgs,
|
||||||
|
const QString &detectionRegExp)
|
||||||
: McuPackageVersionDetector()
|
: McuPackageVersionDetector()
|
||||||
, m_detectionPath(detectionPath)
|
, m_detectionPath(detectionPath)
|
||||||
, m_detectionArgs(detectionArgs)
|
, m_detectionArgs(detectionArgs)
|
||||||
, m_detectionRegExp(detectionRegExp)
|
, 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())
|
if (m_detectionPath.isEmpty() || m_detectionRegExp.isEmpty())
|
||||||
return QString();
|
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())
|
if (!binaryPath.exists())
|
||||||
return QString();
|
return QString();
|
||||||
|
|
||||||
@@ -89,9 +91,9 @@ McuPackageXmlVersionDetector::McuPackageXmlVersionDetector(const QString &filePa
|
|||||||
, m_versionRegExp(versionRegExp)
|
, 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) {
|
for (const auto &xmlFile : files) {
|
||||||
QFile sdkXmlFile = QFile(xmlFile.absoluteFilePath());
|
QFile sdkXmlFile = QFile(xmlFile.absoluteFilePath());
|
||||||
sdkXmlFile.open(QFile::OpenModeFlag::ReadOnly);
|
sdkXmlFile.open(QFile::OpenModeFlag::ReadOnly);
|
||||||
@@ -117,9 +119,9 @@ McuPackageDirectoryVersionDetector::McuPackageDirectoryVersionDetector(const QSt
|
|||||||
, m_isFile(isFile)
|
, 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);
|
.entryInfoList(m_isFile ? QDir::Filter::Files : QDir::Filter::Dirs);
|
||||||
for (const auto &entry : files) {
|
for (const auto &entry : files) {
|
||||||
const QString matched = matchRegExp(entry.fileName(), m_versionRegExp);
|
const QString matched = matchRegExp(entry.fileName(), m_versionRegExp);
|
||||||
@@ -133,11 +135,11 @@ McuPackagePathVersionDetector::McuPackagePathVersionDetector(const QString &vers
|
|||||||
: m_versionRegExp(versionRegExp)
|
: 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 QString();
|
||||||
return matchRegExp(packagePath, m_versionRegExp);
|
return matchRegExp(packagePath.toString(), m_versionRegExp);
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace Internal
|
} // namespace Internal
|
||||||
|
@@ -25,8 +25,8 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <QObject>
|
|
||||||
#include <utils/filepath.h>
|
#include <utils/filepath.h>
|
||||||
|
#include <QObject>
|
||||||
|
|
||||||
namespace McuSupport {
|
namespace McuSupport {
|
||||||
namespace Internal {
|
namespace Internal {
|
||||||
@@ -37,7 +37,7 @@ class McuPackageVersionDetector : public QObject
|
|||||||
public:
|
public:
|
||||||
McuPackageVersionDetector();
|
McuPackageVersionDetector();
|
||||||
virtual ~McuPackageVersionDetector() = default;
|
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
|
// Get version from the output of an executable
|
||||||
@@ -47,7 +47,7 @@ public:
|
|||||||
McuPackageExecutableVersionDetector(const Utils::FilePath &detectionPath,
|
McuPackageExecutableVersionDetector(const Utils::FilePath &detectionPath,
|
||||||
const QStringList &detectionArgs,
|
const QStringList &detectionArgs,
|
||||||
const QString &detectionRegExp);
|
const QString &detectionRegExp);
|
||||||
QString parseVersion(const QString &packagePath) const final;
|
QString parseVersion(const Utils::FilePath &packagePath) const final;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
const Utils::FilePath m_detectionPath;
|
const Utils::FilePath m_detectionPath;
|
||||||
@@ -63,7 +63,7 @@ public:
|
|||||||
const QString &elementName,
|
const QString &elementName,
|
||||||
const QString &versionAttribute,
|
const QString &versionAttribute,
|
||||||
const QString &versionRegExp);
|
const QString &versionRegExp);
|
||||||
QString parseVersion(const QString &packagePath) const final;
|
QString parseVersion(const Utils::FilePath &packagePath) const final;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
const QString m_filePattern;
|
const QString m_filePattern;
|
||||||
@@ -79,7 +79,7 @@ public:
|
|||||||
McuPackageDirectoryVersionDetector(const QString &filePattern,
|
McuPackageDirectoryVersionDetector(const QString &filePattern,
|
||||||
const QString &versionRegExp,
|
const QString &versionRegExp,
|
||||||
const bool isFile);
|
const bool isFile);
|
||||||
QString parseVersion(const QString &packagePath) const final;
|
QString parseVersion(const Utils::FilePath &packagePath) const final;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
const QString m_filePattern;
|
const QString m_filePattern;
|
||||||
@@ -92,7 +92,7 @@ class McuPackagePathVersionDetector : public McuPackageVersionDetector
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
McuPackagePathVersionDetector(const QString &versionRegExp);
|
McuPackagePathVersionDetector(const QString &versionRegExp);
|
||||||
QString parseVersion(const QString &packagePath) const final;
|
QString parseVersion(const Utils::FilePath &packagePath) const final;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
const QString m_versionRegExp;
|
const QString m_versionRegExp;
|
||||||
|
Reference in New Issue
Block a user