Hash :
d3c8d543
Author :
Date :
2021-04-08T14:03:51
Consider AOSP ANGLE path as well during SHA generation Account for an in-tree AOSP build of ANGLE while generating ANGLE commit SHA Bug: angleproject:5838 Change-Id: I81d6d821810544c35daf6af9b167f18a4b095e99 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/2815241 Commit-Queue: Mohan Maiya <m.maiya@samsung.com> Reviewed-by: Tim Van Patten <timvp@google.com> Reviewed-by: Geoff Lang <geofflang@chromium.org>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83
#!/usr/bin/env python
# Copyright 2018 The ANGLE Project Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
# Generate commit.h with git commit hash.
#
import subprocess as sp
import sys
import os
usage = """\
Usage: commit_id.py check - check if git is present
commit_id.py position - print commit position
commit_id.py gen <file_to_write> - generate commit.h"""
def grab_output(command, cwd):
return sp.Popen(
command, stdout=sp.PIPE, shell=True, cwd=cwd).communicate()[0].strip().decode('utf-8')
def get_commit_position(cwd):
return grab_output('git rev-list HEAD --count', cwd)
if len(sys.argv) < 2:
sys.exit(usage)
operation = sys.argv[1]
# Set the root of ANGLE's repo as the working directory
cwd = os.path.join(os.path.dirname(os.path.realpath(__file__)), '..')
aosp_angle_path = os.path.join(os.path.dirname('.'), 'external', 'angle')
if os.path.exists(aosp_angle_path):
cwd = aosp_angle_path
git_dir_exists = os.path.exists(os.path.join(cwd, '.git', 'HEAD'))
if operation == 'check':
if git_dir_exists:
print("1")
else:
print("0")
sys.exit(0)
elif operation == 'position':
if git_dir_exists:
print(get_commit_position(cwd))
else:
print("0")
sys.exit(0)
if len(sys.argv) < 3 or operation != 'gen':
sys.exit(usage)
output_file = sys.argv[2]
commit_id_size = 12
commit_id = 'unknown hash'
commit_date = 'unknown date'
commit_position = '0'
enable_binary_loading = False
if git_dir_exists:
try:
commit_id = grab_output('git rev-parse --short=%d HEAD' % commit_id_size, cwd)
commit_date = grab_output('git show -s --format=%ci HEAD', cwd)
commit_position = get_commit_position(cwd)
enable_binary_loading = True
except:
pass
hfile = open(output_file, 'w')
hfile.write('#define ANGLE_COMMIT_HASH "%s"\n' % commit_id)
hfile.write('#define ANGLE_COMMIT_HASH_SIZE %d\n' % commit_id_size)
hfile.write('#define ANGLE_COMMIT_DATE "%s"\n' % commit_date)
hfile.write('#define ANGLE_COMMIT_POSITION %s\n' % commit_position)
if not enable_binary_loading:
hfile.write('#define ANGLE_DISABLE_PROGRAM_BINARY_LOAD\n')
hfile.close()