QmlJS: Proliferate FilePath use, part 3

Change-Id: I3c293a9974414b669a1af8b98afb76a4eb4fbd11
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
hjk
2021-10-28 15:02:33 +02:00
parent 45a716bd0c
commit 17a545115b
2 changed files with 35 additions and 41 deletions

View File

@@ -103,9 +103,9 @@ void PluginDumper::onLoadBuiltinTypes(const QmlJS::ModelManagerInterface::Projec
m_modelManager->updateLibraryInfo(info.qtQmlPath, builtinInfo); m_modelManager->updateLibraryInfo(info.qtQmlPath, builtinInfo);
// prefer QTDIR/qml/builtins.qmltypes if available // prefer QTDIR/qml/builtins.qmltypes if available
const QString builtinQmltypesPath = info.qtQmlPath.toString() + QLatin1String("/builtins.qmltypes"); const FilePath builtinQmltypesPath = info.qtQmlPath / "builtins.qmltypes";
if (QFile::exists(builtinQmltypesPath)) { if (builtinQmltypesPath.exists()) {
loadQmltypesFile(QStringList(builtinQmltypesPath), info.qtQmlPath, builtinInfo); loadQmltypesFile({builtinQmltypesPath}, info.qtQmlPath, builtinInfo);
return; return;
} }
@@ -113,13 +113,6 @@ void PluginDumper::onLoadBuiltinTypes(const QmlJS::ModelManagerInterface::Projec
m_qtToInfo.insert(info.qtQmlPath.toString(), info); m_qtToInfo.insert(info.qtQmlPath.toString(), info);
} }
static QString makeAbsolute(const QString &path, const QString &base)
{
if (QFileInfo(path).isAbsolute())
return path;
return QString::fromLatin1("%1/%3").arg(base, path);
}
void PluginDumper::onLoadPluginTypes(const QString &libraryPath, const QString &importPath, const QString &importUri, const QString &importVersion) void PluginDumper::onLoadPluginTypes(const QString &libraryPath, const QString &importPath, const QString &importUri, const QString &importVersion)
{ {
const FilePath canonicalLibraryPath = FilePath::fromUserInput(libraryPath).cleanPath(); const FilePath canonicalLibraryPath = FilePath::fromUserInput(libraryPath).cleanPath();
@@ -149,7 +142,7 @@ void PluginDumper::onLoadPluginTypes(const QString &libraryPath, const QString &
QDirIterator it(canonicalLibraryPath.toString(), QStringList { "*.qmltypes" }, QDir::Files); QDirIterator it(canonicalLibraryPath.toString(), QStringList { "*.qmltypes" }, QDir::Files);
while (it.hasNext()) { while (it.hasNext()) {
const QString defaultQmltypesPath = makeAbsolute(it.next(), canonicalLibraryPath.toString()); const FilePath defaultQmltypesPath = canonicalLibraryPath.resolvePath(it.next());
if (!plugin.typeInfoPaths.contains(defaultQmltypesPath)) if (!plugin.typeInfoPaths.contains(defaultQmltypesPath))
plugin.typeInfoPaths += defaultQmltypesPath; plugin.typeInfoPaths += defaultQmltypesPath;
@@ -157,8 +150,8 @@ void PluginDumper::onLoadPluginTypes(const QString &libraryPath, const QString &
// add typeinfo files listed in qmldir // add typeinfo files listed in qmldir
foreach (const QString &typeInfo, libraryInfo.typeInfos()) { foreach (const QString &typeInfo, libraryInfo.typeInfos()) {
QString pathNow = makeAbsolute(typeInfo, canonicalLibraryPath.toString()); const FilePath pathNow = canonicalLibraryPath.resolvePath(typeInfo);
if (!plugin.typeInfoPaths.contains(pathNow) && QFile::exists(pathNow)) if (!plugin.typeInfoPaths.contains(pathNow) && pathNow.exists())
plugin.typeInfoPaths += pathNow; plugin.typeInfoPaths += pathNow;
} }
@@ -167,19 +160,19 @@ void PluginDumper::onLoadPluginTypes(const QString &libraryPath, const QString &
const QString pluginLibrary = resolvePlugin(canonicalLibraryPath.toString(), plugin.path, plugin.name); const QString pluginLibrary = resolvePlugin(canonicalLibraryPath.toString(), plugin.path, plugin.name);
if (!pluginLibrary.isEmpty()) { if (!pluginLibrary.isEmpty()) {
if (!pluginWatcher()->watchesFile(pluginLibrary)) if (!pluginWatcher()->watchesFile(pluginLibrary))
pluginWatcher()->addFile(pluginLibrary, Utils::FileSystemWatcher::WatchModifiedDate); pluginWatcher()->addFile(pluginLibrary, FileSystemWatcher::WatchModifiedDate);
m_libraryToPluginIndex.insert(pluginLibrary, index); m_libraryToPluginIndex.insert(pluginLibrary, index);
} }
} }
// watch library qmltypes file // watch library qmltypes file
if (!plugin.typeInfoPaths.isEmpty()) { if (!plugin.typeInfoPaths.isEmpty()) {
foreach (const QString &path, plugin.typeInfoPaths) { for (const FilePath &path : qAsConst(plugin.typeInfoPaths)) {
if (!QFile::exists(path)) if (!path.exists())
continue; continue;
if (!pluginWatcher()->watchesFile(path)) if (!pluginWatcher()->watchesFile(path.toString()))
pluginWatcher()->addFile(path, Utils::FileSystemWatcher::WatchModifiedDate); pluginWatcher()->addFile(path.toString(), FileSystemWatcher::WatchModifiedDate);
m_libraryToPluginIndex.insert(path, index); m_libraryToPluginIndex.insert(path.toString(), index);
} }
} }
@@ -358,14 +351,15 @@ void PluginDumper::pluginChanged(const QString &pluginLibrary)
dump(plugin); dump(plugin);
} }
QFuture<PluginDumper::QmlTypeDescription> PluginDumper::loadQmlTypeDescription(const QStringList &paths) const { QFuture<PluginDumper::QmlTypeDescription> PluginDumper::loadQmlTypeDescription(const FilePaths &paths) const
{
auto future = Utils::runAsync([=](QFutureInterface<PluginDumper::QmlTypeDescription> &future) auto future = Utils::runAsync([=](QFutureInterface<PluginDumper::QmlTypeDescription> &future)
{ {
PluginDumper::QmlTypeDescription result; PluginDumper::QmlTypeDescription result;
for (const QString &p: paths) { for (const FilePath &p: paths) {
Utils::FileReader reader; Utils::FileReader reader;
if (!reader.fetch(Utils::FilePath::fromString(p), QFile::Text)) { if (!reader.fetch(p, QFile::Text)) {
result.errors += reader.errorString(); result.errors += reader.errorString();
continue; continue;
} }
@@ -375,9 +369,9 @@ QFuture<PluginDumper::QmlTypeDescription> PluginDumper::loadQmlTypeDescription(c
QList<ModuleApiInfo> apis; QList<ModuleApiInfo> apis;
QStringList deps; QStringList deps;
CppQmlTypesLoader::parseQmlTypeDescriptions(reader.data(), &objs, &apis, &deps, CppQmlTypesLoader::parseQmlTypeDescriptions(reader.data(), &objs, &apis, &deps,
&error, &warning, p); &error, &warning, p.toString());
if (!error.isEmpty()) { if (!error.isEmpty()) {
result.errors += tr("Failed to parse \"%1\".\nError: %2").arg(p, error); result.errors += tr("Failed to parse \"%1\".\nError: %2").arg(p.toUserOutput(), error);
} else { } else {
result.objects += objs.values(); result.objects += objs.values();
result.moduleApis += apis; result.moduleApis += apis;
@@ -441,27 +435,26 @@ QString PluginDumper::buildQmltypesPath(const QString &name) const
* Recursively load type descriptions of dependencies, collecting results * Recursively load type descriptions of dependencies, collecting results
* in \a objects. * in \a objects.
*/ */
QFuture<PluginDumper::DependencyInfo> PluginDumper::loadDependencies(const QStringList &dependencies, QFuture<PluginDumper::DependencyInfo> PluginDumper::loadDependencies(const FilePaths &dependencies,
QSharedPointer<QSet<QString>> visited) const QSharedPointer<QSet<FilePath>> visited) const
{ {
auto iface = QSharedPointer<QFutureInterface<PluginDumper::DependencyInfo>>(new QFutureInterface<PluginDumper::DependencyInfo>); auto iface = QSharedPointer<QFutureInterface<PluginDumper::DependencyInfo>>(new QFutureInterface<PluginDumper::DependencyInfo>);
if (visited.isNull()) { if (visited.isNull())
visited = QSharedPointer<QSet<QString>>(new QSet<QString>()); visited = QSharedPointer<QSet<FilePath>>(new QSet<FilePath>());
}
QStringList dependenciesPaths; FilePaths dependenciesPaths;
QString path; QString path;
for (const QString &name: dependencies) { for (const FilePath &name : dependencies) {
path = buildQmltypesPath(name); path = buildQmltypesPath(name.toString());
if (!path.isNull()) if (!path.isNull())
dependenciesPaths << path; dependenciesPaths << FilePath::fromString(path);
visited->insert(name); visited->insert(name);
} }
Utils::onFinished(loadQmlTypeDescription(dependenciesPaths), const_cast<PluginDumper*>(this), [=] (const QFuture<PluginDumper::QmlTypeDescription> &typesFuture) { Utils::onFinished(loadQmlTypeDescription(dependenciesPaths), const_cast<PluginDumper*>(this), [=] (const QFuture<PluginDumper::QmlTypeDescription> &typesFuture) {
PluginDumper::QmlTypeDescription typesResult = typesFuture.result(); PluginDumper::QmlTypeDescription typesResult = typesFuture.result();
QStringList newDependencies = typesResult.dependencies; FilePaths newDependencies = Utils::transform(typesResult.dependencies, &FilePath::fromString);
newDependencies = Utils::toList(Utils::toSet(newDependencies) - *visited.data()); newDependencies = Utils::toList(Utils::toSet(newDependencies) - *visited.data());
if (!newDependencies.isEmpty()) { if (!newDependencies.isEmpty()) {
Utils::onFinished(loadDependencies(newDependencies, visited), Utils::onFinished(loadDependencies(newDependencies, visited),
@@ -590,7 +583,7 @@ void PluginDumper::prepareLibraryInfo(LibraryInfo &libInfo,
libInfo.updateFingerprint(); libInfo.updateFingerprint();
} }
void PluginDumper::loadQmltypesFile(const QStringList &qmltypesFilePaths, void PluginDumper::loadQmltypesFile(const FilePaths &qmltypesFilePaths,
const FilePath &libraryPath, const FilePath &libraryPath,
QmlJS::LibraryInfo libraryInfo) QmlJS::LibraryInfo libraryInfo)
{ {
@@ -599,7 +592,8 @@ void PluginDumper::loadQmltypesFile(const QStringList &qmltypesFilePaths,
PluginDumper::QmlTypeDescription typesResult = typesFuture.result(); PluginDumper::QmlTypeDescription typesResult = typesFuture.result();
if (!typesResult.dependencies.isEmpty()) if (!typesResult.dependencies.isEmpty())
{ {
Utils::onFinished(loadDependencies(typesResult.dependencies, QSharedPointer<QSet<QString>>()), this, Utils::onFinished(loadDependencies(Utils::transform(typesResult.dependencies, &FilePath::fromString),
QSharedPointer<QSet<FilePath>>()), this,
[typesResult, libraryInfo, libraryPath, this] (const QFuture<PluginDumper::DependencyInfo> &loadFuture) [typesResult, libraryInfo, libraryPath, this] (const QFuture<PluginDumper::DependencyInfo> &loadFuture)
{ {
PluginDumper::DependencyInfo loadResult = loadFuture.result(); PluginDumper::DependencyInfo loadResult = loadFuture.result();

View File

@@ -69,7 +69,7 @@ private:
QString importPath; QString importPath;
QString importUri; QString importUri;
QString importVersion; QString importVersion;
QStringList typeInfoPaths; Utils::FilePaths typeInfoPaths;
}; };
class QmlTypeDescription { class QmlTypeDescription {
@@ -91,13 +91,13 @@ private:
void runQmlDump(const QmlJS::ModelManagerInterface::ProjectInfo &info, const QStringList &arguments, void runQmlDump(const QmlJS::ModelManagerInterface::ProjectInfo &info, const QStringList &arguments,
const Utils::FilePath &importPath); const Utils::FilePath &importPath);
void dump(const Plugin &plugin); void dump(const Plugin &plugin);
QFuture<QmlTypeDescription> loadQmlTypeDescription(const QStringList &path) const; QFuture<QmlTypeDescription> loadQmlTypeDescription(const Utils::FilePaths &path) const;
QString buildQmltypesPath(const QString &name) const; QString buildQmltypesPath(const QString &name) const;
QFuture<PluginDumper::DependencyInfo> loadDependencies(const QStringList &dependencies, QFuture<PluginDumper::DependencyInfo> loadDependencies(const Utils::FilePaths &dependencies,
QSharedPointer<QSet<QString>> visited) const; QSharedPointer<QSet<Utils::FilePath> > visited) const;
void loadQmltypesFile(const QStringList &qmltypesFilePaths, void loadQmltypesFile(const Utils::FilePaths &qmltypesFilePaths,
const Utils::FilePath &libraryPath, const Utils::FilePath &libraryPath,
QmlJS::LibraryInfo libraryInfo); QmlJS::LibraryInfo libraryInfo);
QString resolvePlugin(const QDir &qmldirPath, const QString &qmldirPluginPath, QString resolvePlugin(const QDir &qmldirPath, const QString &qmldirPluginPath,