c75dba101acf4ffc85fb0bc3ec9290690bf91f7c
[mesa.git] / bin / git_sha1_gen.py
1 #!/usr/bin/env python
2
3 """
4 Generate the contents of the git_sha1.h file.
5 The output of this script goes to stdout.
6 """
7
8
9 import os
10 import os.path
11 import subprocess
12 import sys
13
14
15 def get_git_sha1():
16 """Try to get the git SHA1 with git rev-parse."""
17 git_dir = os.path.join(os.path.dirname(sys.argv[0]), '..', '.git')
18 try:
19 git_sha1 = subprocess.check_output([
20 'git',
21 '--git-dir=' + git_dir,
22 'rev-parse',
23 'HEAD',
24 ], stderr=open(os.devnull, 'w')).decode("ascii")
25 except:
26 # don't print anything if it fails
27 git_sha1 = ''
28 return git_sha1
29
30
31 git_sha1 = os.environ.get('MESA_GIT_SHA1_OVERRIDE', get_git_sha1())[:10]
32 if git_sha1:
33 git_sha1_h_in_path = os.path.join(os.path.dirname(sys.argv[0]),
34 '..', 'src', 'git_sha1.h.in')
35 with open(git_sha1_h_in_path , 'r') as git_sha1_h_in:
36 sys.stdout.write(git_sha1_h_in.read().replace('@VCS_TAG@', git_sha1))