• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/env python
2#  Copyright 2018 The ANGLE Project Authors. All rights reserved.
3#  Use of this source code is governed by a BSD-style license that can be
4#  found in the LICENSE file.
5
6# Generate commit.h with git commit hash.
7#
8
9import subprocess as sp
10import sys
11import os
12
13usage = """\
14Usage: commit_id.py check                - check if git is present
15       commit_id.py gen <file_to_write>  - generate commit.h"""
16
17
18def grab_output(command, cwd):
19    return sp.Popen(command, stdout=sp.PIPE, shell=True, cwd=cwd).communicate()[0].strip()
20
21
22if len(sys.argv) < 2:
23    sys.exit(usage)
24
25operation = sys.argv[1]
26
27# Set the root of ANGLE's repo as the working directory
28cwd = os.path.join(os.path.dirname(os.path.realpath(__file__)), '..')
29
30git_dir_exists = os.path.exists(os.path.join(cwd, '.git', 'HEAD'))
31
32if operation == 'check':
33    if git_dir_exists:
34        print("1")
35    else:
36        print("0")
37    sys.exit(0)
38
39if len(sys.argv) < 3 or operation != 'gen':
40    sys.exit(usage)
41
42output_file = sys.argv[2]
43commit_id_size = 12
44commit_id = 'unknown hash'
45commit_date = 'unknown date'
46enable_binary_loading = False
47
48if git_dir_exists:
49    try:
50        commit_id = grab_output('git rev-parse --short=%d HEAD' % commit_id_size, cwd)
51        commit_date = grab_output('git show -s --format=%ci HEAD', cwd)
52        enable_binary_loading = True
53    except:
54        pass
55
56hfile = open(output_file, 'w')
57
58hfile.write('#define ANGLE_COMMIT_HASH "%s"\n' % commit_id)
59hfile.write('#define ANGLE_COMMIT_HASH_SIZE %d\n' % commit_id_size)
60hfile.write('#define ANGLE_COMMIT_DATE "%s"\n' % commit_date)
61
62if not enable_binary_loading:
63    hfile.write('#define ANGLE_DISABLE_PROGRAM_BINARY_LOAD\n')
64
65hfile.close()
66