summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorUlf Hermann <ulf.hermann@qt.io>2021-02-05 18:43:30 +0100
committerUlf Hermann <ulf.hermann@qt.io>2021-02-10 09:27:06 +0100
commit63bfaae1f527a8f6de34e76dfd1282cd7e22d989 (patch)
treef280c4b17993ffe647ba5cf13c7f8d159acb6277
parent026f8f4df59b641bcafca7bd392f5efefd795898 (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>
-rw-r--r--src/qml/Qt6QmlMacros.cmake9
-rw-r--r--src/qml/doc/src/qmllanguageref/modules/identifiedmodules.qdoc4
-rw-r--r--src/qml/doc/src/qmllanguageref/syntax/imports.qdoc8
-rw-r--r--src/qml/qml/qqmlengine.cpp4
-rw-r--r--src/qml/qml/qqmlimport.cpp60
-rw-r--r--tests/auto/qml/qqmlimport/tst_qqmlimport.cpp10
6 files changed, 54 insertions, 41 deletions
diff --git a/src/qml/Qt6QmlMacros.cmake b/src/qml/Qt6QmlMacros.cmake
index 9e559f8755..60b57b3940 100644
--- a/src/qml/Qt6QmlMacros.cmake
+++ b/src/qml/Qt6QmlMacros.cmake
@@ -1254,7 +1254,8 @@ endfunction()
# Adds a target called TARGET_qmllint that runs on all qml files compiled ahead-of-time.
function(qt6_target_enable_qmllint target)
get_target_property(target_source ${target} SOURCE_DIR)
- get_target_property(includes ${target} QML2_IMPORT_PATH)
+ get_target_property(includes ${target} QML_IMPORT_PATH)
+ get_target_property(deprecated_includes ${target} QML2_IMPORT_PATH)
get_target_property(files ${target} QML_FILES)
if(includes)
@@ -1263,6 +1264,12 @@ function(qt6_target_enable_qmllint target)
endforeach()
endif()
+ if(deprecated_includes)
+ foreach(dir in LISTS deprecated_includes)
+ list(APPEND include_args "-I${dir}")
+ endforeach()
+ endif()
+
add_custom_target(${target}_qmllint
${QT_CMAKE_EXPORT_NAMESPACE}::qmllint ${files} ${include_args}
WORKING_DIRECTORY ${target_source}
diff --git a/src/qml/doc/src/qmllanguageref/modules/identifiedmodules.qdoc b/src/qml/doc/src/qmllanguageref/modules/identifiedmodules.qdoc
index 914a40599c..303ed6b18c 100644
--- a/src/qml/doc/src/qmllanguageref/modules/identifiedmodules.qdoc
+++ b/src/qml/doc/src/qmllanguageref/modules/identifiedmodules.qdoc
@@ -175,13 +175,13 @@ An identified module has several restrictions upon it:
\endlist
For example, if an identified module is installed into
-\c{$QML2_IMPORT_PATH/ExampleModule}, the module identifier directive must be:
+\c{$QML_IMPORT_PATH/ExampleModule}, the module identifier directive must be:
\code
module ExampleModule
\endcode
If the strict module is installed into
-\c{$QML2_IMPORT_PATH/com/example/CustomUi}, the module identifier directive
+\c{$QML_IMPORT_PATH/com/example/CustomUi}, the module identifier directive
must be:
\code
module com.example.CustomUi
diff --git a/src/qml/doc/src/qmllanguageref/syntax/imports.qdoc b/src/qml/doc/src/qmllanguageref/syntax/imports.qdoc
index 4a350877ca..14a99c44f4 100644
--- a/src/qml/doc/src/qmllanguageref/syntax/imports.qdoc
+++ b/src/qml/doc/src/qmllanguageref/syntax/imports.qdoc
@@ -290,19 +290,19 @@ default locations to be searched by the engine. By default, this list contains:
\list
\li The directory of the current file
\li The location specified by QLibraryInfo::QmlImportsPath
-\li Paths specified by the \c QML2_IMPORT_PATH environment variable
+\li Paths specified by the \c QML_IMPORT_PATH environment variable
\li The qrc:/qt-project.org/imports path inside the resources.
\endlist
Additional import paths can be added through QQmlEngine::addImportPath() or the
-\c QML2_IMPORT_PATH environment variable. When running the
+\c QML_IMPORT_PATH environment variable. When running the
\l{Prototyping with qmlscene}{qmlscene} tool, you can also use the \c -I option
to add an import path.
-You can specify multiple import paths in the \c QML2_IMPORT_PATH environment
+You can specify multiple import paths in the \c QML_IMPORT_PATH environment
variable by joining them using the path separator. On Windows the path separator
is a semicolon (;), on other platforms it is a colon (:). This means that you
-cannot specify resource paths or URLs in QML2_IMPORT_PATH, as they contain
+cannot specify resource paths or URLs in QML_IMPORT_PATH, as they contain
colons themselves. However, you can add resource paths and URLs by calling
QQmlEngine::addImportPath() programatically.
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());
diff --git a/tests/auto/qml/qqmlimport/tst_qqmlimport.cpp b/tests/auto/qml/qqmlimport/tst_qqmlimport.cpp
index 92565cc591..bfa836f92c 100644
--- a/tests/auto/qml/qqmlimport/tst_qqmlimport.cpp
+++ b/tests/auto/qml/qqmlimport/tst_qqmlimport.cpp
@@ -64,13 +64,13 @@ void tst_QQmlImport::cleanup()
void tst_QQmlImport::envResourceImportPath()
{
- const bool hadEnv = qEnvironmentVariableIsSet("QML2_IMPORT_PATH");
- const QByteArray oldEnv = hadEnv ? qgetenv("QML2_IMPORT_PATH") : QByteArray();
+ const bool hadEnv = qEnvironmentVariableIsSet("QML_IMPORT_PATH");
+ const QByteArray oldEnv = hadEnv ? qgetenv("QML_IMPORT_PATH") : QByteArray();
auto guard = qScopeGuard([&] {
if (hadEnv)
- qputenv("QML2_IMPORT_PATH", oldEnv);
+ qputenv("QML_IMPORT_PATH", oldEnv);
else
- qunsetenv("QML2_IMPORT_PATH");
+ qunsetenv("QML_IMPORT_PATH");
});
const QStringList envPaths({
@@ -80,7 +80,7 @@ void tst_QQmlImport::envResourceImportPath()
directory()
});
- qputenv("QML2_IMPORT_PATH", envPaths.join(QDir::listSeparator()).toUtf8());
+ qputenv("QML_IMPORT_PATH", envPaths.join(QDir::listSeparator()).toUtf8());
QQmlImportDatabase importDb(nullptr);
const QStringList importPaths = importDb.importPathList();