moc: Do not accept empty input files on --collect-json
... and also don't generate them on --output-json. That was an invitation for build time race conditions. Change-Id: I206ee47f08aa657f9b1cbec4e9e9b3ea97605cae Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
parent
06b7a9b19e
commit
44118fcfef
@ -12,8 +12,10 @@
|
|||||||
static bool readFromFile(QFile *device, QJsonArray *allMetaObjects)
|
static bool readFromFile(QFile *device, QJsonArray *allMetaObjects)
|
||||||
{
|
{
|
||||||
const QByteArray contents = device->readAll();
|
const QByteArray contents = device->readAll();
|
||||||
if (contents.isEmpty())
|
if (contents.isEmpty()) {
|
||||||
return true;
|
fprintf(stderr, "%s:0: metatypes input file is empty\n", qPrintable(device->fileName()));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
QJsonParseError error {};
|
QJsonParseError error {};
|
||||||
QJsonDocument metaObjects = QJsonDocument::fromJson(contents, &error);
|
QJsonDocument metaObjects = QJsonDocument::fromJson(contents, &error);
|
||||||
|
@ -580,11 +580,17 @@ int runMoc(int argc, char **argv)
|
|||||||
|
|
||||||
if (pp.preprocessOnly) {
|
if (pp.preprocessOnly) {
|
||||||
fprintf(out.get(), "%s\n", composePreprocessorOutput(moc.symbols).constData());
|
fprintf(out.get(), "%s\n", composePreprocessorOutput(moc.symbols).constData());
|
||||||
|
} else if (moc.classList.isEmpty()) {
|
||||||
|
moc.note("No relevant classes found. No output generated.");
|
||||||
|
if (jsonOutput) {
|
||||||
|
const QJsonDocument jsonDoc(QJsonObject {
|
||||||
|
{ "outputRevision"_L1, mocOutputRevision },
|
||||||
|
{ "inputFile"_L1, QLatin1StringView(moc.strippedFileName()) }
|
||||||
|
});
|
||||||
|
fputs(jsonDoc.toJson().constData(), jsonOutput.get());
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
if (moc.classList.isEmpty())
|
moc.generate(out.get(), jsonOutput.get());
|
||||||
moc.note("No relevant classes found. No output generated.");
|
|
||||||
else
|
|
||||||
moc.generate(out.get(), jsonOutput.get());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
out.reset();
|
out.reset();
|
||||||
|
@ -1076,6 +1076,18 @@ void Moc::parse()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QByteArrayView Moc::strippedFileName() const
|
||||||
|
{
|
||||||
|
QByteArrayView fn = QByteArrayView(filename);
|
||||||
|
|
||||||
|
auto isSlash = [](char ch) { return ch == '/' || ch == '\\'; };
|
||||||
|
auto rit = std::find_if(fn.crbegin(), fn.crend(), isSlash);
|
||||||
|
if (rit != fn.crend())
|
||||||
|
fn = fn.last(rit - fn.crbegin());
|
||||||
|
|
||||||
|
return fn;
|
||||||
|
}
|
||||||
|
|
||||||
static bool any_type_contains(const QList<PropertyDef> &properties, const QByteArray &pattern)
|
static bool any_type_contains(const QList<PropertyDef> &properties, const QByteArray &pattern)
|
||||||
{
|
{
|
||||||
for (const auto &p : properties) {
|
for (const auto &p : properties) {
|
||||||
@ -1143,12 +1155,7 @@ static QByteArrayList requiredQtContainers(const QList<ClassDef> &classes)
|
|||||||
|
|
||||||
void Moc::generate(FILE *out, FILE *jsonOutput)
|
void Moc::generate(FILE *out, FILE *jsonOutput)
|
||||||
{
|
{
|
||||||
QByteArrayView fn = QByteArrayView(filename);
|
QByteArrayView fn = strippedFileName();
|
||||||
|
|
||||||
auto isSlash = [](char ch) { return ch == '/' || ch == '\\'; };
|
|
||||||
auto rit = std::find_if(fn.crbegin(), fn.crend(), isSlash);
|
|
||||||
if (rit != fn.crend())
|
|
||||||
fn = fn.last(rit - fn.crbegin());
|
|
||||||
|
|
||||||
fprintf(out, "/****************************************************************************\n"
|
fprintf(out, "/****************************************************************************\n"
|
||||||
"** Meta object code from reading C++ file '%s'\n**\n" , fn.constData());
|
"** Meta object code from reading C++ file '%s'\n**\n" , fn.constData());
|
||||||
|
@ -242,6 +242,7 @@ public:
|
|||||||
QList<QString> parsedPluginMetadataFiles;
|
QList<QString> parsedPluginMetadataFiles;
|
||||||
|
|
||||||
void parse();
|
void parse();
|
||||||
|
QByteArrayView strippedFileName() const;
|
||||||
void generate(FILE *out, FILE *jsonOutput);
|
void generate(FILE *out, FILE *jsonOutput);
|
||||||
|
|
||||||
bool parseClassHead(ClassDef *def);
|
bool parseClassHead(ClassDef *def);
|
||||||
|
@ -3381,5 +3381,9 @@
|
|||||||
],
|
],
|
||||||
"inputFile": "trigraphs.h",
|
"inputFile": "trigraphs.h",
|
||||||
"outputRevision": 69
|
"outputRevision": 69
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"inputFile": "using-namespaces.h",
|
||||||
|
"outputRevision": 69
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user