xref: /aosp_15_r20/external/flatbuffers/scripts/check-grpc-generated-code.py (revision 890232f25432b36107d06881e0a25aaa6b473652)
1*890232f2SAndroid Build Coastguard Worker#!/usr/bin/env python3
2*890232f2SAndroid Build Coastguard Worker#
3*890232f2SAndroid Build Coastguard Worker# Copyright 2022 Google Inc. All rights reserved.
4*890232f2SAndroid Build Coastguard Worker#
5*890232f2SAndroid Build Coastguard Worker# Licensed under the Apache License, Version 2.0 (the "License");
6*890232f2SAndroid Build Coastguard Worker# you may not use this file except in compliance with the License.
7*890232f2SAndroid Build Coastguard Worker# You may obtain a copy of the License at
8*890232f2SAndroid Build Coastguard Worker#
9*890232f2SAndroid Build Coastguard Worker#     http://www.apache.org/licenses/LICENSE-2.0
10*890232f2SAndroid Build Coastguard Worker#
11*890232f2SAndroid Build Coastguard Worker# Unless required by applicable law or agreed to in writing, software
12*890232f2SAndroid Build Coastguard Worker# distributed under the License is distributed on an "AS IS" BASIS,
13*890232f2SAndroid Build Coastguard Worker# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14*890232f2SAndroid Build Coastguard Worker# See the License for the specific language governing permissions and
15*890232f2SAndroid Build Coastguard Worker# limitations under the License.
16*890232f2SAndroid Build Coastguard Worker
17*890232f2SAndroid Build Coastguard Workerimport subprocess
18*890232f2SAndroid Build Coastguard Workerimport sys
19*890232f2SAndroid Build Coastguard Workerimport generate_grpc_examples
20*890232f2SAndroid Build Coastguard Workerfrom pathlib import Path
21*890232f2SAndroid Build Coastguard Worker
22*890232f2SAndroid Build Coastguard Worker# Get the path where this script is located so we can invoke the script from
23*890232f2SAndroid Build Coastguard Worker# any directory and have the paths work correctly.
24*890232f2SAndroid Build Coastguard Workerscript_path = Path(__file__).parent.resolve()
25*890232f2SAndroid Build Coastguard Worker
26*890232f2SAndroid Build Coastguard Worker# Get the root path as an absolute path, so all derived paths are absolute.
27*890232f2SAndroid Build Coastguard Workerroot_path = script_path.parent.absolute()
28*890232f2SAndroid Build Coastguard Worker
29*890232f2SAndroid Build Coastguard Workerprint("Generating GRPC code...")
30*890232f2SAndroid Build Coastguard Workergenerate_grpc_examples.GenerateGRPCExamples()
31*890232f2SAndroid Build Coastguard Worker
32*890232f2SAndroid Build Coastguard Workerresult = subprocess.run(["git", "diff", "--quiet"], cwd=root_path)
33*890232f2SAndroid Build Coastguard Worker
34*890232f2SAndroid Build Coastguard Workerif result.returncode != 0:
35*890232f2SAndroid Build Coastguard Worker    print(
36*890232f2SAndroid Build Coastguard Worker        "\n"
37*890232f2SAndroid Build Coastguard Worker        "ERROR: ********************************************************\n"
38*890232f2SAndroid Build Coastguard Worker        "ERROR: * The following differences were found after running   *\n"
39*890232f2SAndroid Build Coastguard Worker        "ERROR: * the script/generate_grpc_examples.py script. Maybe   *\n"
40*890232f2SAndroid Build Coastguard Worker        "ERROR: * you forgot to run it after making changes in a       *\n"
41*890232f2SAndroid Build Coastguard Worker        "ERROR: * generator or schema?                                 *\n"
42*890232f2SAndroid Build Coastguard Worker        "ERROR: ********************************************************\n"
43*890232f2SAndroid Build Coastguard Worker    )
44*890232f2SAndroid Build Coastguard Worker    subprocess.run(["git", "diff", "--binary", "--exit-code"], cwd=root_path)
45*890232f2SAndroid Build Coastguard Worker    sys.exit(result.returncode)
46