普通文本  |  38行  |  1.15 KB

# Copyright (C) 2019 The Android Open Source Project
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import os
import subprocess
import sys

def main(argv):
  if len(argv) != 2:
    print 'Usage: %s output_file.h'
    return 1
  revision = subprocess.check_output(['git', 'rev-parse', 'HEAD']).strip()
  new_contents = '#define PERFETTO_GET_GIT_REVISION() "%s"\n' % revision
  out_file = argv[1]
  old_contents = ''
  if os.path.isfile(out_file):
    with open(out_file) as f:
      old_contents = f.read()
  if old_contents == new_contents:
    return 0
  with open(out_file, 'w') as f:
    f.write(new_contents)
  return 0

if __name__ == '__main__':
  sys.exit(main(sys.argv))