Jamie Madill | 42f529e | 2014-02-24 12:45:32 -0500 | [diff] [blame^] | 1 | import subprocess as sp |
| 2 | import sys |
| 3 | |
| 4 | def grab_output(*command): |
| 5 | return sp.Popen(command, stdout=sp.PIPE).communicate()[0].strip() |
| 6 | |
| 7 | commit_id_size = 12 |
| 8 | |
| 9 | try: |
| 10 | commit_id = grab_output('git', 'rev-parse', '--short=%d' % commit_id_size, 'HEAD') |
| 11 | commit_date = grab_output('git', 'show', '-s', '--format=%ci', 'HEAD') |
| 12 | except: |
| 13 | commit_id = 'invalid-hash' |
| 14 | commit_date = 'invalid-date' |
| 15 | |
| 16 | hfile = open(sys.argv[1], 'w') |
| 17 | |
| 18 | hfile.write('#define ANGLE_COMMIT_HASH "%s"\n' % commit_id) |
| 19 | hfile.write('#define ANGLE_COMMIT_HASH_SIZE %d\n' % commit_id_size) |
| 20 | hfile.write('#define ANGLE_COMMIT_DATE "%s"\n' % commit_date) |
| 21 | |
| 22 | hfile.close() |