McuSupport: Use FilePath::fromUserInput instead of fromString

to normalize path separators for all OS-es

Change-Id: Iad6ea4abf21ba57705e07007bb238ebd7748ecfe
Reviewed-by: hjk <hjk@qt.io>
Reviewed-by: Dawid Śliwa <dawid.sliwa@qt.io>
This commit is contained in:
Piotr Mućko
2022-07-25 20:02:11 +02:00
parent 2361353289
commit 2e70915ab0
6 changed files with 39 additions and 36 deletions

View File

@@ -26,9 +26,9 @@
#include "mcukitinformation.h"
#include <cmakeprojectmanager/cmakekitinformation.h>
#include <utils/qtcassert.h>
#include <utils/algorithm.h>
#include <utils/filepath.h>
#include <utils/qtcassert.h>
using namespace ProjectExplorer;
@@ -74,17 +74,17 @@ Tasks McuDependenciesKitAspect::validate(const Kit *kit) const
// check paths defined in cmake variables for given dependencies exist
const auto cMakeEntries = Utils::NameValueDictionary(configuration(kit));
for (const auto &dependency: dependencies(kit)) {
auto givenPath = Utils::FilePath::fromString(cMakeEntries.value(dependency.name));
for (const auto &dependency : dependencies(kit)) {
auto givenPath = Utils::FilePath::fromUserInput(cMakeEntries.value(dependency.name));
if (givenPath.isEmpty()) {
result << BuildSystemTask(Task::Warning, tr("CMake variable %1 not defined.").arg(
dependency.name));
result << BuildSystemTask(Task::Warning,
tr("CMake variable %1 not defined.").arg(dependency.name));
} else {
const auto detectionPath = givenPath.resolvePath(dependency.value);
if (!detectionPath.exists()) {
result << BuildSystemTask(Task::Warning, tr("CMake variable %1: path %2 does not exist.").arg(
dependency.name,
detectionPath.toUserOutput()));
result << BuildSystemTask(Task::Warning,
tr("CMake variable %1: path %2 does not exist.")
.arg(dependency.name, detectionPath.toUserOutput()));
}
}
}
@@ -94,11 +94,12 @@ Tasks McuDependenciesKitAspect::validate(const Kit *kit) const
void McuDependenciesKitAspect::fix(Kit *kit)
{
QTC_ASSERT(kit, return);
QTC_ASSERT(kit, return );
const QVariant variant = kit->value(McuDependenciesKitAspect::id());
if (!variant.isNull() && !variant.canConvert(QVariant::List)) {
qWarning("Kit \"%s\" has a wrong mcu dependencies value set.", qPrintable(kit->displayName()));
qWarning("Kit \"%s\" has a wrong mcu dependencies value set.",
qPrintable(kit->displayName()));
setDependencies(kit, Utils::NameValueItems());
}
}

View File

@@ -75,7 +75,7 @@ McuPackage::McuPackage(const SettingsHandler::Ptr &settingsHandler,
, m_downloadUrl(downloadUrl)
, m_addToSystemPath(addToSystemPath)
{
m_path = FilePath::fromString(
m_path = FilePath::fromUserInput(
qEnvironmentVariable(m_environmentVariableName.toStdString().c_str()));
if (!m_path.exists()) {
m_path = this->settingsHandler->getPath(settingsKey, QSettings::UserScope, m_defaultPath);

View File

@@ -395,7 +395,7 @@ static McuPackagePtr createStm32CubeProgrammerPackage(const SettingsHandler::Ptr
defaultPath = programPath;
}
const FilePath detectionPath = FilePath::fromString(
const FilePath detectionPath = FilePath::fromUserInput(
QLatin1String(Utils::HostOsInfo::isWindowsHost() ? "/bin/STM32_Programmer_CLI.exe"
: "/bin/STM32_Programmer.sh"));
@@ -433,7 +433,7 @@ static McuPackagePtr createMcuXpressoIdePackage(const SettingsHandler::Ptr &sett
defaultPath = subDirs.first();
}
} else {
const FilePath programPath = FilePath::fromString("/usr/local/mcuxpressoide/");
const FilePath programPath = FilePath::fromUserInput("/usr/local/mcuxpressoide/");
if (programPath.exists())
defaultPath = programPath;
}
@@ -468,10 +468,11 @@ static McuPackagePtr createCypressProgrammerPackage(const SettingsHandler::Ptr &
}
}
return McuPackagePtr{new McuPackage(settingsHandler,
return McuPackagePtr{
new McuPackage(settingsHandler,
"Cypress Auto Flash Utility",
defaultPath,
FilePath("/bin/openocd").withExecutableSuffix(),
FilePath::fromUserInput("/bin/openocd").withExecutableSuffix(),
"CypressAutoFlashUtil", // settings key
"INFINEON_AUTO_FLASH_UTILITY_DIR", // cmake var
envVar)}; // env var
@@ -657,8 +658,8 @@ static PackageDescription parsePackage(const QJsonObject &cmakeEntry)
cmakeEntry["cmakeVar"].toString(),
cmakeEntry["description"].toString(),
cmakeEntry["setting"].toString(),
FilePath::fromString(cmakeEntry["defaultValue"].toString()),
FilePath::fromString(cmakeEntry["validation"].toString()),
FilePath::fromUserInput(cmakeEntry["defaultValue"].toString()),
FilePath::fromUserInput(cmakeEntry["validation"].toString()),
versions,
parseVersionDetection(cmakeEntry),
false};
@@ -728,7 +729,7 @@ McuTargetDescription parseDescriptionJson(const QByteArray &data)
boardSdkPackage,
{
freeRTOS.value("envVar").toString(),
FilePath::fromString(freeRTOS.value("boardSdkSubDir").toString()),
FilePath::fromUserInput(freeRTOS.value("boardSdkSubDir").toString()),
freeRtosEntries,
}};
}
@@ -778,7 +779,7 @@ McuSdkRepository targetsAndPackages(const FilePath &qtForMCUSdkPath,
if (!file.open(QFile::ReadOnly))
continue;
const McuTargetDescription desc = parseDescriptionJson(file.readAll());
const auto pth = FilePath::fromString(fileInfo.filePath());
const auto pth = FilePath::fromUserInput(fileInfo.filePath());
bool ok = false;
const int compatVersion = desc.compatVersion.toInt(&ok);
if (!desc.compatVersion.isEmpty() && ok && compatVersion > MAX_COMPATIBILITY_VERSION) {

View File

@@ -67,7 +67,7 @@ McuPackageVersionDetector *createVersionDetection(const VersionDetection &versio
versionDetection.xmlAttribute,
versionDetection.regex};
else if (!versionDetection.executableArgs.isEmpty())
return new McuPackageExecutableVersionDetector{Utils::FilePath::fromString(
return new McuPackageExecutableVersionDetector{Utils::FilePath::fromUserInput(
versionDetection.filePattern),
QStringList{versionDetection.executableArgs},
versionDetection.regex};

View File

@@ -53,7 +53,7 @@ static FilePath packagePathFromSettings(const QString &settingsKey,
FilePath SettingsHandler::getPath(const QString &settingsKey,
QSettings::Scope scope,
const Utils::FilePath &defaultPath) const
const FilePath &defaultPath) const
{
//Use the default value for empty keys
if (settingsKey.isEmpty())
@@ -63,8 +63,8 @@ FilePath SettingsHandler::getPath(const QString &settingsKey,
}
bool SettingsHandler::write(const QString &settingsKey,
const Utils::FilePath &path,
const Utils::FilePath &defaultPath) const
const FilePath &path,
const FilePath &defaultPath) const
{
const FilePath savedPath = packagePathFromSettings(settingsKey,
*Core::ICore::settings(QSettings::UserScope),

View File

@@ -307,14 +307,15 @@ void McuSupportTest::initTestCase()
EXPECT_CALL(*freeRtosPackage, cmakeVariableName())
.WillRepeatedly(Return(QString{freeRtosCMakeVar}));
EXPECT_CALL(*freeRtosPackage, isValidStatus()).WillRepeatedly(Return(true));
EXPECT_CALL(*freeRtosPackage, path()).WillRepeatedly(Return(FilePath::fromString(freeRtosPath)));
EXPECT_CALL(*freeRtosPackage, path())
.WillRepeatedly(Return(FilePath::fromUserInput(freeRtosPath)));
EXPECT_CALL(*freeRtosPackage, isAddToSystemPath()).WillRepeatedly(Return(true));
EXPECT_CALL(*freeRtosPackage, detectionPath()).WillRepeatedly(Return(FilePath{}));
EXPECT_CALL(*sdkPackage, environmentVariableName()).WillRepeatedly(Return(QString{qulEnvVar}));
EXPECT_CALL(*sdkPackage, cmakeVariableName()).WillRepeatedly(Return(QString{qulCmakeVar}));
EXPECT_CALL(*sdkPackage, isValidStatus()).WillRepeatedly(Return(true));
EXPECT_CALL(*sdkPackage, path()).WillRepeatedly(Return(FilePath::fromString(qtForMcuSdkPath)));
EXPECT_CALL(*sdkPackage, path()).WillRepeatedly(Return(FilePath::fromUserInput(qtForMcuSdkPath)));
EXPECT_CALL(*sdkPackage, isAddToSystemPath()).WillRepeatedly(Return(true));
EXPECT_CALL(*sdkPackage, detectionPath()).WillRepeatedly(Return(FilePath{}));
@@ -324,7 +325,7 @@ void McuSupportTest::initTestCase()
.WillRepeatedly(Return(QString{Legacy::Constants::TOOLCHAIN_FILE_CMAKE_VARIABLE}));
EXPECT_CALL(*armGccToolchainFilePackage, isValidStatus()).WillRepeatedly(Return(true));
EXPECT_CALL(*armGccToolchainFilePackage, path())
.WillRepeatedly(Return(FilePath::fromString(armGccToolchainFilePath)));
.WillRepeatedly(Return(FilePath::fromUserInput(armGccToolchainFilePath)));
EXPECT_CALL(*armGccToolchainFilePackage, isAddToSystemPath()).WillRepeatedly(Return(false));
EXPECT_CALL(*armGccToolchainFilePackage, detectionPath()).WillRepeatedly(Return(FilePath{}));
@@ -829,9 +830,9 @@ void McuSupportTest::test_legacy_createTargetWithToolchainPackages()
EXPECT_CALL(*settingsMockPtr,
getPath(QString{Constants::SETTINGS_KEY_PACKAGE_QT_FOR_MCUS_SDK}, _, _))
.WillRepeatedly(Return(FilePath::fromString(qtForMcuSdkPath)));
.WillRepeatedly(Return(FilePath::fromUserInput(qtForMcuSdkPath)));
EXPECT_CALL(*settingsMockPtr, getPath(compilerSetting, _, _))
.WillRepeatedly(Return(FilePath::fromString(compilerPath)));
.WillRepeatedly(Return(FilePath::fromUserInput(compilerPath)));
const auto [targets, packages]{
targetsFromDescriptions({description}, settingsMockPtr, qtForMcuSdkPath, runLegacy)};
@@ -854,10 +855,10 @@ void McuSupportTest::test_createTargetWithToolchainPackages()
QFETCH(QStringList, versions);
EXPECT_CALL(*settingsMockPtr, getPath(compilerSetting, _, _))
.WillRepeatedly(Return(FilePath::fromString(compilerPath)));
.WillRepeatedly(Return(FilePath::fromUserInput(compilerPath)));
EXPECT_CALL(*settingsMockPtr, getPath(compilerSetting, _, _))
.WillRepeatedly(Return(FilePath::fromString(compilerPath)));
.WillRepeatedly(Return(FilePath::fromUserInput(compilerPath)));
const McuTargetDescription description = parseDescriptionJson(json.toLocal8Bit());
const auto [targets, packages]{
@@ -933,7 +934,7 @@ void McuSupportTest::test_legacy_createQtMCUsPackage()
{
EXPECT_CALL(*settingsMockPtr,
getPath(QString{Constants::SETTINGS_KEY_PACKAGE_QT_FOR_MCUS_SDK}, _, _))
.WillRepeatedly(Return(FilePath::fromString(qtForMcuSdkPath)));
.WillRepeatedly(Return(FilePath::fromUserInput(qtForMcuSdkPath)));
McuPackagePtr qtForMCUsSDK = createQtForMCUsPackage(settingsMockPtr);