forked from qt-creator/qt-creator
McuSupport: Fix invalid version detector being instantiatied
In case the JSON entry was missing completely, a directory version detector was instantiated. Instantiate version dectectors only if there is enough and valid information available. Change-Id: Iaf9cd40165e4d75124f3e0ddda66db2f4dab5ff7 Reviewed-by: Daniele Bortolotti <daniele.bortolotti@qt.io> Reviewed-by: <github-actions-qt-creator@cristianadam.eu> Reviewed-by: Yasser Grimes <yasser.grimes@qt.io> Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
committed by
Rainer Keller
parent
6fae98477b
commit
34d0f2e678
@@ -36,10 +36,15 @@ McuPackageVersionDetector *createVersionDetection(const VersionDetection &versio
|
||||
versionDetection.filePattern),
|
||||
QStringList{versionDetection.executableArgs},
|
||||
versionDetection.regex};
|
||||
else
|
||||
else if (!versionDetection.filePattern.isEmpty() && !versionDetection.regex.isEmpty())
|
||||
return new McuPackageDirectoryVersionDetector(versionDetection.filePattern,
|
||||
versionDetection.regex,
|
||||
versionDetection.isFile);
|
||||
else {
|
||||
// In this case the JSON entry is either invalid or missing.
|
||||
// After refactoring, this should raise a JSON error to the user.
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
static void removeEmptyPackages(Packages &packages)
|
||||
|
@@ -1638,4 +1638,68 @@ void McuSupportTest::test_addToSystemPathFlag()
|
||||
QCOMPARE(freeRtosPackage.shouldAddToSystemPath, false);
|
||||
}
|
||||
|
||||
void McuSupportTest::test_nonemptyVersionDetector()
|
||||
{
|
||||
PackageDescription pkgDesc;
|
||||
pkgDesc.label = "GNU Arm Embedded Toolchain";
|
||||
pkgDesc.envVar = "ARMGCC_DIR";
|
||||
// pkgDesc.cmakeVar left empty
|
||||
// pkgDesc.description left empty
|
||||
pkgDesc.setting = "GNUArmEmbeddedToolchain";
|
||||
// pkgDesc.defaultPath left empty
|
||||
// pkgDesc.validationPath left empty
|
||||
// pkgDesc.versions left empty
|
||||
pkgDesc.versionDetection.filePattern = "bin/arm-none-eabi-g++";
|
||||
pkgDesc.versionDetection.regex = "\\bv?(\\d+\\.\\d+\\.\\d+)\\b";
|
||||
pkgDesc.versionDetection.executableArgs = "--version";
|
||||
// pkgDesc.versionDetection.xmlElement left empty
|
||||
// pkgDesc.versionDetection.xmlAttribute left empty
|
||||
pkgDesc.shouldAddToSystemPath = false;
|
||||
|
||||
const auto package = targetFactory.createPackage(pkgDesc);
|
||||
QVERIFY(package->getVersionDetector() != nullptr);
|
||||
QCOMPARE(typeid(*package->getVersionDetector()).name(),
|
||||
typeid(McuPackageExecutableVersionDetector).name());
|
||||
}
|
||||
|
||||
void McuSupportTest::test_emptyVersionDetector()
|
||||
{
|
||||
PackageDescription pkgDesc;
|
||||
pkgDesc.label = "GNU Arm Embedded Toolchain";
|
||||
pkgDesc.envVar = "ARMGCC_DIR";
|
||||
// pkgDesc.cmakeVar left empty
|
||||
// pkgDesc.description left empty
|
||||
pkgDesc.setting = "GNUArmEmbeddedToolchain";
|
||||
// pkgDesc.defaultPath left empty
|
||||
// pkgDesc.validationPath left empty
|
||||
// pkgDesc.versions left empty
|
||||
// Version detection left completely empty
|
||||
// pkgDesc.versionDetection.filePattern
|
||||
// pkgDesc.versionDetection.regex
|
||||
// pkgDesc.versionDetection.executableArgs
|
||||
// pkgDesc.versionDetection.xmlElement
|
||||
// pkgDesc.versionDetection.xmlAttribute
|
||||
pkgDesc.shouldAddToSystemPath = false;
|
||||
|
||||
const auto package = targetFactory.createPackage(pkgDesc);
|
||||
QVERIFY(package->getVersionDetector() == nullptr);
|
||||
}
|
||||
|
||||
void McuSupportTest::test_emptyVersionDetectorFromJson()
|
||||
{
|
||||
const auto targetDescription = parseDescriptionJson(armgcc_mimxrt1050_evk_freertos_json);
|
||||
auto [targets, packages] = targetFactory.createTargets(targetDescription, sdkPackagePtr);
|
||||
|
||||
auto freeRtos = findOrDefault(packages, [](const McuPackagePtr &pkg) {
|
||||
return (pkg->cmakeVariableName() == freeRtosCMakeVar);
|
||||
});
|
||||
|
||||
QVERIFY2(!freeRtos->cmakeVariableName().isEmpty(), "The freeRTOS package was not found, but there should be one.");
|
||||
|
||||
// For the FreeRTOS package there used to be no version check defined. Use this package to check if this was
|
||||
// considered correctly
|
||||
QVERIFY(freeRtos->getVersionDetector() == nullptr);
|
||||
}
|
||||
|
||||
|
||||
} // namespace McuSupport::Internal::Test
|
||||
|
@@ -103,6 +103,10 @@ private slots:
|
||||
void test_differentValueForEachOperationSystem();
|
||||
void test_addToSystemPathFlag();
|
||||
|
||||
void test_nonemptyVersionDetector();
|
||||
void test_emptyVersionDetector();
|
||||
void test_emptyVersionDetectorFromJson();
|
||||
|
||||
private:
|
||||
QVersionNumber currentQulVersion{2, 0};
|
||||
PackageMock *freeRtosPackage{new PackageMock};
|
||||
|
Reference in New Issue
Block a user