skip generating reflection.fbs in generate_scripts (#7077)
authorDerek Bailey <derekbailey@google.com>
Thu, 3 Feb 2022 06:42:26 +0000 (22:42 -0800)
committerGitHub <noreply@github.com>
Thu, 3 Feb 2022 06:42:26 +0000 (22:42 -0800)
CMakeLists.txt
scripts/generate_code.py

index 2b4482c..21e9015 100644 (file)
@@ -552,7 +552,7 @@ if(Python3_Interpreter_FOUND)
   add_custom_command(
     TARGET flatc
     POST_BUILD
-    COMMAND ${Python3_EXECUTABLE} scripts/generate_code.py ${GENERATION_OPTS}
+    COMMAND ${Python3_EXECUTABLE} scripts/generate_code.py ${GENERATION_OPTS} --skip-gen-reflection
     WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
     COMMENT "Running scripts/generate_code.py..."
     VERBATIM)
index 5b3c225..7a20edd 100755 (executable)
@@ -34,6 +34,11 @@ parser.add_argument(
     action="store_true",
     help="skip generating tests involving monster_extra.fbs",
 )
+parser.add_argument(
+    "--skip-gen-reflection",
+    action="store_true",
+    help="skip generating the reflection.fbs files",
+)
 args = parser.parse_args()
 
 # Get the path where this script is located so we can invoke the script from
@@ -103,7 +108,12 @@ CPP_17_OPTS = NO_INCL_OPTS + [
     "--gen-object-api",
 ]
 RUST_OPTS = BASE_OPTS + ["--rust", "--gen-all", "--gen-name-strings"]
-RUST_SERIALIZE_OPTS = BASE_OPTS + ["--rust", "--gen-all", "--gen-name-strings", "--rust-serialize"]
+RUST_SERIALIZE_OPTS = BASE_OPTS + [
+    "--rust",
+    "--gen-all",
+    "--gen-name-strings",
+    "--rust-serialize",
+]
 TS_OPTS = ["--ts", "--gen-name-strings"]
 LOBSTER_OPTS = ["--lobster"]
 SWIFT_OPTS = ["--swift", "--gen-json-emit", "--bfbs-filenames", str(tests_path)]
@@ -138,7 +148,7 @@ flatc(
 flatc(
     ["--lua", "--bfbs-filenames", str(tests_path)],
     schema="monster_test.fbs",
-    include="include_test"    
+    include="include_test",
 )
 
 flatc(
@@ -412,17 +422,22 @@ flatc(
 )
 
 # Reflection
-temp_dir = ".tmp"
-flatc(
-    ["-c", "--cpp-std", "c++0x", "--no-prefix"],
-    prefix=temp_dir,
-    schema="reflection.fbs",
-    cwd=reflection_path,
-)
-new_reflection_file = Path(reflection_path, temp_dir, "reflection_generated.h")
-original_reflection_file = Path(
-    root_path, "include/flatbuffers/reflection_generated.h"
-)
-if not filecmp.cmp(str(new_reflection_file), str(original_reflection_file)):
-    shutil.move(str(new_reflection_file), str(original_reflection_file))
-shutil.rmtree(str(Path(reflection_path, temp_dir)))
+# Skip generating the reflection if told too, as we run this script after
+# building flatc which uses the reflection_generated.h itself.
+if not args.skip_gen_reflection:
+    temp_dir = ".tmp"
+    flatc(
+        ["-c", "--cpp-std", "c++0x", "--no-prefix"],
+        prefix=temp_dir,
+        schema="reflection.fbs",
+        cwd=reflection_path,
+    )
+    new_reflection_file = Path(
+        reflection_path, temp_dir, "reflection_generated.h"
+    )
+    original_reflection_file = Path(
+        root_path, "include/flatbuffers/reflection_generated.h"
+    )
+    if not filecmp.cmp(str(new_reflection_file), str(original_reflection_file)):
+        shutil.move(str(new_reflection_file), str(original_reflection_file))
+    shutil.rmtree(str(Path(reflection_path, temp_dir)))