Make flatc not silently skip schema files not ending in .fbs

Change-Id: I58463b321703b2ef0dc3f3062633909b86eca1a9
Tested: on Linux.
This commit is contained in:
Wouter van Oortmerssen
2017-08-10 16:28:31 -07:00
parent 8a58aafda1
commit a6a3f59253

View File

@@ -108,8 +108,8 @@ std::string FlatCompiler::GetUsageString(const char* program_name) const {
" --keep-prefix Keep original prefix of schema include statement.\n" " --keep-prefix Keep original prefix of schema include statement.\n"
" --no-fb-import Don't include flatbuffers import statement for TypeScript.\n" " --no-fb-import Don't include flatbuffers import statement for TypeScript.\n"
" --no-ts-reexport Don't re-export imported dependencies for TypeScript.\n" " --no-ts-reexport Don't re-export imported dependencies for TypeScript.\n"
"FILEs may be schemas, or JSON files (conforming to preceding schema)\n" "FILEs may be schemas (must end in .fbs), or JSON files (conforming to preceding\n"
"FILEs after the -- must be binary flatbuffer format files.\n" "schema). FILEs after the -- must be binary flatbuffer format files.\n"
"Output files are named using the base file name of the input,\n" "Output files are named using the base file name of the input,\n"
"and written to the current directory or the path given by -o.\n" "and written to the current directory or the path given by -o.\n"
"example: " << program_name << " -c -b schema1.fbs schema2.fbs data.json\n"; "example: " << program_name << " -c -b schema1.fbs schema2.fbs data.json\n";
@@ -321,6 +321,12 @@ int FlatCompiler::Compile(int argc, const char** argv) {
parser.reset(new flatbuffers::Parser(opts)); parser.reset(new flatbuffers::Parser(opts));
} }
ParseFile(*parser.get(), filename, contents, include_directories); ParseFile(*parser.get(), filename, contents, include_directories);
if (!is_schema && !parser->builder_.GetSize()) {
// If a file doesn't end in .fbs, it must be json/binary. Ensure we
// didn't just parse a schema with a different extension.
Error("input file is neither json nor a .fbs (schema) file: " +
filename, true);
}
if (is_schema && !conform_to_schema.empty()) { if (is_schema && !conform_to_schema.empty()) {
auto err = parser->ConformTo(conform_parser); auto err = parser->ConformTo(conform_parser);
if (!err.empty()) Error("schemas don\'t conform: " + err); if (!err.empty()) Error("schemas don\'t conform: " + err);