diff options
| author | Alexandru Croitor <alexandru.croitor@qt.io> | 2023-12-12 13:43:37 +0100 |
|---|---|---|
| committer | Qt Cherry-pick Bot <cherrypick_bot@qt-project.org> | 2023-12-15 12:46:14 +0000 |
| commit | ead19dbc07768271b196f303e9d43647a066b3da (patch) | |
| tree | 78bbf5f3d8ee950201945bc22a963ec648b05c43 /tools | |
| parent | dbff24f501074372a56971ad0959583cb8134ed4 (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
Fixes: QTBUG-119675
Change-Id: I49041ffff2724fb36b8127b2a08127a9b740db7d
Reviewed-by: Joerg Bornemann <joerg.bornemann@qt.io>
Reviewed-by: Sami Shalayel <sami.shalayel@qt.io>
(cherry picked from commit da1741d4c856cdc31c94dde2a060344574145743)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
(cherry picked from commit 0505ebdc8a1f7db226881f8d61b4ca3cf6e331e4)
Diffstat (limited to 'tools')
| -rw-r--r-- | tools/qmllint/main.cpp | 44 |
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 |
