diff options
author | Sami Shalayel <sami.shalayel@qt.io> | 2024-04-12 10:43:29 +0200 |
---|---|---|
committer | Sami Shalayel <sami.shalayel@qt.io> | 2024-04-18 11:39:16 +0200 |
commit | f1051cb48243ab27a44ec4f30259fa38116c2783 (patch) | |
tree | 2bf3e6322ac95506dde288ffc0be1cfc944aac62 /tools/qmllint/main.cpp | |
parent | 1bef3c4d0db67bd9dcfc7289b6322649af980c22 (diff) |
qmllint: enable environment variables like QML_IMPORT_PATH via -E
Add a -E commandline option for qmllint to enable using environment
variables. For now, this only allows using QML_IMPORT_PATH and
QML2_IMPORT_PATH to pass import paths to qmllint.
Task-number: QTBUG-114969
Change-Id: Ie6baf9c8035703a456ba1e7e575ba424f89d287a
Reviewed-by: Semih Yavuz <semih.yavuz@qt.io>
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
Diffstat (limited to 'tools/qmllint/main.cpp')
-rw-r--r-- | tools/qmllint/main.cpp | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/tools/qmllint/main.cpp b/tools/qmllint/main.cpp index dadbaa3fb5..05dc667232 100644 --- a/tools/qmllint/main.cpp +++ b/tools/qmllint/main.cpp @@ -2,6 +2,7 @@ // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 #include <QtQmlToolingSettings/private/qqmltoolingsettings_p.h> +#include <QtQmlToolingSettings/private/qqmltoolingutils_p.h> #include <QtQmlCompiler/private/qqmljsresourcefilemapper_p.h> #include <QtQmlCompiler/private/qqmljscompiler_p.h> @@ -122,6 +123,11 @@ All warnings can be set to three levels: const QString qmlImportPathsSetting = QLatin1String("AdditionalQmlImportPaths"); settings.addOption(qmlImportPathsSetting); + QCommandLineOption environmentOption( + QStringList() << "E", + QLatin1String("Use the QML_IMPORT_PATH environment variable to look for QML Modules")); + parser.addOption(environmentOption); + QCommandLineOption qmlImportNoDefault( QStringList() << "bare", QLatin1String("Do not include default import directories or the current directory. " @@ -391,6 +397,34 @@ All warnings can be set to three levels: if (parser.isSet(qmlImportPathsOption)) qmlImportPaths << parser.values(qmlImportPathsOption); + if (parser.isSet(environmentOption)) { + if (silent) { + qmlImportPaths << qEnvironmentVariable("QML_IMPORT_PATH") + .split(QDir::separator(), Qt::SkipEmptyParts) + << qEnvironmentVariable("QML2_IMPORT_PATH") + .split(QDir::separator(), Qt::SkipEmptyParts); + } else { + if (const QStringList dirsFromEnv = + QQmlToolingUtils::getAndWarnForInvalidDirsFromEnv(u"QML_IMPORT_PATH"_s); + !dirsFromEnv.isEmpty()) { + qInfo().nospace().noquote() + << "Using import directories passed from environment variable " + "\"QML_IMPORT_PATH\": \"" + << dirsFromEnv.join(u"\", \""_s) << "\"."; + qmlImportPaths << dirsFromEnv; + } + if (const QStringList dirsFromEnv = + QQmlToolingUtils::getAndWarnForInvalidDirsFromEnv( + u"QML2_IMPORT_PATH"_s); + !dirsFromEnv.isEmpty()) { + qInfo().nospace().noquote() << "Using import directories passed from the " + "deprecated environment variable " + "\"QML2_IMPORT_PATH\": \"" + << dirsFromEnv.join(u"\", \""_s) << "\"."; + qmlImportPaths << dirsFromEnv; + } + } + } addAbsolutePaths(qmlImportPaths, settings.value(qmlImportPathsSetting).toStringList()); |