mirror of
https://github.com/google/flatbuffers.git
synced 2026-06-27 18:58:06 +00:00
Remove old GRPC bash script and convert to python3 (#7454)
* Remove old GRPC bash script and convert to python3 * updated checking gRPC script to python3
This commit is contained in:
2
.github/workflows/build.yml
vendored
2
.github/workflows/build.yml
vendored
@@ -275,7 +275,7 @@ jobs:
|
|||||||
- name: Generate
|
- name: Generate
|
||||||
run: scripts/check_generate_code.py
|
run: scripts/check_generate_code.py
|
||||||
- name: Generate gRPC
|
- name: Generate gRPC
|
||||||
run: bash scripts/check-grpc-generated-code.sh
|
run: scripts/check-grpc-generated-code.py
|
||||||
|
|
||||||
build-benchmarks:
|
build-benchmarks:
|
||||||
name: Build Benchmarks (on Linux)
|
name: Build Benchmarks (on Linux)
|
||||||
|
|||||||
@@ -1,71 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
#
|
|
||||||
# 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.
|
|
||||||
|
|
||||||
set -e
|
|
||||||
|
|
||||||
current_dir=`pwd`
|
|
||||||
|
|
||||||
cd ../..
|
|
||||||
|
|
||||||
main_dir=`pwd`
|
|
||||||
|
|
||||||
cd ${current_dir}
|
|
||||||
|
|
||||||
# Looks for flatc within the root dir & debug
|
|
||||||
if [ -e ${main_dir}/flatc ]; then
|
|
||||||
alias fbc='${main_dir}/flatc'
|
|
||||||
elif [ -e ${main_dir}/Debug/flatc ]; then
|
|
||||||
alias fbc='${main_dir}/Debug/flatc'
|
|
||||||
else
|
|
||||||
echo 'flatc' could not be found. Make sure to build FlatBuffers from the \
|
|
||||||
$rootdir directory.
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
generator="--grpc $current_dir/greeter.fbs"
|
|
||||||
|
|
||||||
# Regenerate Go lang code
|
|
||||||
cd go
|
|
||||||
|
|
||||||
cd greeter
|
|
||||||
fbc --bfbs-filenames ../.. --go ${generator}
|
|
||||||
|
|
||||||
cd ${current_dir}
|
|
||||||
|
|
||||||
# Regenerate Python code
|
|
||||||
cd python
|
|
||||||
|
|
||||||
cd greeter
|
|
||||||
|
|
||||||
fbc --bfbs-filenames ../.. --python ${generator}
|
|
||||||
|
|
||||||
cd ${current_dir}
|
|
||||||
|
|
||||||
# Regenerate Swift code
|
|
||||||
cd swift
|
|
||||||
|
|
||||||
cd Greeter/Sources/Model
|
|
||||||
fbc --bfbs-filenames ../../../.. --swift --gen-json-emit ${generator}
|
|
||||||
|
|
||||||
cd ${current_dir}
|
|
||||||
|
|
||||||
# Regenerate Typescript code
|
|
||||||
cd ts
|
|
||||||
|
|
||||||
cd greeter/src
|
|
||||||
fbc --bfbs-filenames ../../.. --ts ${generator}
|
|
||||||
|
|
||||||
cd ${current_dir}
|
|
||||||
4
grpc/examples/ts/greeter/src/greeter_generated.ts
Normal file
4
grpc/examples/ts/greeter/src/greeter_generated.ts
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
// automatically generated by the FlatBuffers compiler, do not modify
|
||||||
|
|
||||||
|
export { HelloReply } from './models/hello-reply';
|
||||||
|
export { HelloRequest } from './models/hello-request';
|
||||||
45
scripts/check-grpc-generated-code.py
Executable file
45
scripts/check-grpc-generated-code.py
Executable file
@@ -0,0 +1,45 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
#
|
||||||
|
# Copyright 2022 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 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.
|
||||||
|
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()
|
||||||
|
|
||||||
|
print("Generating GRPC code...")
|
||||||
|
generate_grpc_examples.GenerateGRPCExamples()
|
||||||
|
|
||||||
|
result = subprocess.run(["git", "diff", "--quiet"], 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)
|
||||||
@@ -1,32 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
#
|
|
||||||
# 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.
|
|
||||||
set -e
|
|
||||||
|
|
||||||
echo "Checks generated grpc code"
|
|
||||||
cd grpc/examples
|
|
||||||
sh generate.sh
|
|
||||||
cd ..
|
|
||||||
|
|
||||||
if ! git diff --quiet; then
|
|
||||||
echo >&2
|
|
||||||
echo "ERROR: ********************************************************" >&2
|
|
||||||
echo "ERROR: The following differences were found after running the" >&2
|
|
||||||
echo "ERROR: grpc/example/generate.sh script. Maybe you forgot to run" >&2
|
|
||||||
echo "ERROR: it after making changes in a generator or schema?" >&2
|
|
||||||
echo "ERROR: ********************************************************" >&2
|
|
||||||
echo >&2
|
|
||||||
git diff --binary --exit-code
|
|
||||||
fi
|
|
||||||
@@ -20,6 +20,7 @@ import glob
|
|||||||
import platform
|
import platform
|
||||||
import shutil
|
import shutil
|
||||||
import subprocess
|
import subprocess
|
||||||
|
import generate_grpc_examples
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
parser = argparse.ArgumentParser()
|
parser = argparse.ArgumentParser()
|
||||||
@@ -514,3 +515,6 @@ def flatc_annotate(schema, include=None, data=None, cwd=tests_path):
|
|||||||
flatc_annotate(
|
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
|
||||||
|
generate_grpc_examples.GenerateGRPCExamples()
|
||||||
|
|||||||
70
scripts/generate_grpc_examples.py
Executable file
70
scripts/generate_grpc_examples.py
Executable file
@@ -0,0 +1,70 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
#
|
||||||
|
# Copyright 2022 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.
|
||||||
|
|
||||||
|
from util import flatc, root_path
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
grpc_examples_path = Path(root_path, "grpc/examples")
|
||||||
|
|
||||||
|
greeter_schema = Path(grpc_examples_path, "greeter.fbs")
|
||||||
|
|
||||||
|
COMMON_ARGS = [
|
||||||
|
"--grpc",
|
||||||
|
"--bfbs-filenames",
|
||||||
|
str(grpc_examples_path),
|
||||||
|
]
|
||||||
|
|
||||||
|
def GenerateGRPCExamples():
|
||||||
|
|
||||||
|
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
|
||||||
|
+ [
|
||||||
|
"--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"),
|
||||||
|
)
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
GenerateGRPCExamples()
|
||||||
51
scripts/util.py
Normal file
51
scripts/util.py
Normal file
@@ -0,0 +1,51 @@
|
|||||||
|
# Copyright 2022 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 platform
|
||||||
|
import subprocess
|
||||||
|
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.
|
||||||
|
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()
|
||||||
|
|
||||||
|
# Get the location of the flatc executable, reading from the first command line
|
||||||
|
# argument or defaulting to default names.
|
||||||
|
flatc_exe = Path("flatc" if not platform.system() == "Windows" else "flatc.exe")
|
||||||
|
|
||||||
|
# Find and assert flatc compiler is present.
|
||||||
|
if root_path in flatc_exe.parents:
|
||||||
|
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=root_path):
|
||||||
|
cmd = [str(flatc_path)] + options
|
||||||
|
if prefix:
|
||||||
|
cmd += ["-o"] + [prefix]
|
||||||
|
if include:
|
||||||
|
cmd += ["-I"] + [include]
|
||||||
|
if isinstance(schema, Path):
|
||||||
|
cmd += [str(schema)]
|
||||||
|
elif isinstance(schema, str):
|
||||||
|
cmd += [schema]
|
||||||
|
else:
|
||||||
|
cmd += schema
|
||||||
|
if data:
|
||||||
|
cmd += [data] if isinstance(data, str) else data
|
||||||
|
return subprocess.check_call(cmd, cwd=str(cwd))
|
||||||
Reference in New Issue
Block a user