diff options
author | Maximilian Goldstein <max.goldstein@qt.io> | 2022-04-06 14:40:48 +0200 |
---|---|---|
committer | Maximilian Goldstein <max.goldstein@qt.io> | 2022-04-11 14:12:09 +0200 |
commit | 5c04d174282a9a36ce12b26e1807d3d5051a7f33 (patch) | |
tree | 7411e0ecc311083a6eb9279840dab59632977a0b /tools/qmllint/main.cpp | |
parent | 324b625f9f35142c85ea09a00fac2a2eb73ac3f2 (diff) |
CMake: Add _qmllint_json target
Adds an additional _qmllint_json target for use in CI settings and a
all_qmllint_json target to run all of them.
Since the output of ninja sub-commands can not be directly processed by
piping it into a script, the output of the qmllint command is instead
written to ${target}_qmllint.json.
[ChangeLog][qmllint][Important Behavior Changes] The --json option now has
a mandatory file argument and writes its output there. You may also pass
"-" to write it to stdout.
Fixes: QTBUG-95157
Change-Id: I3806c4113235d3aa06d3b3310e1cc7b0171b3eca
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Diffstat (limited to 'tools/qmllint/main.cpp')
-rw-r--r-- | tools/qmllint/main.cpp | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/tools/qmllint/main.cpp b/tools/qmllint/main.cpp index 8fd4d9d2a1..45252245f5 100644 --- a/tools/qmllint/main.cpp +++ b/tools/qmllint/main.cpp @@ -89,7 +89,8 @@ All warnings can be set to three levels: parser.addOption(silentOption); QCommandLineOption jsonOption(QStringList() << "json", - QLatin1String("Output linting errors as JSON")); + QLatin1String("Write output as JSON to file"), + QLatin1String("file"), QString()); parser.addOption(jsonOption); QCommandLineOption writeDefaultsOption( @@ -395,8 +396,17 @@ All warnings can be set to three levels: result[u"revision"_qs] = JSON_LOGGING_FORMAT_REVISION; result[u"files"_qs] = jsonFiles; - QTextStream(stdout) << QString::fromUtf8( - QJsonDocument(result).toJson(QJsonDocument::Compact)); + QString fileName = parser.value(jsonOption); + + const QByteArray json = QJsonDocument(result).toJson(QJsonDocument::Compact); + + if (fileName == u"-") { + QTextStream(stdout) << QString::fromUtf8(json); + } else { + QFile file(fileName); + file.open(QFile::WriteOnly); + file.write(json); + } } return success ? 0 : -1; |