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