forked from qt-creator/qt-creator
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:
@@ -26,9 +26,9 @@
|
|||||||
#include "mcukitinformation.h"
|
#include "mcukitinformation.h"
|
||||||
|
|
||||||
#include <cmakeprojectmanager/cmakekitinformation.h>
|
#include <cmakeprojectmanager/cmakekitinformation.h>
|
||||||
#include <utils/qtcassert.h>
|
|
||||||
#include <utils/algorithm.h>
|
#include <utils/algorithm.h>
|
||||||
#include <utils/filepath.h>
|
#include <utils/filepath.h>
|
||||||
|
#include <utils/qtcassert.h>
|
||||||
|
|
||||||
using namespace ProjectExplorer;
|
using namespace ProjectExplorer;
|
||||||
|
|
||||||
@@ -74,17 +74,17 @@ Tasks McuDependenciesKitAspect::validate(const Kit *kit) const
|
|||||||
|
|
||||||
// check paths defined in cmake variables for given dependencies exist
|
// check paths defined in cmake variables for given dependencies exist
|
||||||
const auto cMakeEntries = Utils::NameValueDictionary(configuration(kit));
|
const auto cMakeEntries = Utils::NameValueDictionary(configuration(kit));
|
||||||
for (const auto &dependency: dependencies(kit)) {
|
for (const auto &dependency : dependencies(kit)) {
|
||||||
auto givenPath = Utils::FilePath::fromString(cMakeEntries.value(dependency.name));
|
auto givenPath = Utils::FilePath::fromUserInput(cMakeEntries.value(dependency.name));
|
||||||
if (givenPath.isEmpty()) {
|
if (givenPath.isEmpty()) {
|
||||||
result << BuildSystemTask(Task::Warning, tr("CMake variable %1 not defined.").arg(
|
result << BuildSystemTask(Task::Warning,
|
||||||
dependency.name));
|
tr("CMake variable %1 not defined.").arg(dependency.name));
|
||||||
} else {
|
} else {
|
||||||
const auto detectionPath = givenPath.resolvePath(dependency.value);
|
const auto detectionPath = givenPath.resolvePath(dependency.value);
|
||||||
if (!detectionPath.exists()) {
|
if (!detectionPath.exists()) {
|
||||||
result << BuildSystemTask(Task::Warning, tr("CMake variable %1: path %2 does not exist.").arg(
|
result << BuildSystemTask(Task::Warning,
|
||||||
dependency.name,
|
tr("CMake variable %1: path %2 does not exist.")
|
||||||
detectionPath.toUserOutput()));
|
.arg(dependency.name, detectionPath.toUserOutput()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -94,11 +94,12 @@ Tasks McuDependenciesKitAspect::validate(const Kit *kit) const
|
|||||||
|
|
||||||
void McuDependenciesKitAspect::fix(Kit *kit)
|
void McuDependenciesKitAspect::fix(Kit *kit)
|
||||||
{
|
{
|
||||||
QTC_ASSERT(kit, return);
|
QTC_ASSERT(kit, return );
|
||||||
|
|
||||||
const QVariant variant = kit->value(McuDependenciesKitAspect::id());
|
const QVariant variant = kit->value(McuDependenciesKitAspect::id());
|
||||||
if (!variant.isNull() && !variant.canConvert(QVariant::List)) {
|
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());
|
setDependencies(kit, Utils::NameValueItems());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -75,7 +75,7 @@ McuPackage::McuPackage(const SettingsHandler::Ptr &settingsHandler,
|
|||||||
, m_downloadUrl(downloadUrl)
|
, m_downloadUrl(downloadUrl)
|
||||||
, m_addToSystemPath(addToSystemPath)
|
, m_addToSystemPath(addToSystemPath)
|
||||||
{
|
{
|
||||||
m_path = FilePath::fromString(
|
m_path = FilePath::fromUserInput(
|
||||||
qEnvironmentVariable(m_environmentVariableName.toStdString().c_str()));
|
qEnvironmentVariable(m_environmentVariableName.toStdString().c_str()));
|
||||||
if (!m_path.exists()) {
|
if (!m_path.exists()) {
|
||||||
m_path = this->settingsHandler->getPath(settingsKey, QSettings::UserScope, m_defaultPath);
|
m_path = this->settingsHandler->getPath(settingsKey, QSettings::UserScope, m_defaultPath);
|
||||||
|
|||||||
@@ -395,7 +395,7 @@ static McuPackagePtr createStm32CubeProgrammerPackage(const SettingsHandler::Ptr
|
|||||||
defaultPath = programPath;
|
defaultPath = programPath;
|
||||||
}
|
}
|
||||||
|
|
||||||
const FilePath detectionPath = FilePath::fromString(
|
const FilePath detectionPath = FilePath::fromUserInput(
|
||||||
QLatin1String(Utils::HostOsInfo::isWindowsHost() ? "/bin/STM32_Programmer_CLI.exe"
|
QLatin1String(Utils::HostOsInfo::isWindowsHost() ? "/bin/STM32_Programmer_CLI.exe"
|
||||||
: "/bin/STM32_Programmer.sh"));
|
: "/bin/STM32_Programmer.sh"));
|
||||||
|
|
||||||
@@ -433,7 +433,7 @@ static McuPackagePtr createMcuXpressoIdePackage(const SettingsHandler::Ptr &sett
|
|||||||
defaultPath = subDirs.first();
|
defaultPath = subDirs.first();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
const FilePath programPath = FilePath::fromString("/usr/local/mcuxpressoide/");
|
const FilePath programPath = FilePath::fromUserInput("/usr/local/mcuxpressoide/");
|
||||||
if (programPath.exists())
|
if (programPath.exists())
|
||||||
defaultPath = programPath;
|
defaultPath = programPath;
|
||||||
}
|
}
|
||||||
@@ -468,13 +468,14 @@ static McuPackagePtr createCypressProgrammerPackage(const SettingsHandler::Ptr &
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return McuPackagePtr{new McuPackage(settingsHandler,
|
return McuPackagePtr{
|
||||||
"Cypress Auto Flash Utility",
|
new McuPackage(settingsHandler,
|
||||||
defaultPath,
|
"Cypress Auto Flash Utility",
|
||||||
FilePath("/bin/openocd").withExecutableSuffix(),
|
defaultPath,
|
||||||
"CypressAutoFlashUtil", // settings key
|
FilePath::fromUserInput("/bin/openocd").withExecutableSuffix(),
|
||||||
"INFINEON_AUTO_FLASH_UTILITY_DIR", // cmake var
|
"CypressAutoFlashUtil", // settings key
|
||||||
envVar)}; // env var
|
"INFINEON_AUTO_FLASH_UTILITY_DIR", // cmake var
|
||||||
|
envVar)}; // env var
|
||||||
}
|
}
|
||||||
|
|
||||||
static McuPackagePtr createRenesasProgrammerPackage(const SettingsHandler::Ptr &settingsHandler)
|
static McuPackagePtr createRenesasProgrammerPackage(const SettingsHandler::Ptr &settingsHandler)
|
||||||
@@ -657,8 +658,8 @@ static PackageDescription parsePackage(const QJsonObject &cmakeEntry)
|
|||||||
cmakeEntry["cmakeVar"].toString(),
|
cmakeEntry["cmakeVar"].toString(),
|
||||||
cmakeEntry["description"].toString(),
|
cmakeEntry["description"].toString(),
|
||||||
cmakeEntry["setting"].toString(),
|
cmakeEntry["setting"].toString(),
|
||||||
FilePath::fromString(cmakeEntry["defaultValue"].toString()),
|
FilePath::fromUserInput(cmakeEntry["defaultValue"].toString()),
|
||||||
FilePath::fromString(cmakeEntry["validation"].toString()),
|
FilePath::fromUserInput(cmakeEntry["validation"].toString()),
|
||||||
versions,
|
versions,
|
||||||
parseVersionDetection(cmakeEntry),
|
parseVersionDetection(cmakeEntry),
|
||||||
false};
|
false};
|
||||||
@@ -728,7 +729,7 @@ McuTargetDescription parseDescriptionJson(const QByteArray &data)
|
|||||||
boardSdkPackage,
|
boardSdkPackage,
|
||||||
{
|
{
|
||||||
freeRTOS.value("envVar").toString(),
|
freeRTOS.value("envVar").toString(),
|
||||||
FilePath::fromString(freeRTOS.value("boardSdkSubDir").toString()),
|
FilePath::fromUserInput(freeRTOS.value("boardSdkSubDir").toString()),
|
||||||
freeRtosEntries,
|
freeRtosEntries,
|
||||||
}};
|
}};
|
||||||
}
|
}
|
||||||
@@ -778,7 +779,7 @@ McuSdkRepository targetsAndPackages(const FilePath &qtForMCUSdkPath,
|
|||||||
if (!file.open(QFile::ReadOnly))
|
if (!file.open(QFile::ReadOnly))
|
||||||
continue;
|
continue;
|
||||||
const McuTargetDescription desc = parseDescriptionJson(file.readAll());
|
const McuTargetDescription desc = parseDescriptionJson(file.readAll());
|
||||||
const auto pth = FilePath::fromString(fileInfo.filePath());
|
const auto pth = FilePath::fromUserInput(fileInfo.filePath());
|
||||||
bool ok = false;
|
bool ok = false;
|
||||||
const int compatVersion = desc.compatVersion.toInt(&ok);
|
const int compatVersion = desc.compatVersion.toInt(&ok);
|
||||||
if (!desc.compatVersion.isEmpty() && ok && compatVersion > MAX_COMPATIBILITY_VERSION) {
|
if (!desc.compatVersion.isEmpty() && ok && compatVersion > MAX_COMPATIBILITY_VERSION) {
|
||||||
|
|||||||
@@ -67,7 +67,7 @@ McuPackageVersionDetector *createVersionDetection(const VersionDetection &versio
|
|||||||
versionDetection.xmlAttribute,
|
versionDetection.xmlAttribute,
|
||||||
versionDetection.regex};
|
versionDetection.regex};
|
||||||
else if (!versionDetection.executableArgs.isEmpty())
|
else if (!versionDetection.executableArgs.isEmpty())
|
||||||
return new McuPackageExecutableVersionDetector{Utils::FilePath::fromString(
|
return new McuPackageExecutableVersionDetector{Utils::FilePath::fromUserInput(
|
||||||
versionDetection.filePattern),
|
versionDetection.filePattern),
|
||||||
QStringList{versionDetection.executableArgs},
|
QStringList{versionDetection.executableArgs},
|
||||||
versionDetection.regex};
|
versionDetection.regex};
|
||||||
|
|||||||
@@ -53,7 +53,7 @@ static FilePath packagePathFromSettings(const QString &settingsKey,
|
|||||||
|
|
||||||
FilePath SettingsHandler::getPath(const QString &settingsKey,
|
FilePath SettingsHandler::getPath(const QString &settingsKey,
|
||||||
QSettings::Scope scope,
|
QSettings::Scope scope,
|
||||||
const Utils::FilePath &defaultPath) const
|
const FilePath &defaultPath) const
|
||||||
{
|
{
|
||||||
//Use the default value for empty keys
|
//Use the default value for empty keys
|
||||||
if (settingsKey.isEmpty())
|
if (settingsKey.isEmpty())
|
||||||
@@ -63,8 +63,8 @@ FilePath SettingsHandler::getPath(const QString &settingsKey,
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool SettingsHandler::write(const QString &settingsKey,
|
bool SettingsHandler::write(const QString &settingsKey,
|
||||||
const Utils::FilePath &path,
|
const FilePath &path,
|
||||||
const Utils::FilePath &defaultPath) const
|
const FilePath &defaultPath) const
|
||||||
{
|
{
|
||||||
const FilePath savedPath = packagePathFromSettings(settingsKey,
|
const FilePath savedPath = packagePathFromSettings(settingsKey,
|
||||||
*Core::ICore::settings(QSettings::UserScope),
|
*Core::ICore::settings(QSettings::UserScope),
|
||||||
|
|||||||
@@ -307,14 +307,15 @@ void McuSupportTest::initTestCase()
|
|||||||
EXPECT_CALL(*freeRtosPackage, cmakeVariableName())
|
EXPECT_CALL(*freeRtosPackage, cmakeVariableName())
|
||||||
.WillRepeatedly(Return(QString{freeRtosCMakeVar}));
|
.WillRepeatedly(Return(QString{freeRtosCMakeVar}));
|
||||||
EXPECT_CALL(*freeRtosPackage, isValidStatus()).WillRepeatedly(Return(true));
|
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, isAddToSystemPath()).WillRepeatedly(Return(true));
|
||||||
EXPECT_CALL(*freeRtosPackage, detectionPath()).WillRepeatedly(Return(FilePath{}));
|
EXPECT_CALL(*freeRtosPackage, detectionPath()).WillRepeatedly(Return(FilePath{}));
|
||||||
|
|
||||||
EXPECT_CALL(*sdkPackage, environmentVariableName()).WillRepeatedly(Return(QString{qulEnvVar}));
|
EXPECT_CALL(*sdkPackage, environmentVariableName()).WillRepeatedly(Return(QString{qulEnvVar}));
|
||||||
EXPECT_CALL(*sdkPackage, cmakeVariableName()).WillRepeatedly(Return(QString{qulCmakeVar}));
|
EXPECT_CALL(*sdkPackage, cmakeVariableName()).WillRepeatedly(Return(QString{qulCmakeVar}));
|
||||||
EXPECT_CALL(*sdkPackage, isValidStatus()).WillRepeatedly(Return(true));
|
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, isAddToSystemPath()).WillRepeatedly(Return(true));
|
||||||
EXPECT_CALL(*sdkPackage, detectionPath()).WillRepeatedly(Return(FilePath{}));
|
EXPECT_CALL(*sdkPackage, detectionPath()).WillRepeatedly(Return(FilePath{}));
|
||||||
|
|
||||||
@@ -324,7 +325,7 @@ void McuSupportTest::initTestCase()
|
|||||||
.WillRepeatedly(Return(QString{Legacy::Constants::TOOLCHAIN_FILE_CMAKE_VARIABLE}));
|
.WillRepeatedly(Return(QString{Legacy::Constants::TOOLCHAIN_FILE_CMAKE_VARIABLE}));
|
||||||
EXPECT_CALL(*armGccToolchainFilePackage, isValidStatus()).WillRepeatedly(Return(true));
|
EXPECT_CALL(*armGccToolchainFilePackage, isValidStatus()).WillRepeatedly(Return(true));
|
||||||
EXPECT_CALL(*armGccToolchainFilePackage, path())
|
EXPECT_CALL(*armGccToolchainFilePackage, path())
|
||||||
.WillRepeatedly(Return(FilePath::fromString(armGccToolchainFilePath)));
|
.WillRepeatedly(Return(FilePath::fromUserInput(armGccToolchainFilePath)));
|
||||||
EXPECT_CALL(*armGccToolchainFilePackage, isAddToSystemPath()).WillRepeatedly(Return(false));
|
EXPECT_CALL(*armGccToolchainFilePackage, isAddToSystemPath()).WillRepeatedly(Return(false));
|
||||||
EXPECT_CALL(*armGccToolchainFilePackage, detectionPath()).WillRepeatedly(Return(FilePath{}));
|
EXPECT_CALL(*armGccToolchainFilePackage, detectionPath()).WillRepeatedly(Return(FilePath{}));
|
||||||
|
|
||||||
@@ -829,9 +830,9 @@ void McuSupportTest::test_legacy_createTargetWithToolchainPackages()
|
|||||||
|
|
||||||
EXPECT_CALL(*settingsMockPtr,
|
EXPECT_CALL(*settingsMockPtr,
|
||||||
getPath(QString{Constants::SETTINGS_KEY_PACKAGE_QT_FOR_MCUS_SDK}, _, _))
|
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, _, _))
|
EXPECT_CALL(*settingsMockPtr, getPath(compilerSetting, _, _))
|
||||||
.WillRepeatedly(Return(FilePath::fromString(compilerPath)));
|
.WillRepeatedly(Return(FilePath::fromUserInput(compilerPath)));
|
||||||
|
|
||||||
const auto [targets, packages]{
|
const auto [targets, packages]{
|
||||||
targetsFromDescriptions({description}, settingsMockPtr, qtForMcuSdkPath, runLegacy)};
|
targetsFromDescriptions({description}, settingsMockPtr, qtForMcuSdkPath, runLegacy)};
|
||||||
@@ -854,10 +855,10 @@ void McuSupportTest::test_createTargetWithToolchainPackages()
|
|||||||
QFETCH(QStringList, versions);
|
QFETCH(QStringList, versions);
|
||||||
|
|
||||||
EXPECT_CALL(*settingsMockPtr, getPath(compilerSetting, _, _))
|
EXPECT_CALL(*settingsMockPtr, getPath(compilerSetting, _, _))
|
||||||
.WillRepeatedly(Return(FilePath::fromString(compilerPath)));
|
.WillRepeatedly(Return(FilePath::fromUserInput(compilerPath)));
|
||||||
|
|
||||||
EXPECT_CALL(*settingsMockPtr, getPath(compilerSetting, _, _))
|
EXPECT_CALL(*settingsMockPtr, getPath(compilerSetting, _, _))
|
||||||
.WillRepeatedly(Return(FilePath::fromString(compilerPath)));
|
.WillRepeatedly(Return(FilePath::fromUserInput(compilerPath)));
|
||||||
|
|
||||||
const McuTargetDescription description = parseDescriptionJson(json.toLocal8Bit());
|
const McuTargetDescription description = parseDescriptionJson(json.toLocal8Bit());
|
||||||
const auto [targets, packages]{
|
const auto [targets, packages]{
|
||||||
@@ -933,7 +934,7 @@ void McuSupportTest::test_legacy_createQtMCUsPackage()
|
|||||||
{
|
{
|
||||||
EXPECT_CALL(*settingsMockPtr,
|
EXPECT_CALL(*settingsMockPtr,
|
||||||
getPath(QString{Constants::SETTINGS_KEY_PACKAGE_QT_FOR_MCUS_SDK}, _, _))
|
getPath(QString{Constants::SETTINGS_KEY_PACKAGE_QT_FOR_MCUS_SDK}, _, _))
|
||||||
.WillRepeatedly(Return(FilePath::fromString(qtForMcuSdkPath)));
|
.WillRepeatedly(Return(FilePath::fromUserInput(qtForMcuSdkPath)));
|
||||||
|
|
||||||
McuPackagePtr qtForMCUsSDK = createQtForMCUsPackage(settingsMockPtr);
|
McuPackagePtr qtForMCUsSDK = createQtForMCUsPackage(settingsMockPtr);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user