Commit a905258f authored by Kevin Funk's avatar Kevin Funk Committed by Kevin Funk
Browse files

repc: Remove output file in case of invalid input


This makes repc's behavior more consistent with other generators. If
command-line arguments are correct, input file exists, but the input is
malformed => remove output file. Before this patch, repc generated an
empty file.

On a consecutive make run, this empty file would be considered a valid
output / up-to-date and repc would not be re-run. This patch fixes this,
and makes sure repc is re-run each time, until the input is valid.

Change-Id: I17b20b6f0fb5a7d5b632077ae885540a90049afb
Reviewed-by: default avatarContinuous Integration (KDAB) <build@kdab.com>
Reviewed-by: default avatarBrett Stottlemyer <bstottle@ford.com>
Showing with 10 additions and 3 deletions
......@@ -241,7 +241,9 @@ int main(int argc, char **argv)
fprintf(stderr, PROGRAM_NAME ": No QObject classes found.\n");
return 0;
}
input.close();
if (mode & OutRep) {
CppCodeGenerator generator(&output);
generator.generate(moc.classList, parser.isSet(alwaysClassOption));
......@@ -250,7 +252,6 @@ int main(int argc, char **argv)
RepCodeGenerator generator(&output);
generator.generate(classList2AST(moc.classList), RepCodeGenerator::REPLICA, outputFile);
}
output.close();
} else {
Q_ASSERT(!(mode & OutRep));
RepParser repparser(input);
......@@ -258,9 +259,15 @@ int main(int argc, char **argv)
repparser.setDebug();
if (!repparser.parse()) {
fprintf(stderr, PROGRAM_NAME ": %s:%d: error: %s\n", qPrintable(inputFile), repparser.lineNumber(), qPrintable(repparser.errorString()));
// if everything is okay and only the input was malformed => remove the output file
// let's not create an empty file -- make sure the build system tries to run repc again
// this is the same behavior other code generators exhibit (e.g. flex)
output.remove();
return 1;
}
input.close();
RepCodeGenerator generator(&output);
if ((mode & OutMerged) == OutMerged)
generator.generate(repparser.ast(), RepCodeGenerator::MERGED, outputFile);
......@@ -272,8 +279,8 @@ int main(int argc, char **argv)
fprintf(stderr, PROGRAM_NAME ": Unknown mode.\n");
return 1;
}
output.close();
}
output.close();
return 0;
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment