QmlDesigner: Remove std::filesystem usage

Change-Id: I2282052a92e13744bceec3e5597670a68ba6db4c
Reviewed-by: Tim Jenssen <tim.jenssen@qt.io>
This commit is contained in:
Marco Bubke
2023-04-20 11:57:23 +02:00
parent 4132b308f5
commit d530d39dd3
3 changed files with 41 additions and 51 deletions

View File

@@ -78,8 +78,7 @@ extend_qtc_library(QmlDesignerCore
) )
extend_qtc_library(QmlDesignerCore extend_qtc_library(QmlDesignerCore
CONDITION TARGET Qt6::QmlDomPrivate AND TARGET Qt6::QmlCompilerPrivate AND Qt6_VERSION VERSION_GREATER_EQUAL 6.4.3 CONDITION TARGET Qt6::QmlDomPrivate AND TARGET Qt6::QmlCompilerPrivate AND Qt6_VERSION VERSION_GREATER_EQUAL 6.4.3
AND NOT (CMAKE_HOST_SYSTEM_NAME STREQUAL "Darwin" AND CMAKE_SYSTEM_VERSION VERSION_LESS 19)
DEPENDS Qt6::QmlDomPrivate Qt6::QmlCompilerPrivate DEPENDS Qt6::QmlDomPrivate Qt6::QmlCompilerPrivate
PUBLIC_DEFINES QDS_HAS_QMLPRIVATE PUBLIC_DEFINES QDS_HAS_QMLPRIVATE

View File

@@ -7,10 +7,9 @@
#include <private/qqmldirparser_p.h> #include <private/qqmldirparser_p.h>
#endif #endif
#include <QDirIterator>
#include <QFile> #include <QFile>
#include <filesystem>
namespace QmlDesigner { namespace QmlDesigner {
namespace { namespace {
@@ -49,38 +48,30 @@ void ModuleScanner::scan(const QStringList &modulePaths)
void ModuleScanner::scan([[maybe_unused]] std::string_view modulePath) void ModuleScanner::scan([[maybe_unused]] std::string_view modulePath)
{ {
#ifdef QDS_HAS_QMLPRIVATE #ifdef QDS_HAS_QMLPRIVATE
try { QDirIterator dirIterator{QString::fromUtf8(modulePath), QDir::Dirs, QDirIterator::Subdirectories};
const std::filesystem::path installDirectoryPath{modulePath};
auto current = std::filesystem::recursive_directory_iterator{installDirectoryPath}; while (dirIterator.hasNext()) {
auto end = std::filesystem::end(current); auto directoryPath = dirIterator.next();
QString qmldirPath = directoryPath + "/qmldir";
if (QFileInfo::exists(qmldirPath)) {
QQmlDirParser parser;
for (; current != end; ++current) { auto content = contentAsQString(qmldirPath);
const auto &entry = *current; if (!content)
auto path = entry.path(); continue;
if (path.filename() == "qmldir") { bool hasError = parser.parse(*content);
QQmlDirParser parser; if (hasError)
continue;
auto content = contentAsQString(QString::fromStdU16String(path.u16string())); auto moduleName = parser.typeNamespace();
if (!content)
continue;
bool hasError = parser.parse(*content); if (moduleName.isEmpty() || m_skip(moduleName))
if (hasError) continue;
continue;
auto moduleName = parser.typeNamespace(); m_modules.push_back(
Import::createLibraryImport(moduleName, createVersion(parser.components())));
if (moduleName.isEmpty() || m_skip(moduleName))
continue;
m_modules.push_back(
Import::createLibraryImport(moduleName, createVersion(parser.components())));
}
} }
} catch (const std::filesystem::filesystem_error &) {
return;
} }
#endif #endif
} }

View File

@@ -39,6 +39,7 @@
#include <coreplugin/icore.h> #include <coreplugin/icore.h>
#include <QDirIterator>
#include <QFileSystemWatcher> #include <QFileSystemWatcher>
#include <QQmlEngine> #include <QQmlEngine>
@@ -344,17 +345,23 @@ void projectQmldirPaths(::ProjectExplorer::Target *target, QStringList &qmldirPa
} }
#ifdef QDS_HAS_QMLPRIVATE #ifdef QDS_HAS_QMLPRIVATE
bool skipPath(const std::filesystem::path &path) QStringView currentDirectoryName(const QString &path)
{ {
auto directory = path.filename(); auto found = std::find(path.rbegin(), path.rend(), u'/');
qDebug() << path.string().data();
bool skip = directory == "QtApplicationManager" || directory == "QtInterfaceFramework" if (found == path.rend())
|| directory == "QtOpcUa" || directory == "Qt3D" || directory == "Qt3D" return {};
|| directory == "Scene2D" || directory == "Scene3D" || directory == "QtWayland"
|| directory == "Qt5Compat"; return QStringView{found.base(), path.end()};
if (skip) }
qDebug() << "skip" << path.string().data(); bool skipPath(const QString &path)
{
auto directory = currentDirectoryName(path);
bool skip = directory == u"QtApplicationManager" || directory == u"QtInterfaceFramework"
|| directory == u"QtOpcUa" || directory == u"Qt3D" || directory == u"Qt3D"
|| directory == u"Scene2D" || directory == u"Scene3D" || directory == u"QtWayland"
|| directory == u"Qt5Compat";
return skip; return skip;
} }
@@ -366,21 +373,14 @@ void qtQmldirPaths([[maybe_unused]] ::ProjectExplorer::Target *target,
#ifdef QDS_HAS_QMLPRIVATE #ifdef QDS_HAS_QMLPRIVATE
if (useProjectStorage()) { if (useProjectStorage()) {
const QString installDirectory = qmlPath(target).toString(); const QString installDirectory = qmlPath(target).toString();
QDirIterator dirIterator{installDirectory, QDir::Dirs, QDirIterator::Subdirectories};
const std::filesystem::path installDirectoryPath{installDirectory.toStdString()}; while (dirIterator.hasNext()) {
auto directoryPath = dirIterator.next();
auto current = std::filesystem::recursive_directory_iterator{installDirectoryPath}; QString qmldirPath = directoryPath + "/qmldir";
auto end = std::filesystem::end(current); if (!skipPath(directoryPath) && QFileInfo::exists(qmldirPath))
for (; current != end; ++current) { qmldirPaths.push_back(directoryPath);
const auto &entry = *current;
auto path = entry.path();
if (current.depth() < 3 && !current->is_regular_file() && skipPath(path)) {
current.disable_recursion_pending();
continue;
}
if (path.filename() == "qmldir") {
qmldirPaths.push_back(QString::fromStdU16String(path.generic_u16string()));
}
} }
} }
#endif #endif