moc: Prefix messages from --collect-json with file names
Unless we're reading from stdin or writing to stdout, in which case there are no file names. Change-Id: I583fe2a77f54c5d62d965384a2c316f37a9b2fd2 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
parent
a47dc99079
commit
06b7a9b19e
@ -9,7 +9,7 @@
|
||||
#include <qstringlist.h>
|
||||
#include <cstdlib>
|
||||
|
||||
static bool readFromDevice(QIODevice *device, QJsonArray *allMetaObjects)
|
||||
static bool readFromFile(QFile *device, QJsonArray *allMetaObjects)
|
||||
{
|
||||
const QByteArray contents = device->readAll();
|
||||
if (contents.isEmpty())
|
||||
@ -18,7 +18,8 @@ static bool readFromDevice(QIODevice *device, QJsonArray *allMetaObjects)
|
||||
QJsonParseError error {};
|
||||
QJsonDocument metaObjects = QJsonDocument::fromJson(contents, &error);
|
||||
if (error.error != QJsonParseError::NoError) {
|
||||
fprintf(stderr, "%s at %d\n", error.errorString().toUtf8().constData(), error.offset);
|
||||
fprintf(stderr, "%s:%d: %s\n", qPrintable(device->fileName()), error.offset,
|
||||
qPrintable(error.errorString()));
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -33,13 +34,15 @@ int collectJson(const QStringList &jsonFiles, const QString &outputFile, bool sk
|
||||
QFile output;
|
||||
if (outputFile.isEmpty()) {
|
||||
if (!output.open(stdout, QIODevice::WriteOnly)) {
|
||||
fprintf(stderr, "Error opening stdout for writing\n");
|
||||
fprintf(stderr, "Error opening stdout for writing: %s\n",
|
||||
qPrintable(output.errorString()));
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
} else {
|
||||
output.setFileName(outputFile);
|
||||
if (!output.open(QIODevice::WriteOnly)) {
|
||||
fprintf(stderr, "Error opening %s for writing\n", qPrintable(outputFile));
|
||||
fprintf(stderr, "%s: Cannot open file for writing: %s\n", qPrintable(outputFile),
|
||||
qPrintable(output.errorString()));
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
}
|
||||
@ -48,14 +51,12 @@ int collectJson(const QStringList &jsonFiles, const QString &outputFile, bool sk
|
||||
if (jsonFiles.isEmpty() && !skipStdIn) {
|
||||
QFile f;
|
||||
if (!f.open(stdin, QIODevice::ReadOnly)) {
|
||||
fprintf(stderr, "Error opening stdin for reading\n");
|
||||
fprintf(stderr, "Error opening stdin for reading: %s\n", qPrintable(f.errorString()));
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if (!readFromDevice(&f, &allMetaObjects)) {
|
||||
fprintf(stderr, "Error parsing data from stdin\n");
|
||||
if (!readFromFile(&f, &allMetaObjects))
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
}
|
||||
|
||||
QStringList jsonFilesSorted = jsonFiles;
|
||||
@ -63,14 +64,13 @@ int collectJson(const QStringList &jsonFiles, const QString &outputFile, bool sk
|
||||
for (const QString &jsonFile : std::as_const(jsonFilesSorted)) {
|
||||
QFile f(jsonFile);
|
||||
if (!f.open(QIODevice::ReadOnly)) {
|
||||
fprintf(stderr, "Error opening %s for reading\n", qPrintable(jsonFile));
|
||||
fprintf(stderr, "%s: Cannot open file for reading: %s\n", qPrintable(jsonFile),
|
||||
qPrintable(f.errorString()));
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if (!readFromDevice(&f, &allMetaObjects)) {
|
||||
fprintf(stderr, "Error parsing %s\n", qPrintable(jsonFile));
|
||||
if (!readFromFile(&f, &allMetaObjects))
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
}
|
||||
|
||||
QJsonDocument doc(allMetaObjects);
|
||||
|
Loading…
x
Reference in New Issue
Block a user