mirror of
https://github.com/google/flatbuffers.git
synced 2026-06-26 00:28:39 +00:00
Added --keep-prefix to not strip schema include path in C++ includes.
Change-Id: I3c6356fc6664072796f273096df64829108b4a34 Tested: on Linux.
This commit is contained in:
@@ -123,5 +123,7 @@ Additional options:
|
|||||||
- `--include-prefix PATH` : Prefix this path to any generated include
|
- `--include-prefix PATH` : Prefix this path to any generated include
|
||||||
statements.
|
statements.
|
||||||
|
|
||||||
|
- `--keep-prefix` : Keep original prefix of schema include statement.
|
||||||
|
|
||||||
NOTE: short-form options for generators are deprecated, use the long form
|
NOTE: short-form options for generators are deprecated, use the long form
|
||||||
whenever possible.
|
whenever possible.
|
||||||
|
|||||||
@@ -358,6 +358,7 @@ struct IDLOptions {
|
|||||||
bool union_value_namespacing;
|
bool union_value_namespacing;
|
||||||
bool allow_non_utf8;
|
bool allow_non_utf8;
|
||||||
std::string include_prefix;
|
std::string include_prefix;
|
||||||
|
bool keep_include_path;
|
||||||
bool binary_schema_comments;
|
bool binary_schema_comments;
|
||||||
bool skip_flatbuffers_import;
|
bool skip_flatbuffers_import;
|
||||||
std::string go_namespace;
|
std::string go_namespace;
|
||||||
@@ -403,6 +404,7 @@ struct IDLOptions {
|
|||||||
cpp_object_api_pointer_type("std::unique_ptr"),
|
cpp_object_api_pointer_type("std::unique_ptr"),
|
||||||
union_value_namespacing(true),
|
union_value_namespacing(true),
|
||||||
allow_non_utf8(false),
|
allow_non_utf8(false),
|
||||||
|
keep_include_path(false),
|
||||||
binary_schema_comments(false),
|
binary_schema_comments(false),
|
||||||
skip_flatbuffers_import(false),
|
skip_flatbuffers_import(false),
|
||||||
reexport_ts_modules(true),
|
reexport_ts_modules(true),
|
||||||
|
|||||||
@@ -103,6 +103,7 @@ std::string FlatCompiler::GetUsageString(const char* program_name) const {
|
|||||||
" PATH \n"
|
" PATH \n"
|
||||||
" --include-prefix Prefix this path to any generated include statements.\n"
|
" --include-prefix Prefix this path to any generated include statements.\n"
|
||||||
" PATH\n"
|
" PATH\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, or JSON files (conforming to preceding schema)\n"
|
||||||
@@ -155,6 +156,8 @@ int FlatCompiler::Compile(int argc, const char** argv) {
|
|||||||
opts.include_prefix = argv[argi];
|
opts.include_prefix = argv[argi];
|
||||||
if (opts.include_prefix.back() != '/' &&
|
if (opts.include_prefix.back() != '/' &&
|
||||||
opts.include_prefix.back() != '\\') opts.include_prefix += "/";
|
opts.include_prefix.back() != '\\') opts.include_prefix += "/";
|
||||||
|
} else if(arg == "--keep-prefix") {
|
||||||
|
opts.keep_include_path = true;
|
||||||
} else if(arg == "--strict-json") {
|
} else if(arg == "--strict-json") {
|
||||||
opts.strict_json = true;
|
opts.strict_json = true;
|
||||||
} else if(arg == "--allow-non-utf8") {
|
} else if(arg == "--allow-non-utf8") {
|
||||||
|
|||||||
@@ -72,8 +72,9 @@ class CppGenerator : public BaseGenerator {
|
|||||||
}
|
}
|
||||||
for (auto it = parser_.included_files_.begin();
|
for (auto it = parser_.included_files_.begin();
|
||||||
it != parser_.included_files_.end(); ++it) {
|
it != parser_.included_files_.end(); ++it) {
|
||||||
const auto basename =
|
auto basename = flatbuffers::StripExtension(it->first);
|
||||||
flatbuffers::StripPath(flatbuffers::StripExtension(it->first));
|
if (!parser_.opts.keep_include_path)
|
||||||
|
basename = flatbuffers::StripPath(basename);
|
||||||
if (basename != file_name_) {
|
if (basename != file_name_) {
|
||||||
code_ += "#include \"" + parser_.opts.include_prefix + basename +
|
code_ += "#include \"" + parser_.opts.include_prefix + basename +
|
||||||
"_generated.h\"";
|
"_generated.h\"";
|
||||||
|
|||||||
Reference in New Issue
Block a user