James Kuszmaul | 8e62b02 | 2022-03-22 09:33:25 -0700 | [diff] [blame] | 1 | #!/usr/bin/env python3 |
| 2 | # |
| 3 | # Copyright 2021 Google Inc. All rights reserved. |
| 4 | # |
| 5 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | # you may not use this file except in compliance with the License. |
| 7 | # You may obtain a copy of the License at |
| 8 | # |
| 9 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | # |
| 11 | # Unless required by applicable law or agreed to in writing, software |
| 12 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | # See the License for the specific language governing permissions and |
| 15 | # limitations under the License. |
| 16 | |
| 17 | import argparse |
| 18 | import filecmp |
| 19 | import glob |
| 20 | import platform |
| 21 | import shutil |
| 22 | import subprocess |
Austin Schuh | 2dd86a9 | 2022-09-14 21:19:23 -0700 | [diff] [blame] | 23 | import generate_grpc_examples |
James Kuszmaul | 8e62b02 | 2022-03-22 09:33:25 -0700 | [diff] [blame] | 24 | from pathlib import Path |
| 25 | |
| 26 | parser = argparse.ArgumentParser() |
| 27 | parser.add_argument( |
| 28 | "--flatc", |
| 29 | help="path of the Flat C compiler relative to the root directory", |
| 30 | ) |
| 31 | parser.add_argument("--cpp-0x", action="store_true", help="use --cpp-std c++ox") |
| 32 | parser.add_argument( |
| 33 | "--skip-monster-extra", |
| 34 | action="store_true", |
| 35 | help="skip generating tests involving monster_extra.fbs", |
| 36 | ) |
| 37 | parser.add_argument( |
| 38 | "--skip-gen-reflection", |
| 39 | action="store_true", |
| 40 | help="skip generating the reflection.fbs files", |
| 41 | ) |
| 42 | args = parser.parse_args() |
| 43 | |
| 44 | # Get the path where this script is located so we can invoke the script from |
| 45 | # any directory and have the paths work correctly. |
| 46 | script_path = Path(__file__).parent.resolve() |
| 47 | |
| 48 | # Get the root path as an absolute path, so all derived paths are absolute. |
| 49 | root_path = script_path.parent.absolute() |
| 50 | |
| 51 | # Get the location of the flatc executable, reading from the first command line |
| 52 | # argument or defaulting to default names. |
| 53 | flatc_exe = Path( |
| 54 | ("flatc" if not platform.system() == "Windows" else "flatc.exe") |
| 55 | if not args.flatc |
| 56 | else args.flatc |
| 57 | ) |
| 58 | |
| 59 | # Find and assert flatc compiler is present. |
| 60 | if root_path in flatc_exe.parents: |
| 61 | flatc_exe = flatc_exe.relative_to(root_path) |
| 62 | flatc_path = Path(root_path, flatc_exe) |
| 63 | assert flatc_path.exists(), "Cannot find the flatc compiler " + str(flatc_path) |
| 64 | |
| 65 | # Specify the other paths that will be referenced |
| 66 | tests_path = Path(root_path, "tests") |
Austin Schuh | 2dd86a9 | 2022-09-14 21:19:23 -0700 | [diff] [blame] | 67 | swift_code_gen = Path(root_path, "tests/swift/tests/CodeGenerationTests") |
James Kuszmaul | 8e62b02 | 2022-03-22 09:33:25 -0700 | [diff] [blame] | 68 | samples_path = Path(root_path, "samples") |
| 69 | reflection_path = Path(root_path, "reflection") |
| 70 | |
| 71 | # Execute the flatc compiler with the specified parameters |
Austin Schuh | 2dd86a9 | 2022-09-14 21:19:23 -0700 | [diff] [blame] | 72 | def flatc(options, schema, prefix=None, include=None, data=None, cwd=tests_path): |
James Kuszmaul | 8e62b02 | 2022-03-22 09:33:25 -0700 | [diff] [blame] | 73 | cmd = [str(flatc_path)] + options |
| 74 | if prefix: |
| 75 | cmd += ["-o"] + [prefix] |
| 76 | if include: |
| 77 | cmd += ["-I"] + [include] |
| 78 | cmd += [schema] if isinstance(schema, str) else schema |
| 79 | if data: |
| 80 | cmd += [data] if isinstance(data, str) else data |
| 81 | result = subprocess.run(cmd, cwd=str(cwd), check=True) |
| 82 | |
| 83 | |
| 84 | # Generate the code for flatbuffers reflection schema |
| 85 | def flatc_reflection(options, location, target): |
| 86 | full_options = ["--no-prefix"] + options |
| 87 | temp_dir = ".tmp" |
| 88 | flatc( |
| 89 | full_options, |
| 90 | prefix=temp_dir, |
| 91 | schema="reflection.fbs", |
| 92 | cwd=reflection_path, |
| 93 | ) |
| 94 | new_reflection_path = Path(reflection_path, temp_dir, target) |
| 95 | original_reflection_path = Path(root_path, location, target) |
| 96 | if not filecmp.cmp(str(new_reflection_path), str(original_reflection_path)): |
Austin Schuh | 2dd86a9 | 2022-09-14 21:19:23 -0700 | [diff] [blame] | 97 | shutil.rmtree(str(original_reflection_path), ignore_errors=True) |
James Kuszmaul | 8e62b02 | 2022-03-22 09:33:25 -0700 | [diff] [blame] | 98 | shutil.move(str(new_reflection_path), str(original_reflection_path)) |
| 99 | shutil.rmtree(str(Path(reflection_path, temp_dir))) |
| 100 | |
Austin Schuh | 2dd86a9 | 2022-09-14 21:19:23 -0700 | [diff] [blame] | 101 | def flatc_annotate(schema, file, include=None, cwd=tests_path): |
| 102 | cmd = [str(flatc_path)] |
| 103 | if include: |
| 104 | cmd += ["-I"] + [include] |
| 105 | cmd += ["--annotate", schema, file] |
| 106 | result = subprocess.run(cmd, cwd=str(cwd), check=True) |
James Kuszmaul | 8e62b02 | 2022-03-22 09:33:25 -0700 | [diff] [blame] | 107 | |
| 108 | # Glob a pattern relative to file path |
| 109 | def glob(path, pattern): |
| 110 | return [str(p) for p in path.glob(pattern)] |
| 111 | |
| 112 | |
| 113 | # flatc options that are shared |
| 114 | BASE_OPTS = ["--reflect-names", "--gen-mutable", "--gen-object-api"] |
| 115 | NO_INCL_OPTS = BASE_OPTS + ["--no-includes"] |
| 116 | |
| 117 | # Language specific options |
| 118 | CS_OPTS = ["--csharp", "--cs-gen-json-serializer"] |
| 119 | CPP_OPTS = [ |
| 120 | "--cpp", |
| 121 | "--gen-compare", |
| 122 | "--cpp-ptr-type", |
| 123 | "flatbuffers::unique_ptr", |
| 124 | ] + (["--cpp-std", "c++0x"] if args.cpp_0x else []) |
| 125 | |
| 126 | CPP_17_OPTS = NO_INCL_OPTS + [ |
| 127 | "--cpp", |
| 128 | "--cpp-std", |
| 129 | "c++17", |
| 130 | "--cpp-static-reflection", |
| 131 | "--gen-object-api", |
| 132 | ] |
Austin Schuh | 2dd86a9 | 2022-09-14 21:19:23 -0700 | [diff] [blame] | 133 | RUST_OPTS = BASE_OPTS + [ |
| 134 | "--rust", |
| 135 | "--gen-all", |
| 136 | "--gen-name-strings", |
| 137 | "--rust-module-root-file", |
| 138 | ] |
James Kuszmaul | 8e62b02 | 2022-03-22 09:33:25 -0700 | [diff] [blame] | 139 | RUST_SERIALIZE_OPTS = BASE_OPTS + [ |
| 140 | "--rust", |
| 141 | "--gen-all", |
| 142 | "--gen-name-strings", |
| 143 | "--rust-serialize", |
| 144 | "--rust-module-root-file", |
| 145 | ] |
| 146 | TS_OPTS = ["--ts", "--gen-name-strings"] |
| 147 | LOBSTER_OPTS = ["--lobster"] |
| 148 | SWIFT_OPTS = ["--swift", "--gen-json-emit", "--bfbs-filenames", str(tests_path)] |
Austin Schuh | 2dd86a9 | 2022-09-14 21:19:23 -0700 | [diff] [blame] | 149 | SWIFT_OPTS_CODE_GEN = [ |
James Kuszmaul | 3b15b0c | 2022-11-08 14:03:16 -0800 | [diff] [blame] | 150 | "--swift", |
Austin Schuh | 2dd86a9 | 2022-09-14 21:19:23 -0700 | [diff] [blame] | 151 | "--gen-json-emit", |
| 152 | "--bfbs-filenames", |
| 153 | swift_code_gen |
| 154 | ] |
James Kuszmaul | 8e62b02 | 2022-03-22 09:33:25 -0700 | [diff] [blame] | 155 | JAVA_OPTS = ["--java"] |
| 156 | KOTLIN_OPTS = ["--kotlin"] |
| 157 | PHP_OPTS = ["--php"] |
| 158 | DART_OPTS = ["--dart"] |
| 159 | PYTHON_OPTS = ["--python"] |
| 160 | BINARY_OPTS = ["-b", "--schema", "--bfbs-comments", "--bfbs-builtins"] |
| 161 | |
| 162 | # Basic Usage |
| 163 | |
| 164 | flatc( |
| 165 | NO_INCL_OPTS |
| 166 | + CPP_OPTS |
| 167 | + CS_OPTS |
James Kuszmaul | 8e62b02 | 2022-03-22 09:33:25 -0700 | [diff] [blame] | 168 | + [ |
| 169 | "--binary", |
| 170 | "--java", |
| 171 | "--kotlin", |
| 172 | "--dart", |
| 173 | "--go", |
| 174 | "--lobster", |
| 175 | "--php", |
| 176 | ], |
| 177 | schema="monster_test.fbs", |
| 178 | include="include_test", |
| 179 | data="monsterdata_test.json", |
| 180 | ) |
| 181 | |
| 182 | flatc( |
Austin Schuh | 2dd86a9 | 2022-09-14 21:19:23 -0700 | [diff] [blame] | 183 | NO_INCL_OPTS |
| 184 | + TS_OPTS, |
| 185 | schema="monster_test.fbs", |
| 186 | prefix="ts", |
| 187 | include="include_test", |
| 188 | data="monsterdata_test.json", |
| 189 | ) |
| 190 | |
| 191 | flatc( |
James Kuszmaul | 8e62b02 | 2022-03-22 09:33:25 -0700 | [diff] [blame] | 192 | ["--lua", "--bfbs-filenames", str(tests_path)], |
| 193 | schema="monster_test.fbs", |
| 194 | include="include_test", |
| 195 | ) |
| 196 | |
| 197 | flatc( |
| 198 | NO_INCL_OPTS + CPP_OPTS + ["--grpc"], |
| 199 | schema="monster_test.fbs", |
| 200 | include="include_test", |
| 201 | data="monsterdata_test.json", |
| 202 | ) |
| 203 | |
| 204 | flatc( |
| 205 | RUST_OPTS, |
| 206 | schema="monster_test.fbs", |
| 207 | include="include_test", |
| 208 | prefix="monster_test", |
| 209 | data="monsterdata_test.json", |
| 210 | ) |
| 211 | |
| 212 | flatc( |
| 213 | RUST_SERIALIZE_OPTS, |
| 214 | schema="monster_test.fbs", |
| 215 | include="include_test", |
| 216 | prefix="monster_test_serialize", |
| 217 | data="monsterdata_test.json", |
| 218 | ) |
| 219 | |
| 220 | flatc( |
| 221 | options=BASE_OPTS + ["--python"], |
| 222 | schema="monster_test.fbs", |
| 223 | include="include_test", |
| 224 | data="monsterdata_test.json", |
| 225 | ) |
| 226 | |
| 227 | flatc( |
| 228 | options=BASE_OPTS + ["--python", "--gen-onefile"], |
| 229 | schema="monster_test.fbs", |
| 230 | include="include_test", |
| 231 | data="monsterdata_test.json", |
| 232 | ) |
| 233 | |
| 234 | # For Rust we currently generate two independent schemas, with namespace_test2 |
| 235 | # duplicating the types in namespace_test1 |
| 236 | flatc( |
Austin Schuh | 2dd86a9 | 2022-09-14 21:19:23 -0700 | [diff] [blame] | 237 | RUST_OPTS + CS_OPTS, |
James Kuszmaul | 8e62b02 | 2022-03-22 09:33:25 -0700 | [diff] [blame] | 238 | prefix="namespace_test", |
| 239 | schema=[ |
| 240 | "namespace_test/namespace_test1.fbs", |
| 241 | "namespace_test/namespace_test2.fbs", |
| 242 | ], |
| 243 | ) |
| 244 | |
| 245 | flatc( |
Austin Schuh | 2dd86a9 | 2022-09-14 21:19:23 -0700 | [diff] [blame] | 246 | BASE_OPTS + CPP_OPTS + CS_OPTS + JAVA_OPTS + KOTLIN_OPTS + PHP_OPTS, |
James Kuszmaul | 8e62b02 | 2022-03-22 09:33:25 -0700 | [diff] [blame] | 247 | prefix="union_vector", |
| 248 | schema="union_vector/union_vector.fbs", |
| 249 | ) |
| 250 | |
| 251 | flatc( |
Austin Schuh | 2dd86a9 | 2022-09-14 21:19:23 -0700 | [diff] [blame] | 252 | BASE_OPTS + TS_OPTS, |
| 253 | prefix="ts/union_vector", |
| 254 | schema="union_vector/union_vector.fbs", |
| 255 | ) |
| 256 | |
| 257 | flatc( |
James Kuszmaul | 8e62b02 | 2022-03-22 09:33:25 -0700 | [diff] [blame] | 258 | BASE_OPTS + TS_OPTS + ["--gen-name-strings", "--gen-mutable"], |
| 259 | include="include_test", |
Austin Schuh | 2dd86a9 | 2022-09-14 21:19:23 -0700 | [diff] [blame] | 260 | prefix="ts", |
James Kuszmaul | 8e62b02 | 2022-03-22 09:33:25 -0700 | [diff] [blame] | 261 | schema="monster_test.fbs", |
| 262 | ) |
| 263 | |
Austin Schuh | 2dd86a9 | 2022-09-14 21:19:23 -0700 | [diff] [blame] | 264 | # Generate the complete flat file TS of monster. |
| 265 | flatc( |
| 266 | ["--ts", "--gen-all", "--ts-flat-files"], |
| 267 | include="include_test", |
| 268 | schema="monster_test.fbs", |
| 269 | prefix="ts/ts-flat-files" |
| 270 | ) |
| 271 | |
James Kuszmaul | 8e62b02 | 2022-03-22 09:33:25 -0700 | [diff] [blame] | 272 | flatc( |
| 273 | BASE_OPTS + TS_OPTS + ["-b"], |
| 274 | include="include_test", |
Austin Schuh | 2dd86a9 | 2022-09-14 21:19:23 -0700 | [diff] [blame] | 275 | prefix="ts", |
James Kuszmaul | 8e62b02 | 2022-03-22 09:33:25 -0700 | [diff] [blame] | 276 | schema="monster_test.fbs", |
| 277 | data="unicode_test.json", |
| 278 | ) |
| 279 | |
| 280 | flatc( |
| 281 | BASE_OPTS + TS_OPTS + ["--gen-name-strings"], |
Austin Schuh | 2dd86a9 | 2022-09-14 21:19:23 -0700 | [diff] [blame] | 282 | prefix="ts/union_vector", |
James Kuszmaul | 8e62b02 | 2022-03-22 09:33:25 -0700 | [diff] [blame] | 283 | schema="union_vector/union_vector.fbs", |
| 284 | ) |
| 285 | |
| 286 | flatc( |
| 287 | RUST_OPTS, |
| 288 | prefix="include_test1", |
| 289 | include="include_test", |
| 290 | schema="include_test/include_test1.fbs", |
| 291 | ) |
| 292 | |
| 293 | flatc( |
| 294 | RUST_OPTS, |
| 295 | prefix="include_test2", |
| 296 | include="include_test", |
| 297 | schema="include_test/sub/include_test2.fbs", |
| 298 | ) |
| 299 | |
| 300 | flatc( |
| 301 | BINARY_OPTS + ["--bfbs-filenames", str(tests_path)], |
| 302 | include="include_test", |
| 303 | schema="monster_test.fbs", |
| 304 | ) |
| 305 | |
Austin Schuh | 2dd86a9 | 2022-09-14 21:19:23 -0700 | [diff] [blame] | 306 | # Generate the annotated binary of the monster_test binary schema. |
| 307 | flatc_annotate( |
James Kuszmaul | 3b15b0c | 2022-11-08 14:03:16 -0800 | [diff] [blame] | 308 | schema="../reflection/reflection.fbs", |
| 309 | file="monster_test.bfbs", |
Austin Schuh | 2dd86a9 | 2022-09-14 21:19:23 -0700 | [diff] [blame] | 310 | include="include_test" |
| 311 | ) |
| 312 | |
| 313 | flatc_annotate( |
James Kuszmaul | 3b15b0c | 2022-11-08 14:03:16 -0800 | [diff] [blame] | 314 | schema="monster_test.fbs", |
| 315 | file="monsterdata_test.mon", |
Austin Schuh | 2dd86a9 | 2022-09-14 21:19:23 -0700 | [diff] [blame] | 316 | include="include_test" |
| 317 | ) |
| 318 | |
James Kuszmaul | 8e62b02 | 2022-03-22 09:33:25 -0700 | [diff] [blame] | 319 | flatc( |
| 320 | CPP_OPTS |
| 321 | + NO_INCL_OPTS |
| 322 | + [ |
| 323 | "--bfbs-comments", |
| 324 | "--bfbs-builtins", |
| 325 | "--bfbs-gen-embed", |
| 326 | "--bfbs-filenames", |
| 327 | str(tests_path), |
| 328 | ], |
| 329 | include="include_test", |
| 330 | schema="monster_test.fbs", |
| 331 | ) |
| 332 | |
| 333 | flatc( |
| 334 | BINARY_OPTS + ["--bfbs-filenames", str(tests_path)], |
| 335 | include="include_test", |
| 336 | schema="arrays_test.fbs", |
| 337 | ) |
| 338 | |
| 339 | flatc( |
| 340 | ["--jsonschema", "--schema"], |
| 341 | include="include_test", |
| 342 | schema="monster_test.fbs", |
| 343 | ) |
| 344 | |
| 345 | if not args.skip_monster_extra: |
| 346 | flatc( |
Austin Schuh | 2dd86a9 | 2022-09-14 21:19:23 -0700 | [diff] [blame] | 347 | CPP_OPTS + CS_OPTS + NO_INCL_OPTS + JAVA_OPTS + KOTLIN_OPTS + PYTHON_OPTS, |
James Kuszmaul | 8e62b02 | 2022-03-22 09:33:25 -0700 | [diff] [blame] | 348 | schema="monster_extra.fbs", |
| 349 | data="monsterdata_extra.json", |
| 350 | ) |
| 351 | |
| 352 | flatc( |
| 353 | DART_OPTS + ["--gen-object-api"], |
| 354 | schema="monster_extra.fbs", |
| 355 | ) |
| 356 | |
| 357 | flatc( |
Austin Schuh | 2dd86a9 | 2022-09-14 21:19:23 -0700 | [diff] [blame] | 358 | CPP_OPTS + CS_OPTS + NO_INCL_OPTS + JAVA_OPTS + ["--jsonschema", "--scoped-enums"], |
James Kuszmaul | 8e62b02 | 2022-03-22 09:33:25 -0700 | [diff] [blame] | 359 | schema="arrays_test.fbs", |
| 360 | ) |
| 361 | |
| 362 | flatc( |
| 363 | RUST_OPTS, |
| 364 | prefix="arrays_test", |
| 365 | schema="arrays_test.fbs", |
| 366 | ) |
| 367 | |
| 368 | flatc( |
| 369 | BASE_OPTS + PYTHON_OPTS, |
| 370 | schema="arrays_test.fbs", |
| 371 | ) |
| 372 | |
| 373 | |
James Kuszmaul | 3b15b0c | 2022-11-08 14:03:16 -0800 | [diff] [blame] | 374 | flatc( |
| 375 | BASE_OPTS + PYTHON_OPTS, |
| 376 | schema="nested_union_test.fbs", |
| 377 | ) |
| 378 | |
| 379 | |
James Kuszmaul | 8e62b02 | 2022-03-22 09:33:25 -0700 | [diff] [blame] | 380 | # Optional Scalars |
| 381 | optional_scalars_schema = "optional_scalars.fbs" |
Austin Schuh | 2dd86a9 | 2022-09-14 21:19:23 -0700 | [diff] [blame] | 382 | flatc(["--java", "--kotlin", "--lobster"], schema=optional_scalars_schema) |
| 383 | flatc(TS_OPTS, schema=optional_scalars_schema, prefix="ts") |
James Kuszmaul | 8e62b02 | 2022-03-22 09:33:25 -0700 | [diff] [blame] | 384 | |
Austin Schuh | 2dd86a9 | 2022-09-14 21:19:23 -0700 | [diff] [blame] | 385 | flatc(["--csharp", "--python", "--gen-object-api"], schema=optional_scalars_schema) |
James Kuszmaul | 8e62b02 | 2022-03-22 09:33:25 -0700 | [diff] [blame] | 386 | |
| 387 | flatc(RUST_OPTS, prefix="optional_scalars", schema=optional_scalars_schema) |
| 388 | |
| 389 | flatc(NO_INCL_OPTS + CPP_OPTS, schema=optional_scalars_schema) |
| 390 | |
Austin Schuh | 2dd86a9 | 2022-09-14 21:19:23 -0700 | [diff] [blame] | 391 | # Type / field collsion |
| 392 | type_field_collsion_schema = "type_field_collsion.fbs" |
| 393 | |
| 394 | flatc(["--csharp", "--gen-object-api"], schema=type_field_collsion_schema) |
| 395 | |
James Kuszmaul | 8e62b02 | 2022-03-22 09:33:25 -0700 | [diff] [blame] | 396 | # Generate string/vector default code for tests |
| 397 | flatc(RUST_OPTS, prefix="more_defaults", schema="more_defaults.fbs") |
| 398 | |
| 399 | # Generate the schema evolution tests |
| 400 | flatc( |
| 401 | CPP_OPTS + ["--scoped-enums"], |
| 402 | prefix="evolution_test", |
| 403 | schema=glob(tests_path, "evolution_test/evolution_v*.fbs"), |
| 404 | ) |
| 405 | |
| 406 | # Generate the keywords tests |
| 407 | flatc(BASE_OPTS + CS_OPTS, schema="keyword_test.fbs") |
| 408 | flatc(RUST_OPTS, prefix="keyword_test", schema="keyword_test.fbs") |
| 409 | flatc( |
| 410 | BASE_OPTS + CS_OPTS + ["--cs-global-alias", "--gen-onefile"], |
| 411 | prefix="nested_namespace_test", |
| 412 | schema=glob(tests_path, "nested_namespace_test/nested_namespace_test*.fbs"), |
| 413 | ) |
Austin Schuh | 2dd86a9 | 2022-09-14 21:19:23 -0700 | [diff] [blame] | 414 | flatc(BASE_OPTS + DART_OPTS, prefix="../dart/test/", schema="keyword_test.fbs") |
| 415 | |
| 416 | # Field key lookup with default value test |
| 417 | dictionary_lookup_schema = "dictionary_lookup.fbs" |
| 418 | flatc(["--java", "--kotlin"], schema=dictionary_lookup_schema) |
James Kuszmaul | 8e62b02 | 2022-03-22 09:33:25 -0700 | [diff] [blame] | 419 | |
| 420 | # Swift Tests |
Austin Schuh | 2dd86a9 | 2022-09-14 21:19:23 -0700 | [diff] [blame] | 421 | swift_prefix = "swift/tests/Tests/FlatBuffers.Test.SwiftTests" |
James Kuszmaul | 8e62b02 | 2022-03-22 09:33:25 -0700 | [diff] [blame] | 422 | flatc( |
Austin Schuh | 2dd86a9 | 2022-09-14 21:19:23 -0700 | [diff] [blame] | 423 | SWIFT_OPTS + BASE_OPTS + ["--grpc"], |
James Kuszmaul | 8e62b02 | 2022-03-22 09:33:25 -0700 | [diff] [blame] | 424 | schema="monster_test.fbs", |
| 425 | include="include_test", |
| 426 | prefix=swift_prefix, |
| 427 | ) |
| 428 | flatc( |
| 429 | SWIFT_OPTS + BASE_OPTS, |
| 430 | schema="union_vector/union_vector.fbs", |
| 431 | prefix=swift_prefix, |
| 432 | ) |
| 433 | flatc(SWIFT_OPTS, schema="optional_scalars.fbs", prefix=swift_prefix) |
Austin Schuh | 2dd86a9 | 2022-09-14 21:19:23 -0700 | [diff] [blame] | 434 | flatc(SWIFT_OPTS, schema="vector_has_test.fbs", prefix=swift_prefix) |
James Kuszmaul | 8e62b02 | 2022-03-22 09:33:25 -0700 | [diff] [blame] | 435 | flatc( |
| 436 | SWIFT_OPTS + ["--gen-object-api"], |
| 437 | schema="more_defaults.fbs", |
| 438 | prefix=swift_prefix, |
| 439 | ) |
| 440 | flatc( |
| 441 | SWIFT_OPTS + BASE_OPTS, |
| 442 | schema="MutatingBool.fbs", |
| 443 | prefix=swift_prefix, |
| 444 | ) |
| 445 | |
Austin Schuh | 2dd86a9 | 2022-09-14 21:19:23 -0700 | [diff] [blame] | 446 | flatc( |
| 447 | SWIFT_OPTS_CODE_GEN + BASE_OPTS + ["--grpc", "--swift-implementation-only"], |
| 448 | schema="test_import.fbs", |
| 449 | cwd=swift_code_gen |
| 450 | ) |
| 451 | |
| 452 | flatc( |
| 453 | SWIFT_OPTS_CODE_GEN + NO_INCL_OPTS + ["--grpc"], |
| 454 | schema="test_no_include.fbs", |
| 455 | cwd=swift_code_gen |
| 456 | ) |
| 457 | |
James Kuszmaul | 3b15b0c | 2022-11-08 14:03:16 -0800 | [diff] [blame] | 458 | # Nim Tests |
| 459 | NIM_OPTS = BASE_OPTS + ["--nim"] |
| 460 | flatc(NIM_OPTS, schema="monster_test.fbs", include="include_test") |
| 461 | flatc(NIM_OPTS, schema="optional_scalars.fbs") |
| 462 | flatc(NIM_OPTS, schema="more_defaults.fbs") |
| 463 | flatc(NIM_OPTS, schema="MutatingBool.fbs") |
| 464 | |
James Kuszmaul | 8e62b02 | 2022-03-22 09:33:25 -0700 | [diff] [blame] | 465 | # --filename-suffix and --filename-ext tests |
| 466 | flatc( |
Austin Schuh | 2dd86a9 | 2022-09-14 21:19:23 -0700 | [diff] [blame] | 467 | CPP_OPTS + NO_INCL_OPTS + ["--grpc", "--filename-ext", "hpp"], |
James Kuszmaul | 8e62b02 | 2022-03-22 09:33:25 -0700 | [diff] [blame] | 468 | include="include_test", |
Austin Schuh | 2dd86a9 | 2022-09-14 21:19:23 -0700 | [diff] [blame] | 469 | prefix="monster_test_suffix/ext_only", |
James Kuszmaul | 8e62b02 | 2022-03-22 09:33:25 -0700 | [diff] [blame] | 470 | schema="monster_test.fbs", |
| 471 | ) |
Austin Schuh | 2dd86a9 | 2022-09-14 21:19:23 -0700 | [diff] [blame] | 472 | flatc( |
| 473 | CPP_OPTS + NO_INCL_OPTS + ["--grpc", "--filename-suffix", "_suffix"], |
| 474 | include="include_test", |
| 475 | prefix="monster_test_suffix/filesuffix_only", |
| 476 | schema="monster_test.fbs", |
| 477 | ) |
| 478 | flatc( |
| 479 | CPP_OPTS + NO_INCL_OPTS + ["--grpc", "--filename-suffix", "_suffix", "--filename-ext", "hpp"], |
| 480 | include="include_test", |
| 481 | prefix="monster_test_suffix", |
| 482 | schema="monster_test.fbs", |
| 483 | ) |
James Kuszmaul | 8e62b02 | 2022-03-22 09:33:25 -0700 | [diff] [blame] | 484 | |
| 485 | # Flag c++17 requires Clang6, GCC7, MSVC2017 (_MSC_VER >= 1914) or higher. |
| 486 | cpp_17_prefix = "cpp17/generated_cpp17" |
| 487 | flatc( |
| 488 | CPP_17_OPTS, |
| 489 | schema="monster_test.fbs", |
| 490 | include="include_test", |
| 491 | prefix=cpp_17_prefix, |
| 492 | ) |
| 493 | flatc( |
| 494 | CPP_17_OPTS, |
| 495 | schema="optional_scalars.fbs", |
| 496 | prefix=cpp_17_prefix, |
| 497 | ) |
| 498 | flatc( |
| 499 | CPP_17_OPTS, |
| 500 | schema="union_vector/union_vector.fbs", |
| 501 | prefix=cpp_17_prefix, |
| 502 | ) |
| 503 | |
Austin Schuh | 2dd86a9 | 2022-09-14 21:19:23 -0700 | [diff] [blame] | 504 | # Private annotations |
| 505 | annotations_test_schema = "private_annotation_test.fbs" |
| 506 | |
| 507 | flatc(RUST_OPTS + ["--no-leak-private-annotation", "--gen-object-api"], prefix="private_annotation_test", schema=annotations_test_schema) |
| 508 | |
James Kuszmaul | 8e62b02 | 2022-03-22 09:33:25 -0700 | [diff] [blame] | 509 | # Sample files |
| 510 | samples_schema = "monster.fbs" |
Austin Schuh | 2dd86a9 | 2022-09-14 21:19:23 -0700 | [diff] [blame] | 511 | flatc(BASE_OPTS + CPP_OPTS + LOBSTER_OPTS, schema=samples_schema, cwd=samples_path) |
| 512 | flatc(RUST_OPTS, prefix="rust_generated", schema=samples_schema, cwd=samples_path) |
James Kuszmaul | 8e62b02 | 2022-03-22 09:33:25 -0700 | [diff] [blame] | 513 | flatc( |
| 514 | BINARY_OPTS + ["--bfbs-filenames", str(samples_path)], |
| 515 | schema=samples_schema, |
| 516 | cwd=samples_path, |
| 517 | ) |
| 518 | |
| 519 | # Reflection |
| 520 | |
| 521 | # Skip generating the reflection if told too, as we run this script after |
| 522 | # building flatc which uses the reflection_generated.h itself. |
| 523 | if not args.skip_gen_reflection: |
Austin Schuh | 2dd86a9 | 2022-09-14 21:19:23 -0700 | [diff] [blame] | 524 | # C++ Reflection |
| 525 | flatc_reflection( |
| 526 | ["-c", "--cpp-std", "c++0x"], "include/flatbuffers", "reflection_generated.h" |
| 527 | ) |
James Kuszmaul | 8e62b02 | 2022-03-22 09:33:25 -0700 | [diff] [blame] | 528 | |
| 529 | # Python Reflection |
| 530 | flatc_reflection(["-p"], "python/flatbuffers", "reflection") |
Austin Schuh | 2dd86a9 | 2022-09-14 21:19:23 -0700 | [diff] [blame] | 531 | |
| 532 | # Annotation |
| 533 | |
| 534 | |
| 535 | def flatc_annotate(schema, include=None, data=None, cwd=tests_path): |
| 536 | cmd = [str(flatc_path)] |
| 537 | if include: |
| 538 | cmd += ["-I"] + [include] |
| 539 | cmd += ["--annotate", schema] |
| 540 | if data: |
| 541 | cmd += [data] if isinstance(data, str) else data |
| 542 | subprocess.run(cmd, cwd=str(cwd), check=True) |
| 543 | |
| 544 | |
| 545 | flatc_annotate( |
| 546 | schema="monster_test.fbs", include="include_test", data="monsterdata_test.mon" |
| 547 | ) |
| 548 | |
| 549 | # Run the generate_grpc_examples script |
| 550 | generate_grpc_examples.GenerateGRPCExamples() |