From 165a6e3d1e540e0e928fcad775a98cc8b1a3d0b4 Mon Sep 17 00:00:00 2001 From: Derek Bailey Date: Thu, 25 Jun 2020 15:35:23 -0700 Subject: [PATCH] Re-added Evolution Schema Code Generation Command (#5999) * Fixed refractoring issue in reflection/generate_code.sh. Also, mv deletes the original file, so I don't need to clean it up manually in that case. * Fixed Dart Tests by removing code-gen for included files. * Added code gen for evolution tests back in. * General generate code and clang format * Added evolution schema generation to .bat file * Added code gen for evolution tests back in. * General generate code and clang format * Added evolution schema generation to .bat file * reran generate_code.sh * Removed wildcard from generate_code.bat that doesn't work --- src/idl_gen_cpp.cpp | 4 +--- src/idl_parser.cpp | 7 +++---- tests/evolution_test/evolution_v1_generated.h | 11 +++++++++++ tests/evolution_test/evolution_v2_generated.h | 11 +++++++++++ tests/generate_code.bat | 3 +++ tests/generate_code.sh | 3 +++ 6 files changed, 32 insertions(+), 7 deletions(-) diff --git a/src/idl_gen_cpp.cpp b/src/idl_gen_cpp.cpp index a8dba2a6f..a62d93e4f 100644 --- a/src/idl_gen_cpp.cpp +++ b/src/idl_gen_cpp.cpp @@ -1681,9 +1681,7 @@ class CppGenerator : public BaseGenerator { code_.SetValue("NATIVE_NAME", NativeName(Name(struct_def), &struct_def, opts_)); // In >= C++11, default member initializers are generated. - if (opts_.g_cpp_std >= cpp::CPP_STD_11) { - return; - } + if (opts_.g_cpp_std >= cpp::CPP_STD_11) { return; } std::string initializer_list; for (auto it = struct_def.fields.vec.begin(); it != struct_def.fields.vec.end(); ++it) { diff --git a/src/idl_parser.cpp b/src/idl_parser.cpp index ae874cfab..897bf8e78 100644 --- a/src/idl_parser.cpp +++ b/src/idl_parser.cpp @@ -880,9 +880,7 @@ CheckedError Parser::ParseField(StructDef &struct_def) { } // if this field is a union that is deprecated, // the automatically added type field should be deprecated as well - if (field->deprecated) { - typefield->deprecated = true; - } + if (field->deprecated) { typefield->deprecated = true; } } EXPECT(';'); @@ -2181,7 +2179,8 @@ CheckedError Parser::ParseEnum(const bool is_union, EnumDef **dest) { if (prev_ev->GetAsUInt64() == ev->GetAsUInt64()) return Error("all enum values must be unique: " + prev_ev->name + " and " + ev->name + " are both " + - NumToString(ev->GetAsInt64())); } + NumToString(ev->GetAsInt64())); + } if (dest) *dest = enum_def; types_.Add(current_namespace_->GetFullyQualifiedName(enum_def->name), diff --git a/tests/evolution_test/evolution_v1_generated.h b/tests/evolution_test/evolution_v1_generated.h index 584dfe478..82fcb33ef 100644 --- a/tests/evolution_test/evolution_v1_generated.h +++ b/tests/evolution_test/evolution_v1_generated.h @@ -125,6 +125,17 @@ FLATBUFFERS_MANUALLY_ALIGNED_STRUCT(8) Struct FLATBUFFERS_FINAL_CLASS { }; FLATBUFFERS_STRUCT_END(Struct, 16); +inline bool operator==(const Struct &lhs, const Struct &rhs) { + return + (lhs.a() == rhs.a()) && + (lhs.b() == rhs.b()); +} + +inline bool operator!=(const Struct &lhs, const Struct &rhs) { + return !(lhs == rhs); +} + + struct TableA FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { typedef TableABuilder Builder; enum FlatBuffersVTableOffset FLATBUFFERS_VTABLE_UNDERLYING_TYPE { diff --git a/tests/evolution_test/evolution_v2_generated.h b/tests/evolution_test/evolution_v2_generated.h index 07adec5b4..eeb49a2ea 100644 --- a/tests/evolution_test/evolution_v2_generated.h +++ b/tests/evolution_test/evolution_v2_generated.h @@ -141,6 +141,17 @@ FLATBUFFERS_MANUALLY_ALIGNED_STRUCT(8) Struct FLATBUFFERS_FINAL_CLASS { }; FLATBUFFERS_STRUCT_END(Struct, 16); +inline bool operator==(const Struct &lhs, const Struct &rhs) { + return + (lhs.a() == rhs.a()) && + (lhs.b() == rhs.b()); +} + +inline bool operator!=(const Struct &lhs, const Struct &rhs) { + return !(lhs == rhs); +} + + struct TableA FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { typedef TableABuilder Builder; enum FlatBuffersVTableOffset FLATBUFFERS_VTABLE_UNDERLYING_TYPE { diff --git a/tests/generate_code.bat b/tests/generate_code.bat index 5d4db19f6..6954c6b71 100644 --- a/tests/generate_code.bat +++ b/tests/generate_code.bat @@ -53,6 +53,9 @@ set TEST_NOINCL_FLAGS=%TEST_BASE_FLAGS% --no-includes --no-fb-import ..\%buildtype%\flatc.exe --python %TEST_BASE_FLAGS% arrays_test.fbs || goto FAIL ..\%buildtype%\flatc.exe --cpp %TEST_BASE_FLAGS% --cpp-ptr-type flatbuffers::unique_ptr native_type_test.fbs || goto FAIL +@rem Generate the schema evolution tests +..\%buildtype%\flatc.exe --cpp --scoped-enums %TEST_CPP_FLAGS% -o evolution_test ./evolution_test/evolution_v1.fbs ./evolution_test/evolution_v2.fbs || goto FAIL + if NOT "%MONSTER_EXTRA%"=="skip" ( @echo Generate MosterExtra ..\%buildtype%\flatc.exe --cpp --java --csharp %TEST_NOINCL_FLAGS% %TEST_CPP_FLAGS% %TEST_CS_FLAGS% monster_extra.fbs monsterdata_extra.json || goto FAIL diff --git a/tests/generate_code.sh b/tests/generate_code.sh index ea6edfa0d..0b3e13434 100755 --- a/tests/generate_code.sh +++ b/tests/generate_code.sh @@ -51,6 +51,9 @@ $TEST_NOINCL_FLAGS $TEST_CPP_FLAGS $TEST_CS_FLAGS -o namespace_test namespace_te ../flatc --python $TEST_BASE_FLAGS arrays_test.fbs ../flatc --dart monster_extra.fbs +# Generate the schema evolution tests +../flatc --cpp --scoped-enums $TEST_CPP_FLAGS -o evolution_test ./evolution_test/evolution_v*.fbs + working_dir=`pwd` cd FlatBuffers.Test.Swift/Tests/FlatBuffers.Test.SwiftTests $working_dir/../flatc --swift --grpc $TEST_NOINCL_FLAGS $TEST_CPP_FLAGS $TEST_CS_FLAGS -I ../../../include_test ../../../monster_test.fbs