CMakeProjectManager: Replace FilePath::toString

Replace occurrences of FilePath::toString with more sensible alternatives.
Use FilePath instead of QString where it makes sense.

Change-Id: I3569b39fa6042d26deeb1dc46e63e4a19efcdb58
Reviewed-by: Cristian Adam <cristian.adam@qt.io>
This commit is contained in:
Andrii Semkiv
2024-09-11 15:51:08 +02:00
parent d486a295e3
commit 7c428e6b5c
10 changed files with 54 additions and 49 deletions

View File

@@ -246,9 +246,12 @@ bool CMakeBuildSystem::supportsAction(Node *context, ProjectAction action, const
static QString relativeFilePaths(const FilePaths &filePaths, const FilePath &projectDir) static QString relativeFilePaths(const FilePaths &filePaths, const FilePath &projectDir)
{ {
return Utils::transform(filePaths, [projectDir](const FilePath &path) { return Utils::transform(
return path.canonicalPath().relativePathFrom(projectDir).cleanPath().toString(); filePaths,
}).join(' '); [projectDir](const FilePath &path) {
return path.canonicalPath().relativePathFrom(projectDir).cleanPath().path();
})
.join(' ');
}; };
static QString newFilesForFunction(const std::string &cmakeFunction, static QString newFilesForFunction(const std::string &cmakeFunction,
@@ -735,7 +738,7 @@ bool CMakeBuildSystem::addFiles(Node *context, const FilePaths &filePaths, FileP
{ {
FilePaths tsFiles, srcFiles; FilePaths tsFiles, srcFiles;
std::tie(tsFiles, srcFiles) = Utils::partition(filePaths, [](const FilePath &fp) { std::tie(tsFiles, srcFiles) = Utils::partition(filePaths, [](const FilePath &fp) {
return Utils::mimeTypeForFile(fp.toString()).name() == Utils::Constants::LINGUIST_MIMETYPE; return Utils::mimeTypeForFile(fp).name() == Utils::Constants::LINGUIST_MIMETYPE;
}); });
bool success = true; bool success = true;
if (!srcFiles.isEmpty()) if (!srcFiles.isEmpty())
@@ -862,7 +865,7 @@ RemovedFilesFromProject CMakeBuildSystem::removeFiles(Node *context,
bool haveGlobbing = false; bool haveGlobbing = false;
for (const auto &file : filePaths) { for (const auto &file : filePaths) {
const QString fileName const QString fileName
= file.canonicalPath().relativePathFrom(projDir).cleanPath().toString(); = file.canonicalPath().relativePathFrom(projDir).cleanPath().path();
auto filePos = projectFileArgumentPosition(targetName, fileName); auto filePos = projectFileArgumentPosition(targetName, fileName);
if (filePos) { if (filePos) {
@@ -944,7 +947,7 @@ bool CMakeBuildSystem::canRenameFile(Node *context,
if (auto n = dynamic_cast<CMakeTargetNode *>(context)) { if (auto n = dynamic_cast<CMakeTargetNode *>(context)) {
const FilePath projDir = n->filePath().canonicalPath(); const FilePath projDir = n->filePath().canonicalPath();
const QString oldRelPathName const QString oldRelPathName
= oldFilePath.canonicalPath().relativePathFrom(projDir).cleanPath().toString(); = oldFilePath.canonicalPath().relativePathFrom(projDir).cleanPath().path();
const QString targetName = n->buildKey(); const QString targetName = n->buildKey();
@@ -1366,7 +1369,7 @@ void CMakeBuildSystem::updateProjectData()
QStringList apps; QStringList apps;
for (const auto &target : std::as_const(m_buildTargets)) { for (const auto &target : std::as_const(m_buildTargets)) {
if (target.targetType == DynamicLibraryType) { if (target.targetType == DynamicLibraryType) {
res.insert(target.executable.parentDir().toString()); res.insert(target.executable.parentDir().path());
apps.push_back(target.executable.toUserOutput()); apps.push_back(target.executable.toUserOutput());
} }
// ### shall we add also the ExecutableType ? // ### shall we add also the ExecutableType ?
@@ -2192,8 +2195,9 @@ DeploymentData CMakeBuildSystem::deploymentDataFromFile() const
if (ct.targetType == ExecutableType || ct.targetType == DynamicLibraryType) { if (ct.targetType == ExecutableType || ct.targetType == DynamicLibraryType) {
if (!ct.executable.isEmpty() if (!ct.executable.isEmpty()
&& result.deployableForLocalFile(ct.executable).localFilePath() != ct.executable) { && result.deployableForLocalFile(ct.executable).localFilePath() != ct.executable) {
result.addFile(ct.executable, result.addFile(
deploymentPrefix + buildDir.relativeChildPath(ct.executable).toString(), ct.executable,
deploymentPrefix + buildDir.relativeChildPath(ct.executable).path(),
DeployableFile::TypeExecutable); DeployableFile::TypeExecutable);
} }
} }

View File

@@ -346,7 +346,7 @@ CMakeConfig CMakeConfig::fromArguments(const QStringList &list, QStringList &unk
CMakeConfig CMakeConfig::fromFile(const Utils::FilePath &cacheFile, QString *errorMessage) CMakeConfig CMakeConfig::fromFile(const Utils::FilePath &cacheFile, QString *errorMessage)
{ {
CMakeConfig result; CMakeConfig result;
QFile cache(cacheFile.toString()); QFile cache(cacheFile.toFSPathString());
if (!cache.open(QIODevice::ReadOnly | QIODevice::Text)) { if (!cache.open(QIODevice::ReadOnly | QIODevice::Text)) {
if (errorMessage) if (errorMessage)
*errorMessage = Tr::tr("Failed to open %1 for reading.").arg(cacheFile.toUserOutput()); *errorMessage = Tr::tr("Failed to open %1 for reading.").arg(cacheFile.toUserOutput());

View File

@@ -277,8 +277,8 @@ static QVariant findOrRegisterDebugger(
QString errorMessage; QString errorMessage;
debugger.reinitializeFromFile(&errorMessage, &env); debugger.reinitializeFromFile(&errorMessage, &env);
if (!errorMessage.isEmpty()) if (!errorMessage.isEmpty())
qCWarning(cmInputLog()) << "Error reinitializing debugger" << debuggerPath.toString() qCWarning(cmInputLog()) << "Error reinitializing debugger"
<< "Error:" << errorMessage; << debuggerPath.toUserOutput() << "Error:" << errorMessage;
return DebuggerItemManager::registerDebugger(debugger); return DebuggerItemManager::registerDebugger(debugger);
} else { } else {
@@ -572,11 +572,11 @@ static QMakeAndCMakePrefixPath qtInfoFromCMakeCache(const CMakeConfig &config,
} }
if (!cmakeMakeProgram.isEmpty()) { if (!cmakeMakeProgram.isEmpty()) {
args.push_back(QStringLiteral("-DCMAKE_MAKE_PROGRAM=%1").arg(cmakeMakeProgram.toString())); args.push_back(QStringLiteral("-DCMAKE_MAKE_PROGRAM=%1").arg(cmakeMakeProgram.path()));
} }
if (!toolchainFile.isEmpty()) { if (!toolchainFile.isEmpty()) {
args.push_back(QStringLiteral("-DCMAKE_TOOLCHAIN_FILE=%1").arg(toolchainFile.toString())); args.push_back(QStringLiteral("-DCMAKE_TOOLCHAIN_FILE=%1").arg(toolchainFile.path()));
} }
if (!prefixPath.isEmpty()) { if (!prefixPath.isEmpty()) {
args.push_back(QStringLiteral("-DCMAKE_PREFIX_PATH=%1").arg(prefixPath)); args.push_back(QStringLiteral("-DCMAKE_PREFIX_PATH=%1").arg(prefixPath));
@@ -585,7 +585,7 @@ static QMakeAndCMakePrefixPath qtInfoFromCMakeCache(const CMakeConfig &config,
args.push_back(QStringLiteral("-DCMAKE_FIND_ROOT_PATH=%1").arg(findRootPath)); args.push_back(QStringLiteral("-DCMAKE_FIND_ROOT_PATH=%1").arg(findRootPath));
} }
if (!hostPath.isEmpty()) { if (!hostPath.isEmpty()) {
args.push_back(QStringLiteral("-DQT_HOST_PATH=%1").arg(hostPath.toString())); args.push_back(QStringLiteral("-DQT_HOST_PATH=%1").arg(hostPath.path()));
} }
qCDebug(cmInputLog) << "CMake probing for qmake path: " << cmakeExecutable.toUserOutput() << args; qCDebug(cmInputLog) << "CMake probing for qmake path: " << cmakeExecutable.toUserOutput() << args;
@@ -717,20 +717,20 @@ void updateConfigWithDirectoryData(CMakeConfig &config, const std::unique_ptr<Di
}); });
if (it != config.end() && it->value.isEmpty()) if (it != config.end() && it->value.isEmpty())
it->value = tcd.compilerPath.toString().toUtf8(); it->value = tcd.compilerPath.path().toUtf8();
else else
config << CMakeConfigItem(key, config << CMakeConfigItem(
CMakeConfigItem::FILEPATH, key, CMakeConfigItem::FILEPATH, tcd.compilerPath.path().toUtf8());
tcd.compilerPath.toString().toUtf8());
}; };
updateCompilerValue("CMAKE_C_COMPILER", ProjectExplorer::Constants::C_LANGUAGE_ID); updateCompilerValue("CMAKE_C_COMPILER", ProjectExplorer::Constants::C_LANGUAGE_ID);
updateCompilerValue("CMAKE_CXX_COMPILER", ProjectExplorer::Constants::CXX_LANGUAGE_ID); updateCompilerValue("CMAKE_CXX_COMPILER", ProjectExplorer::Constants::CXX_LANGUAGE_ID);
if (data->qt.qt) if (data->qt.qt)
config << CMakeConfigItem("QT_QMAKE_EXECUTABLE", config << CMakeConfigItem(
"QT_QMAKE_EXECUTABLE",
CMakeConfigItem::FILEPATH, CMakeConfigItem::FILEPATH,
data->qt.qt->qmakeFilePath().toString().toUtf8()); data->qt.qt->qmakeFilePath().path().toUtf8());
} }
Toolchain *findExternalToolchain(const QString &presetArchitecture, const QString &presetToolset) Toolchain *findExternalToolchain(const QString &presetArchitecture, const QString &presetToolset)
@@ -811,7 +811,7 @@ Toolchain *findExternalToolchain(const QString &presetArchitecture, const QStrin
qCDebug(cmInputLog) << "For external architecture" << presetArchitecture qCDebug(cmInputLog) << "For external architecture" << presetArchitecture
<< "and toolset" << presetToolset << "and toolset" << presetToolset
<< "the following toolchain was selected:\n" << "the following toolchain was selected:\n"
<< compilerPath.toString(); << compilerPath.toUserOutput();
return true; return true;
}); });
} }

View File

@@ -616,7 +616,7 @@ void CMakeManager::buildFile(Node *node)
Target *target = project->activeTarget(); Target *target = project->activeTarget();
QTC_ASSERT(target, return); QTC_ASSERT(target, return);
const QString generator = CMakeGeneratorKitAspect::generator(target->kit()); const QString generator = CMakeGeneratorKitAspect::generator(target->kit());
const QString relativeSource = filePath.relativeChildPath(targetNode->filePath()).toString(); const FilePath relativeSource = filePath.relativeChildPath(targetNode->filePath());
Utils::FilePath targetBase; Utils::FilePath targetBase;
BuildConfiguration *bc = target->activeBuildConfiguration(); BuildConfiguration *bc = target->activeBuildConfiguration();
QTC_ASSERT(bc, return); QTC_ASSERT(bc, return);
@@ -631,7 +631,7 @@ void CMakeManager::buildFile(Node *node)
} }
auto cbc = static_cast<CMakeBuildSystem *>(bc->buildSystem()); auto cbc = static_cast<CMakeBuildSystem *>(bc->buildSystem());
const QString sourceFile = targetBase.pathAppended(relativeSource).toString(); const QString sourceFile = targetBase.resolvePath(relativeSource).path();
const QString objExtension = [&]() -> QString { const QString objExtension = [&]() -> QString {
const auto sourceKind = ProjectFile::classify(relativeSource); const auto sourceKind = ProjectFile::classify(relativeSource);
const QByteArray cmakeLangExtension = ProjectFile::isCxx(sourceKind) const QByteArray cmakeLangExtension = ProjectFile::isCxx(sourceKind)

View File

@@ -247,7 +247,7 @@ QVariant CMakeTargetNode::data(Id role) const
// or "-iphonesimulator" depending on the device type (which is unavailable here). // or "-iphonesimulator" depending on the device type (which is unavailable here).
// dir/target.app/target -> dir // dir/target.app/target -> dir
return m_artifact.parentDir().parentDir().toString(); return m_artifact.parentDir().parentDir().path();
} }
if (role == Ios::Constants::IosCmakeGenerator) if (role == Ios::Constants::IosCmakeGenerator)

View File

@@ -120,7 +120,7 @@ CMakeTool::CMakeTool(const Store &map, bool fromSdk) :
m_isAutoDetected = map.value(CMAKE_INFORMATION_AUTODETECTED, false).toBool(); m_isAutoDetected = map.value(CMAKE_INFORMATION_AUTODETECTED, false).toBool();
m_detectionSource = map.value(CMAKE_INFORMATION_DETECTIONSOURCE).toString(); m_detectionSource = map.value(CMAKE_INFORMATION_DETECTIONSOURCE).toString();
setFilePath(FilePath::fromUserInput(map.value(CMAKE_INFORMATION_COMMAND).toString())); setFilePath(FilePath::fromSettings(map.value(CMAKE_INFORMATION_COMMAND)));
m_qchFilePath = FilePath::fromSettings(map.value(CMAKE_INFORMATION_QCH_FILE_PATH)); m_qchFilePath = FilePath::fromSettings(map.value(CMAKE_INFORMATION_QCH_FILE_PATH));
@@ -178,8 +178,8 @@ Store CMakeTool::toMap() const
Store data; Store data;
data.insert(CMAKE_INFORMATION_DISPLAYNAME, m_displayName); data.insert(CMAKE_INFORMATION_DISPLAYNAME, m_displayName);
data.insert(CMAKE_INFORMATION_ID, m_id.toSetting()); data.insert(CMAKE_INFORMATION_ID, m_id.toSetting());
data.insert(CMAKE_INFORMATION_COMMAND, m_executable.toString()); data.insert(CMAKE_INFORMATION_COMMAND, m_executable.toSettings());
data.insert(CMAKE_INFORMATION_QCH_FILE_PATH, m_qchFilePath.toString()); data.insert(CMAKE_INFORMATION_QCH_FILE_PATH, m_qchFilePath.toSettings());
data.insert(CMAKE_INFORMATION_AUTO_CREATE_BUILD_DIRECTORY, m_autoCreateBuildDirectory); data.insert(CMAKE_INFORMATION_AUTO_CREATE_BUILD_DIRECTORY, m_autoCreateBuildDirectory);
if (m_readerType) if (m_readerType)
data.insert(CMAKE_INFORMATION_READERTYPE, data.insert(CMAKE_INFORMATION_READERTYPE,
@@ -384,16 +384,16 @@ FilePath CMakeTool::searchQchFile(const FilePath &executable)
return {}; return {};
FilePath prefixDir = executable.parentDir().parentDir(); FilePath prefixDir = executable.parentDir().parentDir();
QDir docDir{prefixDir.pathAppended("doc/cmake").toString()}; FilePath docDir = prefixDir.pathAppended("doc/cmake");
if (!docDir.exists()) if (!docDir.exists())
docDir.setPath(prefixDir.pathAppended("share/doc/cmake").toString()); docDir = prefixDir.pathAppended("share/doc/cmake");
if (!docDir.exists()) if (!docDir.exists())
return {}; return {};
const QStringList files = docDir.entryList(QStringList("*.qch")); const FilePaths files = docDir.dirEntries(QStringList("*.qch"));
for (const QString &docFile : files) { for (const FilePath &docFile : files) {
if (docFile.startsWith("cmake", Qt::CaseInsensitive)) { if (docFile.startsWith("cmake")) {
return FilePath::fromString(docDir.absoluteFilePath(docFile)); return docDir.resolvePath(docFile).absolutePath();
} }
} }

View File

@@ -350,7 +350,7 @@ void CMakeToolManager::updateDocumentation()
QStringList docs; QStringList docs;
for (const auto tool : tools) { for (const auto tool : tools) {
if (!tool->qchFilePath().isEmpty()) if (!tool->qchFilePath().isEmpty())
docs.append(tool->qchFilePath().toString()); docs.append(tool->qchFilePath().path());
} }
Core::HelpManager::registerDocumentation(docs); Core::HelpManager::registerDocumentation(docs);
} }

View File

@@ -94,8 +94,9 @@ void ConfigModelItemDelegate::setModelData(QWidget *editor, QAbstractItemModel *
ConfigModel::DataItem data = ConfigModel::dataItemFromIndex(index); ConfigModel::DataItem data = ConfigModel::dataItemFromIndex(index);
if (data.type == ConfigModel::DataItem::FILE || data.type == ConfigModel::DataItem::DIRECTORY) { if (data.type == ConfigModel::DataItem::FILE || data.type == ConfigModel::DataItem::DIRECTORY) {
auto edit = static_cast<PathChooser *>(editor); auto edit = static_cast<PathChooser *>(editor);
if (edit->unexpandedFilePath().toString() != data.value) const QString unexpandedFilePath = edit->unexpandedFilePath().path();
model->setData(index, edit->unexpandedFilePath().toString(), Qt::EditRole); if (unexpandedFilePath != data.value)
model->setData(index, unexpandedFilePath, Qt::EditRole);
return; return;
} else if (!data.values.isEmpty()) { } else if (!data.values.isEmpty()) {
auto edit = static_cast<QComboBox *>(editor); auto edit = static_cast<QComboBox *>(editor);

View File

@@ -315,7 +315,7 @@ void FileApiReader::makeBackupConfiguration(bool store)
if (!reply.renameFile(replyPrev)) if (!reply.renameFile(replyPrev))
Core::MessageManager::writeFlashing( Core::MessageManager::writeFlashing(
addCMakePrefix(Tr::tr("Failed to rename \"%1\" to \"%2\".") addCMakePrefix(Tr::tr("Failed to rename \"%1\" to \"%2\".")
.arg(reply.toString(), replyPrev.toString()))); .arg(reply.toUserOutput(), replyPrev.toUserOutput())));
} }
FilePath cmakeCacheTxt = m_parameters.buildDirectory.pathAppended(Constants::CMAKE_CACHE_TXT); FilePath cmakeCacheTxt = m_parameters.buildDirectory.pathAppended(Constants::CMAKE_CACHE_TXT);
@@ -325,9 +325,9 @@ void FileApiReader::makeBackupConfiguration(bool store)
if (cmakeCacheTxt.exists()) if (cmakeCacheTxt.exists())
if (!FileUtils::copyIfDifferent(cmakeCacheTxt, cmakeCacheTxtPrev)) if (!FileUtils::copyIfDifferent(cmakeCacheTxt, cmakeCacheTxtPrev))
Core::MessageManager::writeFlashing( Core::MessageManager::writeFlashing(addCMakePrefix(
addCMakePrefix(Tr::tr("Failed to copy \"%1\" to \"%2\".") Tr::tr("Failed to copy \"%1\" to \"%2\".")
.arg(cmakeCacheTxt.toString(), cmakeCacheTxtPrev.toString()))); .arg(cmakeCacheTxt.toUserOutput(), cmakeCacheTxtPrev.toUserOutput())));
} }
void FileApiReader::writeConfigurationIntoBuildDirectory(const QStringList &configurationArguments) void FileApiReader::writeConfigurationIntoBuildDirectory(const QStringList &configurationArguments)

View File

@@ -37,8 +37,8 @@ static void expandAllButEnv(const PresetsDetails::ConfigurePreset &preset,
{ {
value.replace("${dollar}", "$"); value.replace("${dollar}", "$");
value.replace("${sourceDir}", sourceDirectory.toString()); value.replace("${sourceDir}", sourceDirectory.path());
value.replace("${sourceParentDir}", sourceDirectory.parentDir().toString()); value.replace("${sourceParentDir}", sourceDirectory.parentDir().path());
value.replace("${sourceDirName}", sourceDirectory.fileName()); value.replace("${sourceDirName}", sourceDirectory.fileName());
value.replace("${presetName}", preset.name); value.replace("${presetName}", preset.name);
@@ -57,9 +57,9 @@ static void expandAllButEnv(const PresetsDetails::BuildPreset &preset,
{ {
value.replace("${dollar}", "$"); value.replace("${dollar}", "$");
value.replace("${sourceDir}", sourceDirectory.toString()); value.replace("${sourceDir}", sourceDirectory.path());
value.replace("${fileDir}", preset.fileDir.path()); value.replace("${fileDir}", preset.fileDir.path());
value.replace("${sourceParentDir}", sourceDirectory.parentDir().toString()); value.replace("${sourceParentDir}", sourceDirectory.parentDir().path());
value.replace("${sourceDirName}", sourceDirectory.fileName()); value.replace("${sourceDirName}", sourceDirectory.fileName());
value.replace("${presetName}", preset.name); value.replace("${presetName}", preset.name);
@@ -233,7 +233,7 @@ void updateToolchainFile(
if (!toolchainFile.exists()) if (!toolchainFile.exists())
return; return;
const QString toolchainFileString = toolchainFile.cleanPath().toString(); const QString toolchainFileString = toolchainFile.cleanPath().path();
// toolchainFile takes precedence to CMAKE_TOOLCHAIN_FILE // toolchainFile takes precedence to CMAKE_TOOLCHAIN_FILE
CMakeConfig cache = configurePreset.cacheVariables ? configurePreset.cacheVariables.value() CMakeConfig cache = configurePreset.cacheVariables ? configurePreset.cacheVariables.value()
@@ -270,7 +270,7 @@ void updateInstallDir(PresetsDetails::ConfigurePreset &configurePreset,
installDir = probePath; installDir = probePath;
} }
} }
installDirString = installDir.cleanPath().toString(); installDirString = installDir.cleanPath().path();
// installDir takes precedence to CMAKE_INSTALL_PREFIX // installDir takes precedence to CMAKE_INSTALL_PREFIX
CMakeConfig cache = configurePreset.cacheVariables ? configurePreset.cacheVariables.value() CMakeConfig cache = configurePreset.cacheVariables ? configurePreset.cacheVariables.value()