Austin Schuh | 2dd86a9 | 2022-09-14 21:19:23 -0700 | [diff] [blame^] | 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 | |
| 17 | import subprocess |
| 18 | import sys |
| 19 | import generate_grpc_examples |
| 20 | from pathlib import Path |
| 21 | |
| 22 | # Get the path where this script is located so we can invoke the script from |
| 23 | # any directory and have the paths work correctly. |
| 24 | script_path = Path(__file__).parent.resolve() |
| 25 | |
| 26 | # Get the root path as an absolute path, so all derived paths are absolute. |
| 27 | root_path = script_path.parent.absolute() |
| 28 | |
| 29 | print("Generating GRPC code...") |
| 30 | generate_grpc_examples.GenerateGRPCExamples() |
| 31 | |
| 32 | result = subprocess.run(["git", "diff", "--quiet"], cwd=root_path) |
| 33 | |
| 34 | if result.returncode != 0: |
| 35 | print( |
| 36 | "\n" |
| 37 | "ERROR: ********************************************************\n" |
| 38 | "ERROR: * The following differences were found after running *\n" |
| 39 | "ERROR: * the script/generate_grpc_examples.py script. Maybe *\n" |
| 40 | "ERROR: * you forgot to run it after making changes in a *\n" |
| 41 | "ERROR: * generator or schema? *\n" |
| 42 | "ERROR: ********************************************************\n" |
| 43 | ) |
| 44 | subprocess.run(["git", "diff", "--binary", "--exit-code"], cwd=root_path) |
| 45 | sys.exit(result.returncode) |