Avoid blocking read from stdin when collecting json files
Change the behavior of moc when collecting json files. If argument files are specified, suppose moc received empty input and skip input from standard input. Pick-to: 6.1 Fixes: QTBUG-93504 Change-Id: I45ec790ed458f1fae543d069555bc8abc6560816 Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
This commit is contained in:
parent
97abef2140
commit
c4b5e84e9e
@ -51,7 +51,7 @@ static bool readFromDevice(QIODevice *device, QJsonArray *allMetaObjects)
|
||||
return true;
|
||||
}
|
||||
|
||||
int collectJson(const QStringList &jsonFiles, const QString &outputFile)
|
||||
int collectJson(const QStringList &jsonFiles, const QString &outputFile, bool skipStdIn)
|
||||
{
|
||||
QHashSeed::setDeterministicGlobalSeed();
|
||||
|
||||
@ -70,7 +70,7 @@ int collectJson(const QStringList &jsonFiles, const QString &outputFile)
|
||||
}
|
||||
|
||||
QJsonArray allMetaObjects;
|
||||
if (jsonFiles.isEmpty()) {
|
||||
if (jsonFiles.isEmpty() && !skipStdIn) {
|
||||
QFile f;
|
||||
if (!f.open(stdin, QIODevice::ReadOnly)) {
|
||||
fprintf(stderr, "Error opening stdin for reading\n");
|
||||
|
@ -35,7 +35,7 @@
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
||||
int collectJson(const QStringList &jsonFiles, const QString &outputFile);
|
||||
int collectJson(const QStringList &jsonFiles, const QString &outputFile, bool skipStdIn);
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
||||
|
@ -145,9 +145,10 @@ QByteArray composePreprocessorOutput(const Symbols &symbols) {
|
||||
return output;
|
||||
}
|
||||
|
||||
static QStringList argumentsFromCommandLineAndFile(const QStringList &arguments)
|
||||
static QStringList argumentsFromCommandLineAndFile(const QStringList &arguments, bool &hasOptionFiles)
|
||||
{
|
||||
QStringList allArguments;
|
||||
hasOptionFiles = false;
|
||||
allArguments.reserve(arguments.size());
|
||||
for (const QString &argument : arguments) {
|
||||
// "@file" doesn't start with a '-' so we can't use QCommandLineParser for it
|
||||
@ -163,6 +164,7 @@ static QStringList argumentsFromCommandLineAndFile(const QStringList &arguments)
|
||||
error("Cannot open options file specified with @");
|
||||
return QStringList();
|
||||
}
|
||||
hasOptionFiles = true;
|
||||
while (!f.atEnd()) {
|
||||
QString line = QString::fromLocal8Bit(f.readLine().trimmed());
|
||||
if (!line.isEmpty())
|
||||
@ -378,7 +380,8 @@ int runMoc(int argc, char **argv)
|
||||
parser.addPositionalArgument(QStringLiteral("[MOC generated json file]"),
|
||||
QStringLiteral("MOC generated json output"));
|
||||
|
||||
const QStringList arguments = argumentsFromCommandLineAndFile(app.arguments());
|
||||
bool hasOptionFiles = false;
|
||||
const QStringList arguments = argumentsFromCommandLineAndFile(app.arguments(), hasOptionFiles);
|
||||
if (arguments.isEmpty())
|
||||
return 1;
|
||||
|
||||
@ -387,7 +390,7 @@ int runMoc(int argc, char **argv)
|
||||
const QStringList files = parser.positionalArguments();
|
||||
output = parser.value(outputOption);
|
||||
if (parser.isSet(collectOption))
|
||||
return collectJson(files, output);
|
||||
return collectJson(files, output, hasOptionFiles);
|
||||
|
||||
if (files.count() > 1) {
|
||||
error(qPrintable(QLatin1String("Too many input files specified: '") + files.join(QLatin1String("' '")) + QLatin1Char('\'')));
|
||||
|
Loading…
Reference in New Issue
Block a user