2021-09-30 19:38:52 +00:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
#
|
|
|
|
# Copyright 2021 Google Inc. All rights reserved.
|
|
|
|
#
|
|
|
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
# you may not use this file except in compliance with the License.
|
|
|
|
# You may obtain a copy of the License at
|
|
|
|
#
|
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
#
|
|
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
|
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
# See the License for the specific language governing permissions and
|
|
|
|
# limitations under the License.
|
|
|
|
|
|
|
|
import filecmp
|
|
|
|
import glob
|
|
|
|
import shutil
|
|
|
|
import subprocess
|
2022-08-17 06:44:50 +00:00
|
|
|
import generate_grpc_examples
|
2021-09-30 19:38:52 +00:00
|
|
|
from pathlib import Path
|
2023-01-10 20:04:25 +00:00
|
|
|
from util import flatc, root_path, tests_path, args, flatc_path
|
2021-09-30 19:38:52 +00:00
|
|
|
|
|
|
|
# Specify the other paths that will be referenced
|
2022-09-10 05:35:42 +00:00
|
|
|
swift_code_gen = Path(root_path, "tests/swift/tests/CodeGenerationTests")
|
2023-01-21 20:22:22 +00:00
|
|
|
ts_code_gen = Path(root_path, "tests/ts")
|
2021-09-30 19:38:52 +00:00
|
|
|
samples_path = Path(root_path, "samples")
|
|
|
|
reflection_path = Path(root_path, "reflection")
|
|
|
|
|
2023-05-05 19:08:09 +00:00
|
|
|
|
2022-02-10 19:10:47 +00:00
|
|
|
# Generate the code for flatbuffers reflection schema
|
|
|
|
def flatc_reflection(options, location, target):
|
|
|
|
full_options = ["--no-prefix"] + options
|
|
|
|
temp_dir = ".tmp"
|
|
|
|
flatc(
|
|
|
|
full_options,
|
|
|
|
prefix=temp_dir,
|
|
|
|
schema="reflection.fbs",
|
|
|
|
cwd=reflection_path,
|
|
|
|
)
|
|
|
|
new_reflection_path = Path(reflection_path, temp_dir, target)
|
|
|
|
original_reflection_path = Path(root_path, location, target)
|
|
|
|
if not filecmp.cmp(str(new_reflection_path), str(original_reflection_path)):
|
2022-08-23 04:42:15 +00:00
|
|
|
shutil.rmtree(str(original_reflection_path), ignore_errors=True)
|
2022-02-10 19:10:47 +00:00
|
|
|
shutil.move(str(new_reflection_path), str(original_reflection_path))
|
|
|
|
shutil.rmtree(str(Path(reflection_path, temp_dir)))
|
|
|
|
|
2023-05-05 19:08:09 +00:00
|
|
|
|
2022-04-22 03:43:55 +00:00
|
|
|
def flatc_annotate(schema, file, include=None, cwd=tests_path):
|
|
|
|
cmd = [str(flatc_path)]
|
|
|
|
if include:
|
|
|
|
cmd += ["-I"] + [include]
|
|
|
|
cmd += ["--annotate", schema, file]
|
|
|
|
result = subprocess.run(cmd, cwd=str(cwd), check=True)
|
2022-02-10 19:10:47 +00:00
|
|
|
|
2023-05-05 19:08:09 +00:00
|
|
|
|
2021-09-30 19:38:52 +00:00
|
|
|
# Glob a pattern relative to file path
|
|
|
|
def glob(path, pattern):
|
|
|
|
return [str(p) for p in path.glob(pattern)]
|
|
|
|
|
|
|
|
|
|
|
|
# flatc options that are shared
|
|
|
|
BASE_OPTS = ["--reflect-names", "--gen-mutable", "--gen-object-api"]
|
|
|
|
NO_INCL_OPTS = BASE_OPTS + ["--no-includes"]
|
|
|
|
|
|
|
|
# Language specific options
|
|
|
|
CS_OPTS = ["--csharp", "--cs-gen-json-serializer"]
|
|
|
|
CPP_OPTS = [
|
|
|
|
"--cpp",
|
|
|
|
"--gen-compare",
|
2021-12-01 07:13:24 +00:00
|
|
|
] + (["--cpp-std", "c++0x"] if args.cpp_0x else [])
|
|
|
|
|
2021-09-30 19:38:52 +00:00
|
|
|
CPP_17_OPTS = NO_INCL_OPTS + [
|
|
|
|
"--cpp",
|
|
|
|
"--cpp-std",
|
|
|
|
"c++17",
|
|
|
|
"--cpp-static-reflection",
|
|
|
|
"--gen-object-api",
|
|
|
|
]
|
2022-03-30 23:43:22 +00:00
|
|
|
RUST_OPTS = BASE_OPTS + [
|
|
|
|
"--rust",
|
|
|
|
"--gen-all",
|
|
|
|
"--gen-name-strings",
|
|
|
|
"--rust-module-root-file",
|
|
|
|
]
|
2022-02-03 06:42:26 +00:00
|
|
|
RUST_SERIALIZE_OPTS = BASE_OPTS + [
|
|
|
|
"--rust",
|
|
|
|
"--gen-all",
|
|
|
|
"--gen-name-strings",
|
|
|
|
"--rust-serialize",
|
2022-02-15 16:48:42 +00:00
|
|
|
"--rust-module-root-file",
|
2022-02-03 06:42:26 +00:00
|
|
|
]
|
2021-09-30 19:38:52 +00:00
|
|
|
TS_OPTS = ["--ts", "--gen-name-strings"]
|
|
|
|
LOBSTER_OPTS = ["--lobster"]
|
2021-10-07 21:22:22 +00:00
|
|
|
SWIFT_OPTS = ["--swift", "--gen-json-emit", "--bfbs-filenames", str(tests_path)]
|
2022-04-06 20:31:38 +00:00
|
|
|
SWIFT_OPTS_CODE_GEN = [
|
2022-10-26 21:56:52 +00:00
|
|
|
"--swift",
|
2022-04-06 20:31:38 +00:00
|
|
|
"--gen-json-emit",
|
|
|
|
"--bfbs-filenames",
|
2023-05-05 19:08:09 +00:00
|
|
|
str(swift_code_gen),
|
2022-04-06 20:31:38 +00:00
|
|
|
]
|
2021-09-30 19:38:52 +00:00
|
|
|
JAVA_OPTS = ["--java"]
|
|
|
|
KOTLIN_OPTS = ["--kotlin"]
|
|
|
|
PHP_OPTS = ["--php"]
|
|
|
|
DART_OPTS = ["--dart"]
|
2023-04-28 16:38:29 +00:00
|
|
|
PYTHON_OPTS = ["--python", "--python-typing"]
|
2021-09-30 19:38:52 +00:00
|
|
|
BINARY_OPTS = ["-b", "--schema", "--bfbs-comments", "--bfbs-builtins"]
|
2023-03-02 18:01:44 +00:00
|
|
|
PROTO_OPTS = ["--proto"]
|
2021-09-30 19:38:52 +00:00
|
|
|
|
|
|
|
# Basic Usage
|
|
|
|
|
|
|
|
flatc(
|
|
|
|
NO_INCL_OPTS
|
|
|
|
+ CPP_OPTS
|
|
|
|
+ CS_OPTS
|
|
|
|
+ [
|
|
|
|
"--binary",
|
|
|
|
"--java",
|
|
|
|
"--kotlin",
|
|
|
|
"--dart",
|
|
|
|
"--go",
|
|
|
|
"--lobster",
|
|
|
|
"--php",
|
|
|
|
],
|
|
|
|
schema="monster_test.fbs",
|
|
|
|
include="include_test",
|
|
|
|
data="monsterdata_test.json",
|
|
|
|
)
|
2022-11-13 19:21:57 +00:00
|
|
|
|
|
|
|
flatc(
|
2023-05-05 19:08:09 +00:00
|
|
|
NO_INCL_OPTS + DART_OPTS,
|
2022-11-13 19:21:57 +00:00
|
|
|
schema="include_test/include_test1.fbs",
|
|
|
|
include="include_test/sub",
|
|
|
|
)
|
|
|
|
|
|
|
|
flatc(
|
2023-05-05 19:08:09 +00:00
|
|
|
NO_INCL_OPTS + DART_OPTS,
|
2022-11-13 19:21:57 +00:00
|
|
|
schema="include_test/sub/include_test2.fbs",
|
|
|
|
include="include_test",
|
|
|
|
)
|
2021-09-30 19:38:52 +00:00
|
|
|
|
2022-09-13 03:03:23 +00:00
|
|
|
flatc(
|
2023-05-05 19:08:09 +00:00
|
|
|
NO_INCL_OPTS + TS_OPTS,
|
2023-01-21 20:22:22 +00:00
|
|
|
cwd=ts_code_gen,
|
|
|
|
schema="../monster_test.fbs",
|
|
|
|
include="../include_test",
|
|
|
|
data="../monsterdata_test.json",
|
2022-09-13 03:03:23 +00:00
|
|
|
)
|
|
|
|
|
2021-12-03 05:29:19 +00:00
|
|
|
flatc(
|
|
|
|
["--lua", "--bfbs-filenames", str(tests_path)],
|
|
|
|
schema="monster_test.fbs",
|
2022-02-03 06:42:26 +00:00
|
|
|
include="include_test",
|
2021-12-03 05:29:19 +00:00
|
|
|
)
|
|
|
|
|
2021-09-30 19:38:52 +00:00
|
|
|
flatc(
|
|
|
|
NO_INCL_OPTS + CPP_OPTS + ["--grpc"],
|
|
|
|
schema="monster_test.fbs",
|
|
|
|
include="include_test",
|
|
|
|
data="monsterdata_test.json",
|
|
|
|
)
|
|
|
|
|
|
|
|
flatc(
|
|
|
|
RUST_OPTS,
|
|
|
|
schema="monster_test.fbs",
|
|
|
|
include="include_test",
|
|
|
|
prefix="monster_test",
|
|
|
|
data="monsterdata_test.json",
|
|
|
|
)
|
|
|
|
|
2022-01-31 00:29:18 +00:00
|
|
|
flatc(
|
|
|
|
RUST_SERIALIZE_OPTS,
|
|
|
|
schema="monster_test.fbs",
|
|
|
|
include="include_test",
|
|
|
|
prefix="monster_test_serialize",
|
|
|
|
data="monsterdata_test.json",
|
|
|
|
)
|
|
|
|
|
2021-09-30 19:38:52 +00:00
|
|
|
flatc(
|
|
|
|
options=BASE_OPTS + ["--python"],
|
|
|
|
schema="monster_test.fbs",
|
|
|
|
include="include_test",
|
|
|
|
data="monsterdata_test.json",
|
|
|
|
)
|
|
|
|
|
2021-12-09 23:47:09 +00:00
|
|
|
flatc(
|
|
|
|
options=BASE_OPTS + ["--python", "--gen-onefile"],
|
|
|
|
schema="monster_test.fbs",
|
|
|
|
include="include_test",
|
|
|
|
data="monsterdata_test.json",
|
|
|
|
)
|
|
|
|
|
2023-03-02 18:01:44 +00:00
|
|
|
flatc(
|
|
|
|
PROTO_OPTS,
|
|
|
|
schema="prototest/test.proto",
|
|
|
|
)
|
|
|
|
|
2021-09-30 19:38:52 +00:00
|
|
|
# For Rust we currently generate two independent schemas, with namespace_test2
|
|
|
|
# duplicating the types in namespace_test1
|
|
|
|
flatc(
|
2022-09-01 17:17:34 +00:00
|
|
|
RUST_OPTS + CS_OPTS,
|
2021-09-30 19:38:52 +00:00
|
|
|
prefix="namespace_test",
|
|
|
|
schema=[
|
|
|
|
"namespace_test/namespace_test1.fbs",
|
|
|
|
"namespace_test/namespace_test2.fbs",
|
|
|
|
],
|
|
|
|
)
|
|
|
|
|
2023-05-05 19:08:09 +00:00
|
|
|
flatc(
|
|
|
|
[
|
|
|
|
"--cpp",
|
|
|
|
"--reflect-names",
|
|
|
|
"--no-includes",
|
|
|
|
"--gen-mutable",
|
|
|
|
"--gen-object-api",
|
|
|
|
"--gen-compare",
|
|
|
|
"--gen-name-strings",
|
|
|
|
],
|
|
|
|
prefix="namespace_test",
|
|
|
|
schema=[
|
|
|
|
"namespace_test/namespace_test1.fbs",
|
|
|
|
"namespace_test/namespace_test2.fbs",
|
|
|
|
],
|
|
|
|
)
|
|
|
|
|
2021-09-30 19:38:52 +00:00
|
|
|
flatc(
|
2022-09-13 03:03:23 +00:00
|
|
|
BASE_OPTS + CPP_OPTS + CS_OPTS + JAVA_OPTS + KOTLIN_OPTS + PHP_OPTS,
|
2021-09-30 19:38:52 +00:00
|
|
|
prefix="union_vector",
|
|
|
|
schema="union_vector/union_vector.fbs",
|
|
|
|
)
|
|
|
|
|
2022-09-13 03:03:23 +00:00
|
|
|
flatc(
|
|
|
|
BASE_OPTS + TS_OPTS,
|
2023-01-21 20:22:22 +00:00
|
|
|
cwd=ts_code_gen,
|
|
|
|
prefix="union_vector",
|
|
|
|
schema="../union_vector/union_vector.fbs",
|
2022-09-13 03:03:23 +00:00
|
|
|
)
|
|
|
|
|
2021-09-30 19:38:52 +00:00
|
|
|
flatc(
|
|
|
|
BASE_OPTS + TS_OPTS + ["--gen-name-strings", "--gen-mutable"],
|
2023-01-21 20:22:22 +00:00
|
|
|
cwd=ts_code_gen,
|
|
|
|
include="../include_test",
|
|
|
|
schema="../monster_test.fbs",
|
2022-08-16 19:52:26 +00:00
|
|
|
)
|
|
|
|
|
2021-09-30 19:38:52 +00:00
|
|
|
flatc(
|
|
|
|
BASE_OPTS + TS_OPTS + ["-b"],
|
2023-01-21 20:22:22 +00:00
|
|
|
cwd=ts_code_gen,
|
|
|
|
include="../include_test",
|
|
|
|
schema="../monster_test.fbs",
|
|
|
|
data="../unicode_test.json",
|
2021-09-30 19:38:52 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
flatc(
|
|
|
|
BASE_OPTS + TS_OPTS + ["--gen-name-strings"],
|
2023-01-21 20:22:22 +00:00
|
|
|
cwd=ts_code_gen,
|
|
|
|
prefix="union_vector",
|
|
|
|
schema="../union_vector/union_vector.fbs",
|
2021-09-30 19:38:52 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
flatc(
|
|
|
|
RUST_OPTS,
|
|
|
|
prefix="include_test1",
|
|
|
|
include="include_test",
|
|
|
|
schema="include_test/include_test1.fbs",
|
|
|
|
)
|
|
|
|
|
|
|
|
flatc(
|
|
|
|
RUST_OPTS,
|
|
|
|
prefix="include_test2",
|
|
|
|
include="include_test",
|
|
|
|
schema="include_test/sub/include_test2.fbs",
|
|
|
|
)
|
|
|
|
|
|
|
|
flatc(
|
|
|
|
BINARY_OPTS + ["--bfbs-filenames", str(tests_path)],
|
|
|
|
include="include_test",
|
|
|
|
schema="monster_test.fbs",
|
|
|
|
)
|
|
|
|
|
2022-04-22 03:43:55 +00:00
|
|
|
# Generate the annotated binary of the monster_test binary schema.
|
|
|
|
flatc_annotate(
|
2022-10-26 21:56:52 +00:00
|
|
|
schema="../reflection/reflection.fbs",
|
|
|
|
file="monster_test.bfbs",
|
2023-05-05 19:08:09 +00:00
|
|
|
include="include_test",
|
2022-04-22 03:43:55 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
flatc_annotate(
|
2023-05-05 19:08:09 +00:00
|
|
|
schema="monster_test.fbs", file="monsterdata_test.mon", include="include_test"
|
2022-04-22 03:43:55 +00:00
|
|
|
)
|
|
|
|
|
2021-09-30 19:38:52 +00:00
|
|
|
flatc(
|
|
|
|
CPP_OPTS
|
|
|
|
+ NO_INCL_OPTS
|
|
|
|
+ [
|
|
|
|
"--bfbs-comments",
|
|
|
|
"--bfbs-builtins",
|
|
|
|
"--bfbs-gen-embed",
|
|
|
|
"--bfbs-filenames",
|
|
|
|
str(tests_path),
|
|
|
|
],
|
|
|
|
include="include_test",
|
|
|
|
schema="monster_test.fbs",
|
|
|
|
)
|
|
|
|
|
|
|
|
flatc(
|
|
|
|
BINARY_OPTS + ["--bfbs-filenames", str(tests_path)],
|
|
|
|
include="include_test",
|
|
|
|
schema="arrays_test.fbs",
|
|
|
|
)
|
|
|
|
|
|
|
|
flatc(
|
|
|
|
["--jsonschema", "--schema"],
|
|
|
|
include="include_test",
|
|
|
|
schema="monster_test.fbs",
|
|
|
|
)
|
|
|
|
|
2021-12-01 07:13:24 +00:00
|
|
|
if not args.skip_monster_extra:
|
|
|
|
flatc(
|
2022-03-30 23:43:22 +00:00
|
|
|
CPP_OPTS + CS_OPTS + NO_INCL_OPTS + JAVA_OPTS + KOTLIN_OPTS + PYTHON_OPTS,
|
2021-12-01 07:13:24 +00:00
|
|
|
schema="monster_extra.fbs",
|
|
|
|
data="monsterdata_extra.json",
|
|
|
|
)
|
|
|
|
|
|
|
|
flatc(
|
|
|
|
DART_OPTS + ["--gen-object-api"],
|
|
|
|
schema="monster_extra.fbs",
|
|
|
|
)
|
2021-09-30 19:38:52 +00:00
|
|
|
|
|
|
|
flatc(
|
2022-03-30 23:43:22 +00:00
|
|
|
CPP_OPTS + CS_OPTS + NO_INCL_OPTS + JAVA_OPTS + ["--jsonschema", "--scoped-enums"],
|
2021-09-30 19:38:52 +00:00
|
|
|
schema="arrays_test.fbs",
|
|
|
|
)
|
|
|
|
|
|
|
|
flatc(
|
|
|
|
RUST_OPTS,
|
|
|
|
prefix="arrays_test",
|
|
|
|
schema="arrays_test.fbs",
|
|
|
|
)
|
|
|
|
|
2023-05-17 17:54:49 +00:00
|
|
|
flatc(
|
|
|
|
RUST_OPTS,
|
|
|
|
prefix="rust_namer_test",
|
|
|
|
schema="rust_namer_test.fbs",
|
|
|
|
)
|
|
|
|
|
2021-09-30 19:38:52 +00:00
|
|
|
flatc(
|
|
|
|
BASE_OPTS + PYTHON_OPTS,
|
|
|
|
schema="arrays_test.fbs",
|
2022-10-26 21:56:52 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
flatc(
|
|
|
|
BASE_OPTS + PYTHON_OPTS,
|
|
|
|
schema="nested_union_test.fbs",
|
2021-09-30 19:38:52 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
# Optional Scalars
|
|
|
|
optional_scalars_schema = "optional_scalars.fbs"
|
2022-09-13 03:03:23 +00:00
|
|
|
flatc(["--java", "--kotlin", "--lobster"], schema=optional_scalars_schema)
|
2023-01-21 20:22:22 +00:00
|
|
|
flatc(TS_OPTS, cwd=ts_code_gen, schema="../optional_scalars.fbs")
|
2021-09-30 19:38:52 +00:00
|
|
|
|
2022-06-13 13:16:00 +00:00
|
|
|
flatc(["--csharp", "--python", "--gen-object-api"], schema=optional_scalars_schema)
|
2021-09-30 19:38:52 +00:00
|
|
|
|
|
|
|
flatc(RUST_OPTS, prefix="optional_scalars", schema=optional_scalars_schema)
|
|
|
|
|
|
|
|
flatc(NO_INCL_OPTS + CPP_OPTS, schema=optional_scalars_schema)
|
|
|
|
|
2022-03-30 19:51:58 +00:00
|
|
|
# Type / field collsion
|
|
|
|
type_field_collsion_schema = "type_field_collsion.fbs"
|
|
|
|
|
|
|
|
flatc(["--csharp", "--gen-object-api"], schema=type_field_collsion_schema)
|
|
|
|
|
2023-01-07 20:37:22 +00:00
|
|
|
# Union / value collision
|
|
|
|
flatc(
|
|
|
|
CS_OPTS + ["--gen-object-api", "--gen-onefile"],
|
|
|
|
prefix="union_value_collsion",
|
2023-05-05 19:08:09 +00:00
|
|
|
schema="union_value_collision.fbs",
|
2023-01-07 20:37:22 +00:00
|
|
|
)
|
|
|
|
|
2021-09-30 19:38:52 +00:00
|
|
|
# Generate string/vector default code for tests
|
|
|
|
flatc(RUST_OPTS, prefix="more_defaults", schema="more_defaults.fbs")
|
|
|
|
|
|
|
|
# Generate the schema evolution tests
|
|
|
|
flatc(
|
|
|
|
CPP_OPTS + ["--scoped-enums"],
|
|
|
|
prefix="evolution_test",
|
|
|
|
schema=glob(tests_path, "evolution_test/evolution_v*.fbs"),
|
|
|
|
)
|
|
|
|
|
|
|
|
# Generate the keywords tests
|
|
|
|
flatc(BASE_OPTS + CS_OPTS, schema="keyword_test.fbs")
|
|
|
|
flatc(RUST_OPTS, prefix="keyword_test", schema="keyword_test.fbs")
|
|
|
|
flatc(
|
|
|
|
BASE_OPTS + CS_OPTS + ["--cs-global-alias", "--gen-onefile"],
|
|
|
|
prefix="nested_namespace_test",
|
|
|
|
schema=glob(tests_path, "nested_namespace_test/nested_namespace_test*.fbs"),
|
|
|
|
)
|
2022-03-28 22:07:09 +00:00
|
|
|
flatc(BASE_OPTS + DART_OPTS, prefix="../dart/test/", schema="keyword_test.fbs")
|
2021-09-30 19:38:52 +00:00
|
|
|
|
2022-04-12 00:16:41 +00:00
|
|
|
# Field key lookup with default value test
|
|
|
|
dictionary_lookup_schema = "dictionary_lookup.fbs"
|
2022-04-12 00:17:19 +00:00
|
|
|
flatc(["--java", "--kotlin"], schema=dictionary_lookup_schema)
|
2022-04-12 00:16:41 +00:00
|
|
|
|
2021-09-30 19:38:52 +00:00
|
|
|
# Swift Tests
|
2022-09-10 05:35:42 +00:00
|
|
|
swift_prefix = "swift/tests/Tests/FlatBuffers.Test.SwiftTests"
|
2021-09-30 19:38:52 +00:00
|
|
|
flatc(
|
2022-03-23 04:42:20 +00:00
|
|
|
SWIFT_OPTS + BASE_OPTS + ["--grpc"],
|
2021-09-30 19:38:52 +00:00
|
|
|
schema="monster_test.fbs",
|
|
|
|
include="include_test",
|
|
|
|
prefix=swift_prefix,
|
|
|
|
)
|
|
|
|
flatc(
|
|
|
|
SWIFT_OPTS + BASE_OPTS,
|
|
|
|
schema="union_vector/union_vector.fbs",
|
|
|
|
prefix=swift_prefix,
|
|
|
|
)
|
|
|
|
flatc(SWIFT_OPTS, schema="optional_scalars.fbs", prefix=swift_prefix)
|
2022-05-11 13:35:53 +00:00
|
|
|
flatc(SWIFT_OPTS, schema="vector_has_test.fbs", prefix=swift_prefix)
|
2022-11-11 17:36:47 +00:00
|
|
|
flatc(SWIFT_OPTS, schema="nan_inf_test.fbs", prefix=swift_prefix)
|
2021-09-30 19:38:52 +00:00
|
|
|
flatc(
|
|
|
|
SWIFT_OPTS + ["--gen-object-api"],
|
|
|
|
schema="more_defaults.fbs",
|
|
|
|
prefix=swift_prefix,
|
|
|
|
)
|
2022-02-02 20:39:19 +00:00
|
|
|
flatc(
|
|
|
|
SWIFT_OPTS + BASE_OPTS,
|
|
|
|
schema="MutatingBool.fbs",
|
|
|
|
prefix=swift_prefix,
|
|
|
|
)
|
2021-09-30 19:38:52 +00:00
|
|
|
|
2022-04-06 20:31:38 +00:00
|
|
|
flatc(
|
|
|
|
SWIFT_OPTS_CODE_GEN + BASE_OPTS + ["--grpc", "--swift-implementation-only"],
|
|
|
|
schema="test_import.fbs",
|
2023-05-05 19:08:09 +00:00
|
|
|
cwd=swift_code_gen,
|
2022-04-06 20:31:38 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
flatc(
|
|
|
|
SWIFT_OPTS_CODE_GEN + NO_INCL_OPTS + ["--grpc"],
|
|
|
|
schema="test_no_include.fbs",
|
2023-05-05 19:08:09 +00:00
|
|
|
cwd=swift_code_gen,
|
2022-04-06 20:31:38 +00:00
|
|
|
)
|
|
|
|
|
2023-01-07 00:40:40 +00:00
|
|
|
# Swift Wasm Tests
|
|
|
|
swift_Wasm_prefix = "swift/Wasm.tests/Tests/FlatBuffers.Test.Swift.WasmTests"
|
|
|
|
flatc(
|
|
|
|
SWIFT_OPTS + BASE_OPTS,
|
|
|
|
schema="monster_test.fbs",
|
|
|
|
include="include_test",
|
|
|
|
prefix=swift_Wasm_prefix,
|
|
|
|
)
|
|
|
|
|
2022-10-21 18:30:04 +00:00
|
|
|
# Nim Tests
|
|
|
|
NIM_OPTS = BASE_OPTS + ["--nim"]
|
|
|
|
flatc(NIM_OPTS, schema="monster_test.fbs", include="include_test")
|
|
|
|
flatc(NIM_OPTS, schema="optional_scalars.fbs")
|
|
|
|
flatc(NIM_OPTS, schema="more_defaults.fbs")
|
|
|
|
flatc(NIM_OPTS, schema="MutatingBool.fbs")
|
|
|
|
|
2021-09-30 19:38:52 +00:00
|
|
|
# --filename-suffix and --filename-ext tests
|
|
|
|
flatc(
|
2022-08-07 18:32:53 +00:00
|
|
|
CPP_OPTS + NO_INCL_OPTS + ["--grpc", "--filename-ext", "hpp"],
|
2021-09-30 19:38:52 +00:00
|
|
|
include="include_test",
|
2022-08-07 18:32:53 +00:00
|
|
|
prefix="monster_test_suffix/ext_only",
|
|
|
|
schema="monster_test.fbs",
|
|
|
|
)
|
|
|
|
flatc(
|
|
|
|
CPP_OPTS + NO_INCL_OPTS + ["--grpc", "--filename-suffix", "_suffix"],
|
|
|
|
include="include_test",
|
|
|
|
prefix="monster_test_suffix/filesuffix_only",
|
|
|
|
schema="monster_test.fbs",
|
|
|
|
)
|
|
|
|
flatc(
|
2023-05-05 19:08:09 +00:00
|
|
|
CPP_OPTS
|
|
|
|
+ NO_INCL_OPTS
|
|
|
|
+ ["--grpc", "--filename-suffix", "_suffix", "--filename-ext", "hpp"],
|
2022-08-07 18:32:53 +00:00
|
|
|
include="include_test",
|
|
|
|
prefix="monster_test_suffix",
|
2021-09-30 19:38:52 +00:00
|
|
|
schema="monster_test.fbs",
|
|
|
|
)
|
|
|
|
|
|
|
|
# Flag c++17 requires Clang6, GCC7, MSVC2017 (_MSC_VER >= 1914) or higher.
|
|
|
|
cpp_17_prefix = "cpp17/generated_cpp17"
|
|
|
|
flatc(
|
|
|
|
CPP_17_OPTS,
|
|
|
|
schema="monster_test.fbs",
|
|
|
|
include="include_test",
|
|
|
|
prefix=cpp_17_prefix,
|
|
|
|
)
|
|
|
|
flatc(
|
|
|
|
CPP_17_OPTS,
|
|
|
|
schema="optional_scalars.fbs",
|
|
|
|
prefix=cpp_17_prefix,
|
|
|
|
)
|
|
|
|
flatc(
|
|
|
|
CPP_17_OPTS,
|
|
|
|
schema="union_vector/union_vector.fbs",
|
|
|
|
prefix=cpp_17_prefix,
|
|
|
|
)
|
|
|
|
|
2022-06-05 21:04:05 +00:00
|
|
|
# Private annotations
|
|
|
|
annotations_test_schema = "private_annotation_test.fbs"
|
|
|
|
|
2023-05-05 19:08:09 +00:00
|
|
|
flatc(
|
|
|
|
RUST_OPTS + ["--no-leak-private-annotation", "--gen-object-api"],
|
|
|
|
prefix="private_annotation_test",
|
|
|
|
schema=annotations_test_schema,
|
|
|
|
)
|
2022-06-05 21:04:05 +00:00
|
|
|
|
2021-09-30 19:38:52 +00:00
|
|
|
# Sample files
|
|
|
|
samples_schema = "monster.fbs"
|
2022-03-30 23:43:22 +00:00
|
|
|
flatc(BASE_OPTS + CPP_OPTS + LOBSTER_OPTS, schema=samples_schema, cwd=samples_path)
|
|
|
|
flatc(RUST_OPTS, prefix="rust_generated", schema=samples_schema, cwd=samples_path)
|
2021-09-30 19:38:52 +00:00
|
|
|
flatc(
|
|
|
|
BINARY_OPTS + ["--bfbs-filenames", str(samples_path)],
|
|
|
|
schema=samples_schema,
|
|
|
|
cwd=samples_path,
|
|
|
|
)
|
|
|
|
|
|
|
|
# Reflection
|
2022-02-10 19:10:47 +00:00
|
|
|
|
2022-02-03 06:42:26 +00:00
|
|
|
# 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:
|
2022-03-30 23:43:22 +00:00
|
|
|
# C++ Reflection
|
|
|
|
flatc_reflection(
|
|
|
|
["-c", "--cpp-std", "c++0x"], "include/flatbuffers", "reflection_generated.h"
|
|
|
|
)
|
2022-02-10 19:10:47 +00:00
|
|
|
|
|
|
|
# Python Reflection
|
2022-02-15 16:48:42 +00:00
|
|
|
flatc_reflection(["-p"], "python/flatbuffers", "reflection")
|
2022-03-30 23:43:22 +00:00
|
|
|
|
2023-03-03 19:14:07 +00:00
|
|
|
# Java Reflection
|
|
|
|
flatc_reflection(
|
|
|
|
["-j", "--java-package-prefix", "com.google.flatbuffers"],
|
2023-05-05 19:08:09 +00:00
|
|
|
"java/src/main/java",
|
|
|
|
"com/google/flatbuffers/reflection",
|
2023-03-03 19:14:07 +00:00
|
|
|
)
|
|
|
|
|
2022-03-30 23:43:22 +00:00
|
|
|
# Annotation
|
|
|
|
|
|
|
|
|
|
|
|
def flatc_annotate(schema, include=None, data=None, cwd=tests_path):
|
|
|
|
cmd = [str(flatc_path)]
|
|
|
|
if include:
|
|
|
|
cmd += ["-I"] + [include]
|
|
|
|
cmd += ["--annotate", schema]
|
|
|
|
if data:
|
|
|
|
cmd += [data] if isinstance(data, str) else data
|
|
|
|
subprocess.run(cmd, cwd=str(cwd), check=True)
|
|
|
|
|
|
|
|
|
|
|
|
flatc_annotate(
|
|
|
|
schema="monster_test.fbs", include="include_test", data="monsterdata_test.mon"
|
|
|
|
)
|
2022-08-17 06:44:50 +00:00
|
|
|
|
|
|
|
# Run the generate_grpc_examples script
|
|
|
|
generate_grpc_examples.GenerateGRPCExamples()
|