xref: /aosp_15_r20/external/flatbuffers/scripts/generate_grpc_examples.py (revision 890232f25432b36107d06881e0a25aaa6b473652)
1#!/usr/bin/env python3
2#
3# Copyright 2022 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
17from util import flatc, root_path
18from pathlib import Path
19
20grpc_examples_path = Path(root_path, "grpc/examples")
21
22greeter_schema = Path(grpc_examples_path, "greeter.fbs")
23
24COMMON_ARGS = [
25    "--grpc",
26    "--bfbs-filenames",
27    str(grpc_examples_path),
28]
29
30def GenerateGRPCExamples():
31
32    flatc(
33        COMMON_ARGS
34        + [
35            "--go",
36        ],
37        schema=greeter_schema,
38        cwd=Path(grpc_examples_path, "go/greeter"),
39    )
40
41    flatc(
42        COMMON_ARGS
43        + [
44            "--python",
45        ],
46        schema=greeter_schema,
47        cwd=Path(grpc_examples_path, "python/greeter"),
48    )
49
50    flatc(
51        COMMON_ARGS
52        + [
53            "--swift",
54            "--gen-json-emit",
55        ],
56        schema=greeter_schema,
57        cwd=Path(grpc_examples_path, "swift/Greeter/Sources/Model"),
58    )
59
60    flatc(
61        COMMON_ARGS
62        + [
63            "--ts",
64        ],
65        schema=greeter_schema,
66        cwd=Path(grpc_examples_path, "ts/greeter/src"),
67    )
68
69if __name__ == "__main__":
70    GenerateGRPCExamples()
71