forked from qt-creator/qt-creator
McuSupport: Improve version detector logic
McuPackageDirectoryVersionDetector class name was misleading, McuPackageDirectoryEntriesVersionDetector better describes its purpose as it can be used to search for a regex match among the entries in packagePath filtered by filePattern. Also, remove isFile boolean member variable since is not needed for current use cases, ie Renesas Graphics library (RGL), and filePattern can be used instead. Also, improve version detector creation logic. If no filePattern is present in the Json kit file, the regex match is based on packagePath only, which is the correct way to detect the version for RGL. Task-number: UL-6642 Change-Id: I3ee2fdb623bdd77aea60f9eae3672b9b5aa40433 Reviewed-by: Rainer Keller <Rainer.Keller@qt.io> Reviewed-by: Christian Stenger <christian.stenger@qt.io> Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
This commit is contained in:
@@ -82,7 +82,7 @@ static McuPackageVersionDetector *generatePackageVersionDetector(const QString &
|
||||
R"(\b(\d+\.\d+\.\d+)\b)");
|
||||
|
||||
if (envVar.startsWith("RGL"))
|
||||
return new McuPackageDirectoryVersionDetector("rgl_*_obj_*", R"(\d+\.\d+\.\w+)", false);
|
||||
return new McuPackagePathVersionDetector(R"(\d+\.\d+\.\w+)");
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
@@ -613,7 +613,6 @@ VersionDetection parseVersionDetection(const QJsonObject &packageEntry)
|
||||
versioning["executableArgs"].toString(),
|
||||
versioning["xmlElement"].toString(),
|
||||
versioning["xmlAttribute"].toString(),
|
||||
versioning["isFile"].toBool(true),
|
||||
};
|
||||
}
|
||||
|
||||
|
@@ -80,18 +80,15 @@ QString McuPackageXmlVersionDetector::parseVersion(const FilePath &packagePath)
|
||||
return QString();
|
||||
}
|
||||
|
||||
McuPackageDirectoryVersionDetector::McuPackageDirectoryVersionDetector(const QString &filePattern,
|
||||
const QString &versionRegExp,
|
||||
const bool isFile)
|
||||
McuPackageDirectoryEntriesVersionDetector::McuPackageDirectoryEntriesVersionDetector(
|
||||
const QString &filePattern, const QString &versionRegExp)
|
||||
: m_filePattern(filePattern)
|
||||
, m_versionRegExp(versionRegExp)
|
||||
, m_isFile(isFile)
|
||||
{}
|
||||
|
||||
QString McuPackageDirectoryVersionDetector::parseVersion(const FilePath &packagePath) const
|
||||
QString McuPackageDirectoryEntriesVersionDetector::parseVersion(const FilePath &packagePath) const
|
||||
{
|
||||
const auto files = QDir(packagePath.toString(), m_filePattern)
|
||||
.entryInfoList(m_isFile ? QDir::Filter::Files : QDir::Filter::Dirs);
|
||||
const auto files = QDir(packagePath.toString(), m_filePattern).entryInfoList();
|
||||
for (const auto &entry : files) {
|
||||
const QString matched = matchRegExp(entry.fileName(), m_versionRegExp);
|
||||
if (!matched.isEmpty())
|
||||
|
@@ -49,18 +49,16 @@ private:
|
||||
};
|
||||
|
||||
// Get version from the filename of a given file/dir in the package directory
|
||||
class McuPackageDirectoryVersionDetector : public McuPackageVersionDetector
|
||||
class McuPackageDirectoryEntriesVersionDetector : public McuPackageVersionDetector
|
||||
{
|
||||
public:
|
||||
McuPackageDirectoryVersionDetector(const QString &filePattern,
|
||||
const QString &versionRegExp,
|
||||
const bool isFile);
|
||||
McuPackageDirectoryEntriesVersionDetector(const QString &filePattern,
|
||||
const QString &versionRegExp);
|
||||
QString parseVersion(const Utils::FilePath &packagePath) const final;
|
||||
|
||||
private:
|
||||
const QString m_filePattern;
|
||||
const QString m_versionRegExp;
|
||||
const bool m_isFile;
|
||||
};
|
||||
|
||||
// Get version from the path of the package itself
|
||||
|
@@ -18,7 +18,6 @@ struct VersionDetection
|
||||
QString executableArgs;
|
||||
QString xmlElement;
|
||||
QString xmlAttribute;
|
||||
bool isFile;
|
||||
}; // struct VersionDetection
|
||||
|
||||
struct PackageDescription
|
||||
|
@@ -37,9 +37,10 @@ McuPackageVersionDetector *createVersionDetection(const VersionDetection &versio
|
||||
QStringList{versionDetection.executableArgs},
|
||||
versionDetection.regex};
|
||||
else if (!versionDetection.filePattern.isEmpty() && !versionDetection.regex.isEmpty())
|
||||
return new McuPackageDirectoryVersionDetector(versionDetection.filePattern,
|
||||
versionDetection.regex,
|
||||
versionDetection.isFile);
|
||||
return new McuPackageDirectoryEntriesVersionDetector(versionDetection.filePattern,
|
||||
versionDetection.regex);
|
||||
else if (!versionDetection.regex.isEmpty())
|
||||
return new McuPackagePathVersionDetector(versionDetection.regex);
|
||||
else {
|
||||
// In this case the JSON entry is either invalid or missing.
|
||||
// After refactoring, this should raise a JSON error to the user.
|
||||
|
@@ -66,9 +66,7 @@ constexpr auto ghs_rh850_d1m1a_baremetal_json = R"(
|
||||
"type": "path",
|
||||
"defaultValue": "/Renesas_Electronics/D1x_RGL/rgl_ghs_D1Mx_obj_V.2.0.0a",
|
||||
"versionDetection": {
|
||||
"filePattern": "rgl_*_obj_*",
|
||||
"regex": "\\d+\\.\\d+\\.\\w+",
|
||||
"isFile": false
|
||||
"regex": "\\d+\\.\\d+\\.\\w+"
|
||||
},
|
||||
"optional": false
|
||||
}
|
||||
|
@@ -1357,15 +1357,13 @@ void McuSupportTest::test_passDirectoryVersionDetectorToRenesasBoardSdkPackage()
|
||||
{
|
||||
const McuTargetDescription description = parseDescriptionJson(ghs_rh850_d1m1a_baremetal_json);
|
||||
|
||||
QCOMPARE(description.boardSdk.versionDetection.filePattern, "rgl_*_obj_*");
|
||||
QCOMPARE(description.boardSdk.versionDetection.regex, R"(\d+\.\d+\.\w+)");
|
||||
QCOMPARE(description.boardSdk.versionDetection.isFile, false);
|
||||
|
||||
McuPackagePtr boardSdk{targetFactory.createPackage(description.boardSdk)};
|
||||
|
||||
const auto *versionDetector{boardSdk->getVersionDetector()};
|
||||
QVERIFY(versionDetector != nullptr);
|
||||
QCOMPARE(typeid(*versionDetector).name(), typeid(McuPackageDirectoryVersionDetector).name());
|
||||
QCOMPARE(typeid(*versionDetector).name(), typeid(McuPackagePathVersionDetector).name());
|
||||
}
|
||||
|
||||
void McuSupportTest::test_resolveEnvironmentVariablesInDefaultPath()
|
||||
|
Reference in New Issue
Block a user