gfx/angle/src/commit_id.py
author Sebastian Kaspari <s.kaspari@gmail.com>
Tue, 27 Oct 2015 10:47:03 +0100
changeset 307700 ee8a828b497498c8a4325e3007197c75af931c3b
parent 206337 26a02411f50b9892b74530e74cc3d1b06c22f3fe
child 381930 db6d6ef366eae53617cc63577fd48b03cdbced4e
permissions -rw-r--r--
Bug 1182918 - Tab Queue: Add telemetry for double tap action. r=mfinkle, a=sylvestre

import subprocess as sp
import sys
import os

# Usage: commit_id.py check <angle_dir> (checks if git is present)
# Usage: commit_id.py gen <angle_dir> <file_to_write> (generates commit id)

def grab_output(command, cwd):
    return sp.Popen(command, stdout=sp.PIPE, shell=True, cwd=cwd).communicate()[0].strip()

operation = sys.argv[1]
cwd = sys.argv[2]

if operation == 'check':
    index_path = os.path.join(cwd, '.git', 'index')
    if os.path.exists(index_path):
        print("1")
    else:
        print("0")
    sys.exit(0)

output_file = sys.argv[3]
commit_id_size = 12

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:
    commit_id = 'invalid-hash'
    commit_date = 'invalid-date'

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.close()