From 9e62375b71cf32e9deebb8815c14bb0a2346747e Mon Sep 17 00:00:00 2001 From: Kai Koehne <kai.koehne@digia.com> Date: Tue, 2 Sep 2014 14:42:51 +0200 Subject: [PATCH] QmlJS: Use canonical paths for matching of import directories We rely on string comparison for detection of QML import paths. Therefore make sure that all paths are canonical. Change-Id: I416bc31915644a888c416d726049668b0e71f29a Task-number: QTCREATORBUG-12902 Reviewed-by: Fawzi Mohamed <fawzi.mohamed@digia.com> --- src/libs/qmljs/qmljsdocument.cpp | 1 + src/libs/qmljs/qmljslink.cpp | 16 +++++++++++----- src/libs/qmljs/qmljsmodelmanagerinterface.cpp | 6 ++++-- src/plugins/qmljstools/qmljsmodelmanager.cpp | 8 ++++---- 4 files changed, 20 insertions(+), 11 deletions(-) diff --git a/src/libs/qmljs/qmljsdocument.cpp b/src/libs/qmljs/qmljsdocument.cpp index cf7fd70bd1c..cb1b9c52c71 100644 --- a/src/libs/qmljs/qmljsdocument.cpp +++ b/src/libs/qmljs/qmljsdocument.cpp @@ -534,6 +534,7 @@ void Snapshot::insert(const Document::Ptr &document, bool allowInvalid) void Snapshot::insertLibraryInfo(const QString &path, const LibraryInfo &info) { + QTC_CHECK(!path.isEmpty()); QTC_CHECK(info.fingerprint() == info.calculateFingerprint()); _libraries.insert(QDir::cleanPath(path), info); if (!info.wasFound()) return; diff --git a/src/libs/qmljs/qmljslink.cpp b/src/libs/qmljs/qmljslink.cpp index 50746e0a766..ede1022f205 100644 --- a/src/libs/qmljs/qmljslink.cpp +++ b/src/libs/qmljs/qmljslink.cpp @@ -438,15 +438,21 @@ Import LinkPrivate::importNonFile(Document::Ptr doc, const ImportInfo &importInf } bool LinkPrivate::importLibrary(Document::Ptr doc, - const QString &libraryPath, + const QString &libraryPath_, Import *import, const QString &importPath) { const ImportInfo &importInfo = import->info; - - const LibraryInfo libraryInfo = snapshot.libraryInfo(libraryPath); - if (!libraryInfo.isValid()) - return false; + QString libraryPath = libraryPath_; + + LibraryInfo libraryInfo = snapshot.libraryInfo(libraryPath); + if (!libraryInfo.isValid()) { + // try canonical path + libraryPath = QFileInfo(libraryPath).canonicalFilePath(); + libraryInfo = snapshot.libraryInfo(libraryPath); + if (!libraryInfo.isValid()) + return false; + } import->libraryPath = libraryPath; diff --git a/src/libs/qmljs/qmljsmodelmanagerinterface.cpp b/src/libs/qmljs/qmljsmodelmanagerinterface.cpp index 281e7461c59..a9f7adf64e9 100644 --- a/src/libs/qmljs/qmljsmodelmanagerinterface.cpp +++ b/src/libs/qmljs/qmljsmodelmanagerinterface.cpp @@ -114,9 +114,11 @@ ModelManagerInterface::ModelManagerInterface(QObject *parent) qRegisterMetaType<QmlJS::Document::Ptr>("QmlJS::Document::Ptr"); qRegisterMetaType<QmlJS::LibraryInfo>("QmlJS::LibraryInfo"); - m_defaultProjectInfo.qtImportsPath = QLibraryInfo::location(QLibraryInfo::ImportsPath); + m_defaultProjectInfo.qtImportsPath = QFileInfo( + QLibraryInfo::location(QLibraryInfo::ImportsPath)).canonicalFilePath(); #if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)) - m_defaultProjectInfo.qtQmlPath = QLibraryInfo::location(QLibraryInfo::Qml2ImportsPath); + m_defaultProjectInfo.qtQmlPath = QFileInfo( + QLibraryInfo::location(QLibraryInfo::Qml2ImportsPath)).canonicalFilePath(); #endif m_defaultImportPaths << environmentImportPaths(); diff --git a/src/plugins/qmljstools/qmljsmodelmanager.cpp b/src/plugins/qmljstools/qmljsmodelmanager.cpp index 3c5a53806df..802765c5403 100644 --- a/src/plugins/qmljstools/qmljsmodelmanager.cpp +++ b/src/plugins/qmljstools/qmljsmodelmanager.cpp @@ -112,14 +112,14 @@ ModelManagerInterface::ProjectInfo QmlJSTools::defaultProjectInfoForProject( projectInfo.tryQmlDump = project && ( qtVersion->type() == QLatin1String(QtSupport::Constants::DESKTOPQT) || qtVersion->type() == QLatin1String(QtSupport::Constants::SIMULATORQT)); - projectInfo.qtQmlPath = qtVersion->qmakeProperty("QT_INSTALL_QML"); - projectInfo.qtImportsPath = qtVersion->qmakeProperty("QT_INSTALL_IMPORTS"); + projectInfo.qtQmlPath = QFileInfo(qtVersion->qmakeProperty("QT_INSTALL_QML")).canonicalFilePath(); + projectInfo.qtImportsPath = QFileInfo(qtVersion->qmakeProperty("QT_INSTALL_IMPORTS")).canonicalFilePath(); projectInfo.qtVersionString = qtVersion->qtVersionString(); } else { #if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)) - projectInfo.qtQmlPath = QLibraryInfo::location(QLibraryInfo::Qml2ImportsPath); + projectInfo.qtQmlPath = QFileInfo(QLibraryInfo::location(QLibraryInfo::Qml2ImportsPath)).canonicalFilePath(); #endif - projectInfo.qtImportsPath = QLibraryInfo::location(QLibraryInfo::ImportsPath); + projectInfo.qtImportsPath = QFileInfo(QLibraryInfo::location(QLibraryInfo::ImportsPath)).canonicalFilePath(); projectInfo.qtVersionString = QLatin1String(qVersion()); } -- GitLab