diff options
author | Ulf Hermann <ulf.hermann@qt.io> | 2021-02-05 18:43:30 +0100 |
---|---|---|
committer | Ulf Hermann <ulf.hermann@qt.io> | 2021-02-10 09:27:06 +0100 |
commit | 63bfaae1f527a8f6de34e76dfd1282cd7e22d989 (patch) | |
tree | f280c4b17993ffe647ba5cf13c7f8d159acb6277 /src/qml/qml | |
parent | 026f8f4df59b641bcafca7bd392f5efefd795898 (diff) |
Support and prefer QML_IMPORT_PATH over QML2_IMPORT_PATH
The 2 is meaningless.
Task-number: QTBUG-85064
Change-Id: I9f140155d274c691b5eab1285d9b7153f9f93a87
Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
Reviewed-by: Andrei Golubev <andrei.golubev@qt.io>
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Diffstat (limited to 'src/qml/qml')
-rw-r--r-- | src/qml/qml/qqmlengine.cpp | 4 | ||||
-rw-r--r-- | src/qml/qml/qqmlimport.cpp | 60 |
2 files changed, 35 insertions, 29 deletions
diff --git a/src/qml/qml/qqmlengine.cpp b/src/qml/qml/qqmlengine.cpp index eb0d2f24f3..aa30c08c19 100644 --- a/src/qml/qml/qqmlengine.cpp +++ b/src/qml/qml/qqmlengine.cpp @@ -1919,7 +1919,7 @@ void QQmlEngine::addImportPath(const QString& path) type version mapping and possibly QML extensions plugins. By default, the list contains the directory of the application executable, - paths specified in the \c QML2_IMPORT_PATH environment variable, + paths specified in the \c QML_IMPORT_PATH environment variable, and the builtin \c QmlImportsPath from QLibraryInfo. \sa addImportPath(), setImportPathList() @@ -1935,7 +1935,7 @@ QStringList QQmlEngine::importPathList() const installed modules in a URL-based directory structure. By default, the list contains the directory of the application executable, - paths specified in the \c QML2_IMPORT_PATH environment variable, + paths specified in the \c QML_IMPORT_PATH environment variable, and the builtin \c QmlImportsPath from QLibraryInfo. \sa importPathList(), addImportPath() diff --git a/src/qml/qml/qqmlimport.cpp b/src/qml/qml/qqmlimport.cpp index 7fa9277ab3..670a6617fc 100644 --- a/src/qml/qml/qqmlimport.cpp +++ b/src/qml/qml/qqmlimport.cpp @@ -1932,6 +1932,29 @@ void QQmlImports::setDesignerSupportRequired(bool b) designerSupportRequired = b; } +static QStringList parseEnvImportPath(const QString &envImportPath) +{ + if (QDir::listSeparator() == u':') { + // Double colons are interpreted as separator + resource path. + QStringList paths = envImportPath.split(u':'); + bool wasEmpty = false; + for (auto it = paths.begin(); it != paths.end();) { + if (it->isEmpty()) { + wasEmpty = true; + it = paths.erase(it); + } else { + if (wasEmpty) { + it->prepend(u':'); + wasEmpty = false; + } + ++it; + } + } + return paths; + } else { + return envImportPath.split(QDir::listSeparator(), Qt::SkipEmptyParts); + } +} /*! \class QQmlImportDatabase @@ -1942,39 +1965,22 @@ QQmlImportDatabase::QQmlImportDatabase(QQmlEngine *e) : engine(e) { filePluginPath << QLatin1String("."); - // Search order is applicationDirPath(), qrc:/qt-project.org/imports, $QML2_IMPORT_PATH, QLibraryInfo::QmlImportsPath + // Search order is applicationDirPath(), qrc:/qt-project.org/imports, $QML_IMPORT_PATH, $QML2_IMPORT_PATH, QLibraryInfo::QmlImportsPath QString installImportsPath = QLibraryInfo::path(QLibraryInfo::QmlImportsPath); addImportPath(installImportsPath); - // env import paths - if (Q_UNLIKELY(!qEnvironmentVariableIsEmpty("QML2_IMPORT_PATH"))) { - const QString envImportPath = qEnvironmentVariable("QML2_IMPORT_PATH"); - const QChar pathSep = QDir::listSeparator(); - QStringList paths; - if (pathSep == u':') { - // Double colons are interpreted as separator + resource path. - paths = envImportPath.split(u':'); - bool wasEmpty = false; - for (auto it = paths.begin(); it != paths.end();) { - if (it->isEmpty()) { - wasEmpty = true; - it = paths.erase(it); - } else { - if (wasEmpty) { - it->prepend(u':'); - wasEmpty = false; - } - ++it; - } - } - } else { - paths = envImportPath.split(pathSep, Qt::SkipEmptyParts); + auto addEnvImportPath = [this](const char *var) { + if (Q_UNLIKELY(!qEnvironmentVariableIsEmpty(var))) { + const QStringList paths = parseEnvImportPath(qEnvironmentVariable(var)); + for (int ii = paths.count() - 1; ii >= 0; --ii) + addImportPath(paths.at(ii)); } + }; - for (int ii = paths.count() - 1; ii >= 0; --ii) - addImportPath(paths.at(ii)); - } + // env import paths + addEnvImportPath("QML_IMPORT_PATH"); + addEnvImportPath("QML2_IMPORT_PATH"); addImportPath(QStringLiteral("qrc:/qt-project.org/imports")); addImportPath(QCoreApplication::applicationDirPath()); |