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 <andrei.golubev@qt.io>
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
This commit is contained in:
Fabian Kosmale 2022-01-18 16:16:20 +01:00
parent f9834fa3c7
commit fdc2608c31
3 changed files with 6 additions and 32 deletions

View File

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

View File

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

View File

@ -39,9 +39,7 @@
#include <QtCore/qhashfunctions.h>
#include <QtCore/qfileinfo.h>
#include <QtCore/qlibraryinfo.h>
#if QT_CONFIG(commandlineparser)
# include <QtCore/qcommandlineparser.h>
#endif
#include <QtCore/qcommandlineparser.h>
#include <cstdlib> // 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
}