QmlJS: Proliferate FilePath use, part 2

Change-Id: I631df6ba5e782e2db9e03de4e5df843d15c19f37
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
hjk
2021-10-12 18:00:17 +02:00
parent b59c374217
commit 761ce1feb1
6 changed files with 53 additions and 51 deletions

View File

@@ -632,6 +632,10 @@ LibraryInfo Snapshot::libraryInfo(const QString &path) const
return _libraries.value(QDir::cleanPath(path));
}
LibraryInfo Snapshot::libraryInfo(const Utils::FilePath &path) const
{
return _libraries.value(path.cleanPath().toString());
}
void ModuleApiInfo::addToHash(QCryptographicHash &hash) const
{

View File

@@ -256,7 +256,8 @@ public:
Document::Ptr document(const QString &fileName) const;
QList<Document::Ptr> documentsInDirectory(const QString &path) const;
LibraryInfo libraryInfo(const QString &path) const;
LibraryInfo libraryInfo(const QString &path) const; // FIXME: Remove
LibraryInfo libraryInfo(const Utils::FilePath &path) const;
Document::MutablePtr documentFromSource(const QString &code,
const QString &fileName,

View File

@@ -684,19 +684,19 @@ void ModelManagerInterface::updateDocument(const Document::Ptr &doc)
emit documentUpdated(doc);
}
void ModelManagerInterface::updateLibraryInfo(const QString &path, const LibraryInfo &info)
void ModelManagerInterface::updateLibraryInfo(const FilePath &path, const LibraryInfo &info)
{
if (!info.pluginTypeInfoError().isEmpty())
qCDebug(qmljsLog) << "Dumping errors for " << path << ":" << info.pluginTypeInfoError();
{
QMutexLocker locker(&m_mutex);
m_validSnapshot.insertLibraryInfo(path, info);
m_newestSnapshot.insertLibraryInfo(path, info);
m_validSnapshot.insertLibraryInfo(path.toString(), info);
m_newestSnapshot.insertLibraryInfo(path.toString(), info);
}
// only emit if we got new useful information
if (info.isValid())
emit libraryInfoUpdated(path, info);
emit libraryInfoUpdated(path.toString(), info);
}
static QStringList filesInDirectoryForLanguages(const QString &path,
@@ -773,7 +773,7 @@ enum class LibraryStatus {
Unknown
};
static LibraryStatus libraryStatus(const QString &path, const Snapshot &snapshot,
static LibraryStatus libraryStatus(const FilePath &path, const Snapshot &snapshot,
QSet<QString> *newLibraries)
{
if (path.isEmpty())
@@ -782,7 +782,7 @@ static LibraryStatus libraryStatus(const QString &path, const Snapshot &snapshot
const LibraryInfo &existingInfo = snapshot.libraryInfo(path);
if (existingInfo.isValid())
return LibraryStatus::Accepted;
if (newLibraries->contains(path))
if (newLibraries->contains(path.toString()))
return LibraryStatus::Accepted;
// if we looked at the path before, done
return existingInfo.wasScanned()
@@ -790,7 +790,7 @@ static LibraryStatus libraryStatus(const QString &path, const Snapshot &snapshot
: LibraryStatus::Unknown;
}
static bool findNewQmlApplicationInPath(const QString &path,
static bool findNewQmlApplicationInPath(const FilePath &path,
const Snapshot &snapshot,
ModelManagerInterface *modelManager,
QSet<QString> *newLibraries)
@@ -803,8 +803,8 @@ static bool findNewQmlApplicationInPath(const QString &path,
QString qmltypesFile;
QDir dir(path);
QDirIterator it(path, QStringList { "*.qmltypes" }, QDir::Files);
QDir dir(path.toString());
QDirIterator it(path.toString(), QStringList { "*.qmltypes" }, QDir::Files);
if (!it.hasNext())
return false;
@@ -828,7 +828,7 @@ static bool findNewQmlLibraryInPath(const QString &path,
QSet<QString> *newLibraries,
bool ignoreMissing)
{
switch (libraryStatus(path, snapshot, newLibraries)) {
switch (libraryStatus(FilePath::fromString(path), snapshot, newLibraries)) {
case LibraryStatus::Accepted: return true;
case LibraryStatus::Rejected: return false;
default: break;
@@ -839,7 +839,7 @@ static bool findNewQmlLibraryInPath(const QString &path,
if (!qmldirFile.exists()) {
if (!ignoreMissing) {
LibraryInfo libraryInfo(LibraryInfo::NotFound);
modelManager->updateLibraryInfo(path, libraryInfo);
modelManager->updateLibraryInfo(FilePath::fromString(path), libraryInfo);
}
return false;
}
@@ -858,7 +858,7 @@ static bool findNewQmlLibraryInPath(const QString &path,
const QString libraryPath = QFileInfo(qmldirFile).absolutePath();
newLibraries->insert(libraryPath);
modelManager->updateLibraryInfo(libraryPath, LibraryInfo(qmldirParser));
modelManager->updateLibraryInfo(FilePath::fromString(libraryPath), LibraryInfo(qmldirParser));
modelManager->loadPluginTypes(QFileInfo(libraryPath).canonicalFilePath(), libraryPath,
QString(), QString());
@@ -1252,7 +1252,7 @@ void ModelManagerInterface::updateImportPaths()
for (const Document::Ptr &doc : qAsConst(snapshot))
findNewLibraryImports(doc, snapshot, this, &importedFiles, &scannedPaths, &newLibraries);
for (const QString &path : qAsConst(allApplicationDirectories))
findNewQmlApplicationInPath(path, snapshot, this, &newLibraries);
findNewQmlApplicationInPath(FilePath::fromString(path), snapshot, this, &newLibraries);
updateSourceFiles(importedFiles, true);
@@ -1433,7 +1433,7 @@ LibraryInfo ModelManagerInterface::builtins(const Document::Ptr &doc) const
{
const ProjectInfo info = projectInfoForPath(doc->fileName());
if (!info.qtQmlPath.isEmpty())
return m_validSnapshot.libraryInfo(info.qtQmlPath.toString());
return m_validSnapshot.libraryInfo(info.qtQmlPath);
return LibraryInfo();
}

View File

@@ -156,7 +156,7 @@ public:
void updateProjectInfo(const ProjectInfo &pinfo, ProjectExplorer::Project *p);
void updateDocument(const QmlJS::Document::Ptr& doc);
void updateLibraryInfo(const QString &path, const QmlJS::LibraryInfo &info);
void updateLibraryInfo(const Utils::FilePath &path, const QmlJS::LibraryInfo &info);
void emitDocumentChangedOnDisk(QmlJS::Document::Ptr doc);
void updateQrcFile(const QString &path);
ProjectInfo projectInfoForPath(const QString &path) const;

View File

@@ -89,25 +89,23 @@ void PluginDumper::onLoadBuiltinTypes(const QmlJS::ModelManagerInterface::Projec
if (info.qmlDumpPath.isEmpty() || info.qtQmlPath.isEmpty())
return;
// FIXME: This doesn't work for non-local paths.
const QString importsPath = QDir::cleanPath(info.qtQmlPath.toString());
if (m_runningQmldumps.values().contains(importsPath))
if (m_runningQmldumps.values().contains(info.qmlDumpPath))
return;
LibraryInfo builtinInfo;
if (!force) {
const Snapshot snapshot = m_modelManager->snapshot();
builtinInfo = snapshot.libraryInfo(info.qtQmlPath.toString());
builtinInfo = snapshot.libraryInfo(info.qtQmlPath);
if (builtinInfo.isValid())
return;
}
builtinInfo = LibraryInfo(LibraryInfo::Found);
m_modelManager->updateLibraryInfo(info.qtQmlPath.toString(), builtinInfo);
m_modelManager->updateLibraryInfo(info.qtQmlPath, builtinInfo);
// prefer QTDIR/qml/builtins.qmltypes if available
const QString builtinQmltypesPath = info.qtQmlPath.toString() + QLatin1String("/builtins.qmltypes");
if (QFile::exists(builtinQmltypesPath)) {
loadQmltypesFile(QStringList(builtinQmltypesPath), info.qtQmlPath.toString(), builtinInfo);
loadQmltypesFile(QStringList(builtinQmltypesPath), info.qtQmlPath, builtinInfo);
return;
}
@@ -124,7 +122,7 @@ static QString makeAbsolute(const QString &path, const QString &base)
void PluginDumper::onLoadPluginTypes(const QString &libraryPath, const QString &importPath, const QString &importUri, const QString &importVersion)
{
const QString canonicalLibraryPath = QDir::cleanPath(libraryPath);
const FilePath canonicalLibraryPath = FilePath::fromUserInput(libraryPath).cleanPath();
if (m_runningQmldumps.values().contains(canonicalLibraryPath))
return;
const Snapshot snapshot = m_modelManager->snapshot();
@@ -135,7 +133,7 @@ void PluginDumper::onLoadPluginTypes(const QString &libraryPath, const QString &
// avoid inserting the same plugin twice
int index;
for (index = 0; index < m_plugins.size(); ++index) {
if (m_plugins.at(index).qmldirPath == libraryPath)
if (m_plugins.at(index).qmldirPath == canonicalLibraryPath)
break;
}
if (index == m_plugins.size())
@@ -148,10 +146,10 @@ void PluginDumper::onLoadPluginTypes(const QString &libraryPath, const QString &
plugin.importVersion = importVersion;
// add default qmltypes file if it exists
QDirIterator it(canonicalLibraryPath, QStringList { "*.qmltypes" }, QDir::Files);
QDirIterator it(canonicalLibraryPath.toString(), QStringList { "*.qmltypes" }, QDir::Files);
while (it.hasNext()) {
const QString defaultQmltypesPath = makeAbsolute(it.next(), canonicalLibraryPath);
const QString defaultQmltypesPath = makeAbsolute(it.next(), canonicalLibraryPath.toString());
if (!plugin.typeInfoPaths.contains(defaultQmltypesPath))
plugin.typeInfoPaths += defaultQmltypesPath;
@@ -159,14 +157,14 @@ void PluginDumper::onLoadPluginTypes(const QString &libraryPath, const QString &
// add typeinfo files listed in qmldir
foreach (const QString &typeInfo, libraryInfo.typeInfos()) {
QString pathNow = makeAbsolute(typeInfo, canonicalLibraryPath);
QString pathNow = makeAbsolute(typeInfo, canonicalLibraryPath.toString());
if (!plugin.typeInfoPaths.contains(pathNow) && QFile::exists(pathNow))
plugin.typeInfoPaths += pathNow;
}
// watch plugin libraries
foreach (const QmlDirParser::Plugin &plugin, snapshot.libraryInfo(canonicalLibraryPath).plugins()) {
const QString pluginLibrary = resolvePlugin(canonicalLibraryPath, plugin.path, plugin.name);
const QString pluginLibrary = resolvePlugin(canonicalLibraryPath.toString(), plugin.path, plugin.name);
if (!pluginLibrary.isEmpty()) {
if (!pluginWatcher()->watchesFile(pluginLibrary))
pluginWatcher()->addFile(pluginLibrary, Utils::FileSystemWatcher::WatchModifiedDate);
@@ -195,26 +193,25 @@ void PluginDumper::dumpAllPlugins()
}
}
static QString noTypeinfoError(const QString &libraryPath)
static QString noTypeinfoError(const FilePath &libraryPath)
{
return PluginDumper::tr("QML module does not contain information about components contained in plugins.\n\n"
"Module path: %1\n"
"See \"Using QML Modules with Plugins\" in the documentation.").arg(
libraryPath);
libraryPath.toUserOutput());
}
static QString qmldumpErrorMessage(const QString &libraryPath, const QString &error)
static QString qmldumpErrorMessage(const FilePath &libraryPath, const QString &error)
{
return noTypeinfoError(libraryPath) + QLatin1String("\n\n") +
return noTypeinfoError(libraryPath) + "\n\n" +
PluginDumper::tr("Automatic type dump of QML module failed.\nErrors:\n%1").
arg(error) + QLatin1Char('\n');
}
static QString qmldumpFailedMessage(const QString &libraryPath, const QString &error)
static QString qmldumpFailedMessage(const FilePath &libraryPath, const QString &error)
{
QString firstLines =
QStringList(error.split(QLatin1Char('\n')).mid(0, 10)).join(QLatin1Char('\n'));
return noTypeinfoError(libraryPath) + QLatin1String("\n\n") +
QString firstLines = QStringList(error.split('\n').mid(0, 10)).join('\n');
return noTypeinfoError(libraryPath) + "\n\n" +
PluginDumper::tr("Automatic type dump of QML module failed.\n"
"First 10 lines or errors:\n"
"\n"
@@ -224,11 +221,11 @@ static QString qmldumpFailedMessage(const QString &libraryPath, const QString &e
).arg(firstLines);
}
static void printParseWarnings(const QString &libraryPath, const QString &warning)
static void printParseWarnings(const FilePath &libraryPath, const QString &warning)
{
ModelManagerInterface::writeWarning(
PluginDumper::tr("Warnings while parsing QML type information of %1:\n"
"%2").arg(libraryPath, warning));
"%2").arg(libraryPath.toUserOutput(), warning));
}
static QString qmlPluginDumpErrorMessage(QtcProcess *process)
@@ -269,7 +266,7 @@ void PluginDumper::qmlPluginTypeDumpDone(QtcProcess *process)
{
process->deleteLater();
const QString libraryPath = m_runningQmldumps.take(process);
const FilePath libraryPath = m_runningQmldumps.take(process);
if (libraryPath.isEmpty())
return;
const Snapshot snapshot = m_modelManager->snapshot();
@@ -298,7 +295,7 @@ void PluginDumper::qmlPluginTypeDumpDone(QtcProcess *process)
CppQmlTypesInfo infos;
CppQmlTypesLoader::parseQmlTypeDescriptions(output, &infos.objectsList, &infos.moduleApis, &infos.dependencies,
&infos.error, &infos.warning,
QLatin1String("<dump of ") + libraryPath + QLatin1Char('>'));
"<dump of " + libraryPath.toUserOutput() + '>');
future.reportFinished(&infos);
});
m_modelManager->addFuture(future);
@@ -338,13 +335,13 @@ void PluginDumper::qmlPluginTypeDumpError(QtcProcess *process)
{
process->deleteLater();
const QString libraryPath = m_runningQmldumps.take(process);
const FilePath libraryPath = m_runningQmldumps.take(process);
if (libraryPath.isEmpty())
return;
const QString errorMessages = qmlPluginDumpErrorMessage(process);
const Snapshot snapshot = m_modelManager->snapshot();
LibraryInfo libraryInfo = snapshot.libraryInfo(libraryPath);
if (!libraryPath.endsWith(QLatin1String("private"), Qt::CaseInsensitive))
if (!libraryPath.path().endsWith(QLatin1String("private"), Qt::CaseInsensitive))
ModelManagerInterface::writeWarning(qmldumpErrorMessage(libraryPath, errorMessages));
libraryInfo.setPluginTypeInfoStatus(LibraryInfo::DumpError, qmldumpFailedMessage(libraryPath, errorMessages));
libraryInfo.updateFingerprint();
@@ -564,7 +561,7 @@ static void applyQt515MissingImportWorkaround(const QString &path, LibraryInfo &
}
void PluginDumper::prepareLibraryInfo(LibraryInfo &libInfo,
const QString &libraryPath,
const FilePath &libraryPath,
const QStringList &deps,
const QStringList &errors,
const QStringList &warnings,
@@ -588,13 +585,13 @@ void PluginDumper::prepareLibraryInfo(LibraryInfo &libInfo,
if (!warnings.isEmpty())
printParseWarnings(libraryPath, warnings.join(QLatin1String("\n")));
applyQt515MissingImportWorkaround(libraryPath, libInfo);
applyQt515MissingImportWorkaround(libraryPath.toString(), libInfo);
libInfo.updateFingerprint();
}
void PluginDumper::loadQmltypesFile(const QStringList &qmltypesFilePaths,
const QString &libraryPath,
const FilePath &libraryPath,
QmlJS::LibraryInfo libraryInfo)
{
Utils::onFinished(loadQmlTypeDescription(qmltypesFilePaths), this, [=](const QFuture<PluginDumper::QmlTypeDescription> &typesFuture)
@@ -640,7 +637,7 @@ void PluginDumper::runQmlDump(const ModelManagerInterface::ProjectInfo &info,
connect(process, &QtcProcess::finished, this, [this, process] { qmlPluginTypeDumpDone(process); });
connect(process, &QtcProcess::errorOccurred, this, [this, process] { qmlPluginTypeDumpError(process); });
process->start();
m_runningQmldumps.insert(process, importPath.toString());
m_runningQmldumps.insert(process, importPath);
}
void PluginDumper::dump(const Plugin &plugin)
@@ -686,7 +683,7 @@ void PluginDumper::dump(const Plugin &plugin)
args << plugin.importUri;
args << plugin.importVersion;
args << (plugin.importPath.isEmpty() ? QLatin1String(".") : plugin.importPath);
runQmlDump(info, args, FilePath::fromString(plugin.qmldirPath));
runQmlDump(info, args, plugin.qmldirPath);
}
/*!

View File

@@ -65,7 +65,7 @@ private:
private:
class Plugin {
public:
QString qmldirPath;
Utils::FilePath qmldirPath;
QString importPath;
QString importUri;
QString importVersion;
@@ -98,7 +98,7 @@ private:
QSharedPointer<QSet<QString>> visited) const;
void loadQmltypesFile(const QStringList &qmltypesFilePaths,
const QString &libraryPath,
const Utils::FilePath &libraryPath,
QmlJS::LibraryInfo libraryInfo);
QString resolvePlugin(const QDir &qmldirPath, const QString &qmldirPluginPath,
const QString &baseName);
@@ -109,7 +109,7 @@ private:
private:
Utils::FileSystemWatcher *pluginWatcher();
void prepareLibraryInfo(LibraryInfo &libInfo,
const QString &libraryPath,
const Utils::FilePath &libraryPath,
const QStringList &deps,
const QStringList &errors,
const QStringList &warnings,
@@ -118,7 +118,7 @@ private:
ModelManagerInterface *m_modelManager;
Utils::FileSystemWatcher *m_pluginWatcher;
QHash<Utils::QtcProcess *, QString> m_runningQmldumps;
QHash<Utils::QtcProcess *, Utils::FilePath> m_runningQmldumps;
QList<Plugin> m_plugins;
QHash<QString, int> m_libraryToPluginIndex;
QHash<QString, QmlJS::ModelManagerInterface::ProjectInfo> m_qtToInfo;