From fdc2608c31d2de91616356644915f1165606a9e8 Mon Sep 17 00:00:00 2001 From: Fabian Kosmale Date: Tue, 18 Jan 2022 16:16:20 +0100 Subject: [PATCH] tools: Unconditionally depend on QCommandLineParser qmllint's utility is rather limited when we can pass it neither the qmldir nor qmltypes files. Instead of trying to somehow handle the case with ifdefs, move the feature check into the build system and completely disable the tool if we lack the parser. The same holds for qmltc, which is already completely unusable without the parser (and just prints an error message if build without the feature enabled). Change-Id: I31828bb7d551caeaffd1974d1dff14a25446ce95 Reviewed-by: Andrei Golubev Reviewed-by: Ulf Hermann --- tools/CMakeLists.txt | 6 ++++-- tools/qmllint/main.cpp | 18 +----------------- tools/qmltc/main.cpp | 14 +------------- 3 files changed, 6 insertions(+), 32 deletions(-) diff --git a/tools/CMakeLists.txt b/tools/CMakeLists.txt index e4fbb589f4..1e8ec2d46f 100644 --- a/tools/CMakeLists.txt +++ b/tools/CMakeLists.txt @@ -9,10 +9,12 @@ qt_exclude_tool_directories_from_default_target( if(QT_FEATURE_qml_devtools) add_subdirectory(qmldom) - add_subdirectory(qmllint) + if(QT_FEATURE_commandlineparser) + add_subdirectory(qmllint) + add_subdirectory(qmltc) + endif() add_subdirectory(qmlimportscanner) add_subdirectory(qmlformat) - add_subdirectory(qmltc) if (TARGET Qt::LanguageServerPrivate) add_subdirectory(qmlls) endif() diff --git a/tools/qmllint/main.cpp b/tools/qmllint/main.cpp index c68e1b21b1..eb744b3c19 100644 --- a/tools/qmllint/main.cpp +++ b/tools/qmllint/main.cpp @@ -61,7 +61,6 @@ int main(int argv, char *argc[]) QCoreApplication app(argv, argc); QCoreApplication::setApplicationName("qmllint"); QCoreApplication::setApplicationVersion(QT_VERSION_STR); -#if QT_CONFIG(commandlineparser) QCommandLineParser parser; QQmlToolingSettings settings(QLatin1String("qmllint")); parser.setApplicationDescription(QLatin1String(R"(QML syntax verifier and analyzer @@ -224,23 +223,11 @@ All warnings can be set to three levels: parser.isSet(resourceOption) ? parser.values(resourceOption) : QStringList {}; QStringList resourceFiles = defaultResourceFiles; -#else - bool silent = false; - bool useAbsolutePaths = false; - bool useJson = false; - bool warnUnqualified = true; - bool warnWithStatement = true; - bool warnInheritanceCycle = true; - QStringList qmlImportPaths {}; - QStringList qmltypesFiles {}; - QStringList resourceFiles {}; -#endif bool success = true; QQmlLinter linter(qmlImportPaths, useAbsolutePath); QJsonArray jsonFiles; -#if QT_CONFIG(commandlineparser) for (const QString &filename : positionalArguments) { if (!parser.isSet(ignoreSettings)) { settings.search(filename); @@ -277,10 +264,7 @@ All warnings can be set to three levels: addAbsolutePaths(qmlImportPaths, settings.value(qmlImportPathsSetting).toStringList()); } -#else - const auto arguments = app.arguments(); - for (const QString &filename : arguments) { -#endif + success &= linter.lintFile(filename, nullptr, silent, useJson ? &jsonFiles : nullptr, qmlImportPaths, qmldirFiles, resourceFiles, options); } diff --git a/tools/qmltc/main.cpp b/tools/qmltc/main.cpp index 8ae320c79e..6854d93687 100644 --- a/tools/qmltc/main.cpp +++ b/tools/qmltc/main.cpp @@ -39,9 +39,7 @@ #include #include #include -#if QT_CONFIG(commandlineparser) -# include -#endif +#include #include // EXIT_SUCCESS, EXIT_FAILURE @@ -60,7 +58,6 @@ int main(int argc, char **argv) QCoreApplication::setApplicationName(u"qmltc"_qs); QCoreApplication::setApplicationVersion(QStringLiteral(QT_VERSION_STR)); -#if QT_CONFIG(commandlineparser) // command-line parsing: QCommandLineParser parser; parser.addHelpOption(); @@ -190,13 +187,4 @@ int main(int argc, char **argv) return EXIT_FAILURE; return EXIT_SUCCESS; -#else - // we need the parser at least for --resource-path option (and maybe for - // something else in the future), so just fail here if QCommandLine parser - // is unavailable - fprintf(stderr, - "qmltc requires commandlineparser feature enabled. Rebuild Qt with that feature " - "present if you want to use this tool\n"); - return EXIT_FAILURE; -#endif }