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
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)
CONDITION TARGET Qt6::QmlDomPrivate AND TARGET Qt6::QmlCompilerPrivate AND Qt6_VERSION VERSION_GREATER_EQUAL 6.4.3
DEPENDS Qt6::QmlDomPrivate Qt6::QmlCompilerPrivate
PUBLIC_DEFINES QDS_HAS_QMLPRIVATE

View File

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

View File

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