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>
This commit is contained in:
Ulf Hermann 2021-02-05 18:43:30 +01:00
parent 026f8f4df5
commit 63bfaae1f5
6 changed files with 54 additions and 41 deletions

View File

@ -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}

View File

@ -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

View File

@ -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.

View File

@ -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()

View File

@ -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());

View File

@ -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();