1#!/usr/bin/env python3 2# 3# Copyright 2021 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 17import platform 18import subprocess 19import sys 20from 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. 24script_path = Path(__file__).parent.resolve() 25 26# Get the root path as an absolute path, so all derived paths are absolute. 27root_path = script_path.parent.absolute() 28 29result = subprocess.run(["git", "diff", "--quiet"], cwd=root_path) 30 31if result.returncode != 0: 32 print( 33 "\n" 34 "ERROR: *********************************************************\n" 35 "ERROR: * The following differences were found after building. *\n" 36 "ERROR: * Perhaps there is a difference in the flags for the. *\n" 37 "ERROR: * CMakeLists.txt vs the script/generate_code.py script? *\n" 38 "ERROR: *********************************************************\n" 39 ) 40 subprocess.run(["git", "diff", "--binary", "--exit-code"], cwd=root_path) 41 sys.exit(result.returncode) 42 43# Rung the generate_code.py script, forwarding arguments 44gen_cmd = ["scripts/generate_code.py"] + sys.argv[1:] 45if platform.system() == "Windows": 46 gen_cmd = ["py"] + gen_cmd 47subprocess.run(gen_cmd, cwd=root_path) 48 49result = subprocess.run(["git", "diff", "--quiet"], cwd=root_path) 50 51if result.returncode != 0: 52 print( 53 "\n" 54 "ERROR: ********************************************************\n" 55 "ERROR: * The following differences were found after running *\n" 56 "ERROR: * the script/generate_code.py script. Maybe you forgot *\n" 57 "ERROR: * to run it after making changes in a generator? *\n" 58 "ERROR: ********************************************************\n" 59 ) 60 subprocess.run(["git", "diff", "--binary", "--exit-code"], cwd=root_path) 61 sys.exit(result.returncode) 62 63sys.exit(0) 64