Implement --file-names-only (#8788)

* flatc builds and seems to work, some of the extra targets are having linker errors

* fix build system

* pipeline failures

* un-rename files

* refactor to use unique_ptr

* typo

* rm make_unique, add comments

* fix cmake

---------

Co-authored-by: Wouter van Oortmerssen <aardappel@gmail.com>
This commit is contained in:
Justin Davis
2025-12-02 23:37:06 -05:00
committed by GitHub
parent 0b60686e3d
commit a1e125af11
34 changed files with 207 additions and 210 deletions

View File

@@ -181,9 +181,25 @@ int main(int argc, const char* argv[]) {
flatbuffers::NewTsCodeGenerator());
// Create the FlatC options by parsing the command line arguments.
const flatbuffers::FlatCOptions& options =
flatbuffers::FlatCOptions options =
flatc.ParseFromCommandLineArguments(argc, argv);
// this exists here to ensure file_saver outlives the compilation process
std::unique_ptr<flatbuffers::FileSaver> file_saver;
if (options.file_names_only) {
file_saver.reset(new flatbuffers::FileNameSaver{});
} else {
file_saver.reset(new flatbuffers::RealFileSaver{});
}
options.opts.file_saver = file_saver.get();
FLATBUFFERS_ASSERT(options.opts.file_saver);
// Compile with the extracted FlatC options.
return flatc.Compile(options);
int success = flatc.Compile(options);
// print file names if file-names-only option is set
options.opts.file_saver->Finish();
return success;
}