moc: Add warnings when resolving and opening includes fails
Previously, only cryptic warnings: QFSFileEngine::open: No file name specified occurred. Task-number: QTBUG-55014 Change-Id: Ic99614eb58c605ed6e1b86d3d4b8f527c5b9244c Reviewed-by: Olivier Goffart (Woboq GmbH) <ogoffart@woboq.com>bb10
parent
dd3a08dd53
commit
a5c851598c
|
|
@ -457,11 +457,22 @@ int runMoc(int argc, char **argv)
|
|||
const auto includeFiles = parser.values(includeOption);
|
||||
for (const QString &includeName : includeFiles) {
|
||||
QByteArray rawName = pp.resolveInclude(QFile::encodeName(includeName), moc.filename);
|
||||
QFile f(QFile::decodeName(rawName));
|
||||
if (f.open(QIODevice::ReadOnly)) {
|
||||
moc.symbols += Symbol(0, MOC_INCLUDE_BEGIN, rawName);
|
||||
moc.symbols += pp.preprocessed(rawName, &f);
|
||||
moc.symbols += Symbol(0, MOC_INCLUDE_END, rawName);
|
||||
if (rawName.isEmpty()) {
|
||||
fprintf(stderr, "Warning: Failed to resolve include \"%s\" for moc file %s\n",
|
||||
includeName.toLocal8Bit().constData(),
|
||||
moc.filename.isEmpty() ? "<standard input>" : moc.filename.constData());
|
||||
} else {
|
||||
QFile f(QFile::decodeName(rawName));
|
||||
if (f.open(QIODevice::ReadOnly)) {
|
||||
moc.symbols += Symbol(0, MOC_INCLUDE_BEGIN, rawName);
|
||||
moc.symbols += pp.preprocessed(rawName, &f);
|
||||
moc.symbols += Symbol(0, MOC_INCLUDE_END, rawName);
|
||||
} else {
|
||||
fprintf(stderr, "Warning: Cannot open %s included by moc file %s: %s\n",
|
||||
rawName.constData(),
|
||||
moc.filename.isEmpty() ? "<standard input>" : moc.filename.constData(),
|
||||
f.errorString().toLocal8Bit().constData());
|
||||
}
|
||||
}
|
||||
}
|
||||
moc.symbols += pp.preprocessed(moc.filename, &in);
|
||||
|
|
|
|||
|
|
@ -2027,6 +2027,13 @@ void tst_Moc::warnings_data()
|
|||
<< 1
|
||||
<< QString("IGNORE_ALL_STDOUT")
|
||||
<< QString(":-1: Error: Unexpected character in macro argument list.");
|
||||
|
||||
QTest::newRow("Missing header warning")
|
||||
<< QByteArray("class X : public QObject { Q_OBJECT };")
|
||||
<< (QStringList() << QStringLiteral("--include") << QStringLiteral("doesnotexist.h"))
|
||||
<< 0
|
||||
<< QString("IGNORE_ALL_STDOUT")
|
||||
<< QStringLiteral("Warning: Failed to resolve include \"doesnotexist.h\" for moc file <standard input>");
|
||||
}
|
||||
|
||||
void tst_Moc::warnings()
|
||||
|
|
|
|||
Loading…
Reference in New Issue