Hash :
ba8ef68c
Author :
Date :
2020-02-24T14:13:40
Always use commit_id.py to generate commit.h commit_id_.py is capable of generating the default commit.h. This makes it so we always take a single path in gn. Remove the existing commit.h and generate it into the root generation folder (not the id subfolder) because Android blueprints can't handle generating into subfolders that don't exist. Make the <angle_dir> argument capable of taking a filename or directory name. This allows us to pass the .git/HEAD file which is a gn input. Android blueprints require all paths used as input or output to a script are listed as inputs or outputs in the genrule. BUG=angleproject:2344 Change-Id: I6600083fc400faf07808316c4a6244d6599df79a Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/2074924 Commit-Queue: Geoff Lang <geofflang@chromium.org> Reviewed-by: Jamie Madill <jmadill@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
#!/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 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()
if len(sys.argv) < 2:
sys.exit(usage)
operation = sys.argv[1]
cwd = os.path.join(os.path.dirname(os.path.realpath(__file__)), '..')
if operation == 'check':
try:
# Try a git command to verify the cwd is valid and we can use the 'gen command'
grab_output('git status', cwd)
print("1")
except:
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'
additional_defines = []
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)
except:
additional_defines.append('#define ANGLE_DISABLE_PROGRAM_BINARY_LOAD')
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)
for additional_define in additional_defines:
hfile.write(additional_define + '\n')
hfile.close()