aboutsummaryrefslogtreecommitdiffstats
path: root/tools/qmllint/main.cpp
diff options
context:
space:
mode:
authorAlexandru Croitor <alexandru.croitor@qt.io>2023-12-12 13:43:37 +0100
committerAlexandru Croitor <alexandru.croitor@qt.io>2023-12-14 12:28:13 +0100
commitda1741d4c856cdc31c94dde2a060344574145743 (patch)
tree0ec031e9e531ae5f1f9f591ee34f70146f6056ce /tools/qmllint/main.cpp
parent9e0dd093b520afe0b8efad910c2ed84d97a388b7 (diff)
qmllint: Add response file support
Adapt CMake code to use a response file instead of a long string of arguments when calling the various qmllint targets. Avoids long command line errors on Windows. Pick-to: 6.5 6.6 6.7 Fixes: QTBUG-119675 Change-Id: I49041ffff2724fb36b8127b2a08127a9b740db7d Reviewed-by: Joerg Bornemann <joerg.bornemann@qt.io> Reviewed-by: Sami Shalayel <sami.shalayel@qt.io>
Diffstat (limited to 'tools/qmllint/main.cpp')
-rw-r--r--tools/qmllint/main.cpp44
1 files changed, 39 insertions, 5 deletions
diff --git a/tools/qmllint/main.cpp b/tools/qmllint/main.cpp
index b244868a17..531f056a28 100644
--- a/tools/qmllint/main.cpp
+++ b/tools/qmllint/main.cpp
@@ -30,6 +30,35 @@ using namespace Qt::StringLiterals;
constexpr int JSON_LOGGING_FORMAT_REVISION = 3;
+bool argumentsFromCommandLineAndFile(QStringList& allArguments, const QStringList &arguments)
+{
+ allArguments.reserve(arguments.size());
+ for (const QString &argument : arguments) {
+ // "@file" doesn't start with a '-' so we can't use QCommandLineParser for it
+ if (argument.startsWith(u'@')) {
+ QString optionsFile = argument;
+ optionsFile.remove(0, 1);
+ if (optionsFile.isEmpty()) {
+ qWarning().nospace() << "The @ option requires an input file";
+ return false;
+ }
+ QFile f(optionsFile);
+ if (!f.open(QIODevice::ReadOnly | QIODevice::Text)) {
+ qWarning().nospace() << "Cannot open options file specified with @";
+ return false;
+ }
+ while (!f.atEnd()) {
+ QString line = QString::fromLocal8Bit(f.readLine().trimmed());
+ if (!line.isEmpty())
+ allArguments << line;
+ }
+ } else {
+ allArguments << argument;
+ }
+ }
+ return true;
+}
+
int main(int argv, char *argc[])
{
QHashSeed::setDeterministicGlobalSeed();
@@ -189,11 +218,16 @@ All warnings can be set to three levels:
parser.addPositionalArgument(QLatin1String("files"),
QLatin1String("list of qml or js files to verify"));
- if (!parser.parse(app.arguments())) {
- if (parser.unknownOptionNames().isEmpty()) {
- qWarning().noquote() << parser.errorText();
- return 1;
- }
+
+ QStringList arguments;
+ if (!argumentsFromCommandLineAndFile(arguments, app.arguments())) {
+ // argumentsFromCommandLine already printed any necessary warnings.
+ return 1;
+ }
+
+ if (!parser.parse(arguments)) {
+ qWarning().noquote() << parser.errorText();
+ return 1;
}
// Since we can't use QCommandLineParser::process(), we need to handle version and help manually