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:
Daniele Bortolotti
2022-10-19 14:24:16 +02:00
parent 9566124cad
commit 16261ad472
7 changed files with 14 additions and 24 deletions

View File

@@ -82,7 +82,7 @@ static McuPackageVersionDetector *generatePackageVersionDetector(const QString &
R"(\b(\d+\.\d+\.\d+)\b)"); R"(\b(\d+\.\d+\.\d+)\b)");
if (envVar.startsWith("RGL")) if (envVar.startsWith("RGL"))
return new McuPackageDirectoryVersionDetector("rgl_*_obj_*", R"(\d+\.\d+\.\w+)", false); return new McuPackagePathVersionDetector(R"(\d+\.\d+\.\w+)");
return nullptr; return nullptr;
} }
@@ -613,7 +613,6 @@ VersionDetection parseVersionDetection(const QJsonObject &packageEntry)
versioning["executableArgs"].toString(), versioning["executableArgs"].toString(),
versioning["xmlElement"].toString(), versioning["xmlElement"].toString(),
versioning["xmlAttribute"].toString(), versioning["xmlAttribute"].toString(),
versioning["isFile"].toBool(true),
}; };
} }

View File

@@ -80,18 +80,15 @@ QString McuPackageXmlVersionDetector::parseVersion(const FilePath &packagePath)
return QString(); return QString();
} }
McuPackageDirectoryVersionDetector::McuPackageDirectoryVersionDetector(const QString &filePattern, McuPackageDirectoryEntriesVersionDetector::McuPackageDirectoryEntriesVersionDetector(
const QString &versionRegExp, const QString &filePattern, const QString &versionRegExp)
const bool isFile)
: m_filePattern(filePattern) : m_filePattern(filePattern)
, m_versionRegExp(versionRegExp) , 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) const auto files = QDir(packagePath.toString(), m_filePattern).entryInfoList();
.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);
if (!matched.isEmpty()) if (!matched.isEmpty())

View File

@@ -49,18 +49,16 @@ private:
}; };
// Get version from the filename of a given file/dir in the package directory // Get version from the filename of a given file/dir in the package directory
class McuPackageDirectoryVersionDetector : public McuPackageVersionDetector class McuPackageDirectoryEntriesVersionDetector : public McuPackageVersionDetector
{ {
public: public:
McuPackageDirectoryVersionDetector(const QString &filePattern, McuPackageDirectoryEntriesVersionDetector(const QString &filePattern,
const QString &versionRegExp, const QString &versionRegExp);
const bool isFile);
QString parseVersion(const Utils::FilePath &packagePath) const final; QString parseVersion(const Utils::FilePath &packagePath) const final;
private: private:
const QString m_filePattern; const QString m_filePattern;
const QString m_versionRegExp; const QString m_versionRegExp;
const bool m_isFile;
}; };
// Get version from the path of the package itself // Get version from the path of the package itself

View File

@@ -18,7 +18,6 @@ struct VersionDetection
QString executableArgs; QString executableArgs;
QString xmlElement; QString xmlElement;
QString xmlAttribute; QString xmlAttribute;
bool isFile;
}; // struct VersionDetection }; // struct VersionDetection
struct PackageDescription struct PackageDescription

View File

@@ -37,9 +37,10 @@ McuPackageVersionDetector *createVersionDetection(const VersionDetection &versio
QStringList{versionDetection.executableArgs}, QStringList{versionDetection.executableArgs},
versionDetection.regex}; versionDetection.regex};
else if (!versionDetection.filePattern.isEmpty() && !versionDetection.regex.isEmpty()) else if (!versionDetection.filePattern.isEmpty() && !versionDetection.regex.isEmpty())
return new McuPackageDirectoryVersionDetector(versionDetection.filePattern, return new McuPackageDirectoryEntriesVersionDetector(versionDetection.filePattern,
versionDetection.regex, versionDetection.regex);
versionDetection.isFile); else if (!versionDetection.regex.isEmpty())
return new McuPackagePathVersionDetector(versionDetection.regex);
else { else {
// In this case the JSON entry is either invalid or missing. // In this case the JSON entry is either invalid or missing.
// After refactoring, this should raise a JSON error to the user. // After refactoring, this should raise a JSON error to the user.

View File

@@ -66,9 +66,7 @@ constexpr auto ghs_rh850_d1m1a_baremetal_json = R"(
"type": "path", "type": "path",
"defaultValue": "/Renesas_Electronics/D1x_RGL/rgl_ghs_D1Mx_obj_V.2.0.0a", "defaultValue": "/Renesas_Electronics/D1x_RGL/rgl_ghs_D1Mx_obj_V.2.0.0a",
"versionDetection": { "versionDetection": {
"filePattern": "rgl_*_obj_*", "regex": "\\d+\\.\\d+\\.\\w+"
"regex": "\\d+\\.\\d+\\.\\w+",
"isFile": false
}, },
"optional": false "optional": false
} }

View File

@@ -1357,15 +1357,13 @@ void McuSupportTest::test_passDirectoryVersionDetectorToRenesasBoardSdkPackage()
{ {
const McuTargetDescription description = parseDescriptionJson(ghs_rh850_d1m1a_baremetal_json); 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.regex, R"(\d+\.\d+\.\w+)");
QCOMPARE(description.boardSdk.versionDetection.isFile, false);
McuPackagePtr boardSdk{targetFactory.createPackage(description.boardSdk)}; McuPackagePtr boardSdk{targetFactory.createPackage(description.boardSdk)};
const auto *versionDetector{boardSdk->getVersionDetector()}; const auto *versionDetector{boardSdk->getVersionDetector()};
QVERIFY(versionDetector != nullptr); QVERIFY(versionDetector != nullptr);
QCOMPARE(typeid(*versionDetector).name(), typeid(McuPackageDirectoryVersionDetector).name()); QCOMPARE(typeid(*versionDetector).name(), typeid(McuPackagePathVersionDetector).name());
} }
void McuSupportTest::test_resolveEnvironmentVariablesInDefaultPath() void McuSupportTest::test_resolveEnvironmentVariablesInDefaultPath()