1 # Copyright (C) 2019 The Android Open Source Project 2 # 3 # Licensed under the Apache License, Version 2.0 (the "License"); 4 # you may not use this file except in compliance with the License. 5 # You may obtain a copy of the License at 6 # 7 # http://www.apache.org/licenses/LICENSE-2.0 8 # 9 # Unless required by applicable law or agreed to in writing, software 10 # distributed under the License is distributed on an "AS IS" BASIS, 11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 # See the License for the specific language governing permissions and 13 # limitations under the License. 14 15 import os 16 import subprocess 17 import sys 18 19 def main(argv): 20 if len(argv) != 2: 21 print 'Usage: %s output_file.h' 22 return 1 23 revision = subprocess.check_output(['git', 'rev-parse', 'HEAD']).strip() 24 new_contents = '#define PERFETTO_GET_GIT_REVISION() "%s"\n' % revision 25 out_file = argv[1] 26 old_contents = '' 27 if os.path.isfile(out_file): 28 with open(out_file) as f: 29 old_contents = f.read() 30 if old_contents == new_contents: 31 return 0 32 with open(out_file, 'w') as f: 33 f.write(new_contents) 34 return 0 35 36 if __name__ == '__main__': 37 sys.exit(main(sys.argv)) 38