Make --bfbs-filenames default to location of first schema file. (#6705)

* Make --bfbs-filenames default to location of first schema file.

Make RelativeToProjectRoot always work, applying "../" where needed. This is
needed for backwards compatibility. The first input file may be deeper in some
directory than the other files. Now, there will always be a declaration
file.

* documentation

* clang format

Co-authored-by: Casper Neo <cneo@google.com>
This commit is contained in:
Casper
2021-06-22 10:19:46 -04:00
committed by GitHub
parent c8db1ca5d4
commit 71d43f3be9
4 changed files with 34 additions and 19 deletions

View File

@@ -149,8 +149,11 @@ std::string FlatCompiler::GetUsageString(const char *program_name) const {
" --oneof-union Translate .proto oneofs to flatbuffer unions.\n"
" --grpc Generate GRPC interfaces for the specified languages.\n"
" --schema Serialize schemas instead of JSON (use with -b).\n"
" --bfbs-filenames PATH Adds declaration filenames, relative to PATH and prefixed with"
" `//`, to the binary schema.\n"
" --bfbs-filenames PATH Sets the root path where reflection filenames in \n"
" reflection.fbs are relative to. The 'root' is denoted with \n"
" `//`. E.g. if PATH=/a/b/c \n then /a/d/e.fbs will be serialized\n"
" as //../d/e.fbs. (PATH defaults to the directory of the first\n"
" provided schema file.)\n"
" --bfbs-comments Add doc comments to the binary schema files.\n"
" --bfbs-builtins Add builtin attributes to the binary schema files.\n"
" --bfbs-gen-embed Generate code to embed the bfbs schema to the source.\n"
@@ -444,6 +447,9 @@ int FlatCompiler::Compile(int argc, const char **argv) {
static_cast<size_t>(file_it - filenames.begin()) >= binary_files_from;
auto ext = flatbuffers::GetExtension(filename);
const bool is_schema = ext == "fbs" || ext == "proto";
if (is_schema && opts.project_root.empty()) {
opts.project_root = StripFileName(filename);
}
const bool is_binary_schema = ext == reflection::SchemaExtension();
if (is_binary) {
parser->builder_.Clear();