mirror of
https://github.com/google/flatbuffers.git
synced 2026-06-03 12:21:23 +00:00
bulk code format fix (#8707)
This commit is contained in:
@@ -14,10 +14,10 @@
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
from pathlib import Path
|
||||
import subprocess
|
||||
import sys
|
||||
import generate_grpc_examples
|
||||
from pathlib import Path
|
||||
|
||||
# Get the path where this script is located so we can invoke the script from
|
||||
# any directory and have the paths work correctly.
|
||||
@@ -29,17 +29,19 @@ root_path = script_path.parent.absolute()
|
||||
print("Generating GRPC code...")
|
||||
generate_grpc_examples.GenerateGRPCExamples()
|
||||
|
||||
result = subprocess.run(["git", "diff", "--quiet", "--ignore-cr-at-eol"], cwd=root_path)
|
||||
result = subprocess.run(
|
||||
["git", "diff", "--quiet", "--ignore-cr-at-eol"], cwd=root_path
|
||||
)
|
||||
|
||||
if result.returncode != 0:
|
||||
print(
|
||||
"\n"
|
||||
"ERROR: ********************************************************\n"
|
||||
"ERROR: * The following differences were found after running *\n"
|
||||
"ERROR: * the script/generate_grpc_examples.py script. Maybe *\n"
|
||||
"ERROR: * you forgot to run it after making changes in a *\n"
|
||||
"ERROR: * generator or schema? *\n"
|
||||
"ERROR: ********************************************************\n"
|
||||
)
|
||||
subprocess.run(["git", "diff", "--binary", "--exit-code"], cwd=root_path)
|
||||
sys.exit(result.returncode)
|
||||
print(
|
||||
"\n"
|
||||
"ERROR: ********************************************************\n"
|
||||
"ERROR: * The following differences were found after running *\n"
|
||||
"ERROR: * the script/generate_grpc_examples.py script. Maybe *\n"
|
||||
"ERROR: * you forgot to run it after making changes in a *\n"
|
||||
"ERROR: * generator or schema? *\n"
|
||||
"ERROR: ********************************************************\n"
|
||||
)
|
||||
subprocess.run(["git", "diff", "--binary", "--exit-code"], cwd=root_path)
|
||||
sys.exit(result.returncode)
|
||||
|
||||
@@ -14,10 +14,10 @@
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
from pathlib import Path
|
||||
import platform
|
||||
import subprocess
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
# Get the path where this script is located so we can invoke the script from
|
||||
# any directory and have the paths work correctly.
|
||||
@@ -26,38 +26,42 @@ script_path = Path(__file__).parent.resolve()
|
||||
# Get the root path as an absolute path, so all derived paths are absolute.
|
||||
root_path = script_path.parent.absolute()
|
||||
|
||||
result = subprocess.run(["git", "diff", "--quiet", "--ignore-cr-at-eol"], cwd=root_path)
|
||||
result = subprocess.run(
|
||||
["git", "diff", "--quiet", "--ignore-cr-at-eol"], cwd=root_path
|
||||
)
|
||||
|
||||
if result.returncode != 0:
|
||||
print(
|
||||
"\n"
|
||||
"ERROR: *********************************************************\n"
|
||||
"ERROR: * The following differences were found after building. *\n"
|
||||
"ERROR: * Perhaps there is a difference in the flags for the. *\n"
|
||||
"ERROR: * CMakeLists.txt vs the script/generate_code.py script? *\n"
|
||||
"ERROR: *********************************************************\n"
|
||||
)
|
||||
subprocess.run(["git", "diff", "--binary", "--exit-code"], cwd=root_path)
|
||||
sys.exit(result.returncode)
|
||||
print(
|
||||
"\n"
|
||||
"ERROR: *********************************************************\n"
|
||||
"ERROR: * The following differences were found after building. *\n"
|
||||
"ERROR: * Perhaps there is a difference in the flags for the. *\n"
|
||||
"ERROR: * CMakeLists.txt vs the script/generate_code.py script? *\n"
|
||||
"ERROR: *********************************************************\n"
|
||||
)
|
||||
subprocess.run(["git", "diff", "--binary", "--exit-code"], cwd=root_path)
|
||||
sys.exit(result.returncode)
|
||||
|
||||
# Rung the generate_code.py script, forwarding arguments
|
||||
gen_cmd = ["scripts/generate_code.py"] + sys.argv[1:]
|
||||
if platform.system() == "Windows":
|
||||
gen_cmd = ["py"] + gen_cmd
|
||||
gen_cmd = ["py"] + gen_cmd
|
||||
subprocess.run(gen_cmd, cwd=root_path)
|
||||
|
||||
result = subprocess.run(["git", "diff", "--quiet", "--ignore-cr-at-eol"], cwd=root_path)
|
||||
result = subprocess.run(
|
||||
["git", "diff", "--quiet", "--ignore-cr-at-eol"], cwd=root_path
|
||||
)
|
||||
|
||||
if result.returncode != 0:
|
||||
print(
|
||||
"\n"
|
||||
"ERROR: ********************************************************\n"
|
||||
"ERROR: * The following differences were found after running *\n"
|
||||
"ERROR: * the script/generate_code.py script. Maybe you forgot *\n"
|
||||
"ERROR: * to run it after making changes in a generator? *\n"
|
||||
"ERROR: ********************************************************\n"
|
||||
)
|
||||
subprocess.run(["git", "diff", "--binary", "--exit-code"], cwd=root_path)
|
||||
sys.exit(result.returncode)
|
||||
print(
|
||||
"\n"
|
||||
"ERROR: ********************************************************\n"
|
||||
"ERROR: * The following differences were found after running *\n"
|
||||
"ERROR: * the script/generate_code.py script. Maybe you forgot *\n"
|
||||
"ERROR: * to run it after making changes in a generator? *\n"
|
||||
"ERROR: ********************************************************\n"
|
||||
)
|
||||
subprocess.run(["git", "diff", "--binary", "--exit-code"], cwd=root_path)
|
||||
sys.exit(result.returncode)
|
||||
|
||||
sys.exit(0)
|
||||
|
||||
@@ -16,11 +16,11 @@
|
||||
|
||||
import filecmp
|
||||
import glob
|
||||
from pathlib import Path
|
||||
import shutil
|
||||
import subprocess
|
||||
import generate_grpc_examples
|
||||
from pathlib import Path
|
||||
from util import flatc, root_path, tests_path, args, flatc_path
|
||||
from util import args, flatc, flatc_path, root_path, tests_path
|
||||
|
||||
# Specify the other paths that will be referenced
|
||||
swift_code_gen = Path(root_path, "tests/swift/fuzzer/CodeGenerationTests")
|
||||
@@ -31,33 +31,33 @@ reflection_path = Path(root_path, "reflection")
|
||||
|
||||
# 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)):
|
||||
shutil.rmtree(str(original_reflection_path), ignore_errors=True)
|
||||
shutil.move(str(new_reflection_path), str(original_reflection_path))
|
||||
shutil.rmtree(str(Path(reflection_path, temp_dir)))
|
||||
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)):
|
||||
shutil.rmtree(str(original_reflection_path), ignore_errors=True)
|
||||
shutil.move(str(new_reflection_path), str(original_reflection_path))
|
||||
shutil.rmtree(str(Path(reflection_path, temp_dir)))
|
||||
|
||||
|
||||
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)
|
||||
cmd = [str(flatc_path)]
|
||||
if include:
|
||||
cmd += ["-I"] + [include]
|
||||
cmd += ["--annotate", schema, file]
|
||||
result = subprocess.run(cmd, cwd=str(cwd), check=True)
|
||||
|
||||
|
||||
# Glob a pattern relative to file path
|
||||
def glob(path, pattern):
|
||||
return [str(p) for p in path.glob(pattern)]
|
||||
return [str(p) for p in path.glob(pattern)]
|
||||
|
||||
|
||||
# flatc options that are shared
|
||||
@@ -169,7 +169,9 @@ flatc(
|
||||
# Also generate a suffix variant exercising the callback API to keep prior
|
||||
# *_generated naming convention in sync with new callback additions.
|
||||
flatc(
|
||||
NO_INCL_OPTS + CPP_OPTS + ["--grpc", "--grpc-callback-api", "--filename-suffix", "_generated"],
|
||||
NO_INCL_OPTS
|
||||
+ CPP_OPTS
|
||||
+ ["--grpc", "--grpc-callback-api", "--filename-suffix", "_generated"],
|
||||
schema="monster_test.fbs",
|
||||
include="include_test",
|
||||
)
|
||||
@@ -300,7 +302,9 @@ flatc_annotate(
|
||||
)
|
||||
|
||||
flatc_annotate(
|
||||
schema="monster_test.fbs", file="monsterdata_test.mon", include="include_test"
|
||||
schema="monster_test.fbs",
|
||||
file="monsterdata_test.mon",
|
||||
include="include_test",
|
||||
)
|
||||
|
||||
flatc(
|
||||
@@ -330,19 +334,23 @@ flatc(
|
||||
)
|
||||
|
||||
if not args.skip_monster_extra:
|
||||
flatc(
|
||||
CPP_OPTS + CS_OPTS + NO_INCL_OPTS + JAVA_OPTS + KOTLIN_OPTS + PYTHON_OPTS,
|
||||
schema="monster_extra.fbs",
|
||||
data="monsterdata_extra.json",
|
||||
)
|
||||
flatc(
|
||||
CPP_OPTS + CS_OPTS + NO_INCL_OPTS + JAVA_OPTS + KOTLIN_OPTS + PYTHON_OPTS,
|
||||
schema="monster_extra.fbs",
|
||||
data="monsterdata_extra.json",
|
||||
)
|
||||
|
||||
flatc(
|
||||
DART_OPTS + ["--gen-object-api"],
|
||||
schema="monster_extra.fbs",
|
||||
)
|
||||
flatc(
|
||||
DART_OPTS + ["--gen-object-api"],
|
||||
schema="monster_extra.fbs",
|
||||
)
|
||||
|
||||
flatc(
|
||||
CPP_OPTS + CS_OPTS + NO_INCL_OPTS + JAVA_OPTS + ["--jsonschema", "--scoped-enums"],
|
||||
CPP_OPTS
|
||||
+ CS_OPTS
|
||||
+ NO_INCL_OPTS
|
||||
+ JAVA_OPTS
|
||||
+ ["--jsonschema", "--scoped-enums"],
|
||||
schema="arrays_test.fbs",
|
||||
)
|
||||
|
||||
@@ -352,7 +360,13 @@ flatc(
|
||||
)
|
||||
|
||||
flatc(
|
||||
["--cpp", "--gen-mutable", "--gen-compare", "--gen-object-api", "--reflect-names"],
|
||||
[
|
||||
"--cpp",
|
||||
"--gen-mutable",
|
||||
"--gen-compare",
|
||||
"--gen-object-api",
|
||||
"--reflect-names",
|
||||
],
|
||||
schema="native_inline_table_test.fbs",
|
||||
)
|
||||
|
||||
@@ -385,7 +399,9 @@ optional_scalars_schema = "optional_scalars.fbs"
|
||||
flatc(["--java", "--kotlin", "--lobster"], schema=optional_scalars_schema)
|
||||
flatc(TS_OPTS, cwd=ts_code_gen, schema="../optional_scalars.fbs")
|
||||
|
||||
flatc(["--csharp", "--python", "--gen-object-api"], schema=optional_scalars_schema)
|
||||
flatc(
|
||||
["--csharp", "--python", "--gen-object-api"], schema=optional_scalars_schema
|
||||
)
|
||||
|
||||
flatc(RUST_OPTS, prefix="optional_scalars", schema=optional_scalars_schema)
|
||||
|
||||
@@ -534,8 +550,14 @@ flatc(
|
||||
|
||||
# Sample files
|
||||
samples_schema = "monster.fbs"
|
||||
flatc(BASE_OPTS + CPP_OPTS + LOBSTER_OPTS + SWIFT_OPTS, schema=samples_schema, cwd=samples_path)
|
||||
flatc(RUST_OPTS, prefix="rust_generated", schema=samples_schema, cwd=samples_path)
|
||||
flatc(
|
||||
BASE_OPTS + CPP_OPTS + LOBSTER_OPTS + SWIFT_OPTS,
|
||||
schema=samples_schema,
|
||||
cwd=samples_path,
|
||||
)
|
||||
flatc(
|
||||
RUST_OPTS, prefix="rust_generated", schema=samples_schema, cwd=samples_path
|
||||
)
|
||||
flatc(
|
||||
BINARY_OPTS + ["--bfbs-filenames", str(samples_path)],
|
||||
schema=samples_schema,
|
||||
@@ -547,10 +569,12 @@ flatc(
|
||||
# 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:
|
||||
# C++ Reflection
|
||||
flatc_reflection(
|
||||
["-c", "--cpp-std", "c++0x"], "include/flatbuffers", "reflection_generated.h"
|
||||
)
|
||||
# C++ Reflection
|
||||
flatc_reflection(
|
||||
["-c", "--cpp-std", "c++0x"],
|
||||
"include/flatbuffers",
|
||||
"reflection_generated.h",
|
||||
)
|
||||
|
||||
# Python Reflection
|
||||
flatc_reflection(["-p"], "python/flatbuffers", "reflection")
|
||||
@@ -566,17 +590,19 @@ flatc_reflection(
|
||||
|
||||
|
||||
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)
|
||||
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"
|
||||
schema="monster_test.fbs",
|
||||
include="include_test",
|
||||
data="monsterdata_test.mon",
|
||||
)
|
||||
|
||||
# Run the generate_grpc_examples script
|
||||
|
||||
@@ -14,8 +14,8 @@
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
from util import flatc, root_path
|
||||
from pathlib import Path
|
||||
from util import flatc, root_path
|
||||
|
||||
grpc_examples_path = Path(root_path, "grpc/examples")
|
||||
|
||||
@@ -27,44 +27,46 @@ COMMON_ARGS = [
|
||||
str(grpc_examples_path),
|
||||
]
|
||||
|
||||
|
||||
def GenerateGRPCExamples():
|
||||
|
||||
flatc(
|
||||
COMMON_ARGS
|
||||
+ [
|
||||
"--go",
|
||||
],
|
||||
schema=greeter_schema,
|
||||
cwd=Path(grpc_examples_path, "go/greeter"),
|
||||
)
|
||||
flatc(
|
||||
COMMON_ARGS
|
||||
+ [
|
||||
"--go",
|
||||
],
|
||||
schema=greeter_schema,
|
||||
cwd=Path(grpc_examples_path, "go/greeter"),
|
||||
)
|
||||
|
||||
flatc(
|
||||
COMMON_ARGS
|
||||
+ [
|
||||
"--python",
|
||||
],
|
||||
schema=greeter_schema,
|
||||
cwd=Path(grpc_examples_path, "python/greeter"),
|
||||
)
|
||||
flatc(
|
||||
COMMON_ARGS
|
||||
+ [
|
||||
"--python",
|
||||
],
|
||||
schema=greeter_schema,
|
||||
cwd=Path(grpc_examples_path, "python/greeter"),
|
||||
)
|
||||
|
||||
flatc(
|
||||
COMMON_ARGS
|
||||
+ [
|
||||
"--swift",
|
||||
"--gen-json-emit",
|
||||
],
|
||||
schema=greeter_schema,
|
||||
cwd=Path(grpc_examples_path, "swift/Greeter/Sources/Model"),
|
||||
)
|
||||
flatc(
|
||||
COMMON_ARGS
|
||||
+ [
|
||||
"--swift",
|
||||
"--gen-json-emit",
|
||||
],
|
||||
schema=greeter_schema,
|
||||
cwd=Path(grpc_examples_path, "swift/Greeter/Sources/Model"),
|
||||
)
|
||||
|
||||
flatc(
|
||||
COMMON_ARGS
|
||||
+ [
|
||||
"--ts",
|
||||
],
|
||||
schema=greeter_schema,
|
||||
cwd=Path(grpc_examples_path, "ts/greeter/src"),
|
||||
)
|
||||
|
||||
flatc(
|
||||
COMMON_ARGS
|
||||
+ [
|
||||
"--ts",
|
||||
],
|
||||
schema=greeter_schema,
|
||||
cwd=Path(grpc_examples_path, "ts/greeter/src"),
|
||||
)
|
||||
|
||||
if __name__ == "__main__":
|
||||
GenerateGRPCExamples()
|
||||
GenerateGRPCExamples()
|
||||
|
||||
@@ -13,9 +13,9 @@
|
||||
# limitations under the License.
|
||||
|
||||
import argparse
|
||||
from pathlib import Path
|
||||
import platform
|
||||
import subprocess
|
||||
from pathlib import Path
|
||||
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument(
|
||||
@@ -53,18 +53,21 @@ flatc_exe = Path(
|
||||
|
||||
# Find and assert flatc compiler is present.
|
||||
if root_path in flatc_exe.parents:
|
||||
flatc_exe = flatc_exe.relative_to(root_path)
|
||||
flatc_exe = flatc_exe.relative_to(root_path)
|
||||
flatc_path = Path(root_path, flatc_exe)
|
||||
assert flatc_path.exists(), "Cannot find the flatc compiler " + str(flatc_path)
|
||||
|
||||
|
||||
# Execute the flatc compiler with the specified parameters
|
||||
def flatc(options, schema, prefix=None, include=None, data=None, cwd=tests_path):
|
||||
cmd = [str(flatc_path)] + options
|
||||
if prefix:
|
||||
cmd += ["-o"] + [prefix]
|
||||
if include:
|
||||
cmd += ["-I"] + [include]
|
||||
cmd += [schema] if isinstance(schema, str) else schema
|
||||
if data:
|
||||
cmd += [data] if isinstance(data, str) else data
|
||||
result = subprocess.run(cmd, cwd=str(cwd), check=True)
|
||||
def flatc(
|
||||
options, schema, prefix=None, include=None, data=None, cwd=tests_path
|
||||
):
|
||||
cmd = [str(flatc_path)] + options
|
||||
if prefix:
|
||||
cmd += ["-o"] + [prefix]
|
||||
if include:
|
||||
cmd += ["-I"] + [include]
|
||||
cmd += [schema] if isinstance(schema, str) else schema
|
||||
if data:
|
||||
cmd += [data] if isinstance(data, str) else data
|
||||
result = subprocess.run(cmd, cwd=str(cwd), check=True)
|
||||
|
||||
Reference in New Issue
Block a user