2
Generate the contents of the git_sha1.h file.
13
"""Try to get the git SHA1 with git rev-parse."""
14
git_dir = os.path.join(os.path.dirname(sys.argv[0]), '..', '.git')
16
git_sha1 = subprocess.check_output([
18
'--git-dir=' + git_dir,
21
], stderr=open(os.devnull, 'w')).decode("ascii")
23
# don't print anything if it fails
28
def write_if_different(contents):
30
Avoid touching the output file if it doesn't need modifications
31
Useful to avoid triggering rebuilds when nothing has changed.
33
if os.path.isfile(args.output):
34
with open(args.output, 'r') as file:
35
if file.read() == contents:
37
with open(args.output, 'w') as file:
41
parser = argparse.ArgumentParser()
42
parser.add_argument('--output', help='File to write the #define in',
44
args = parser.parse_args()
46
git_sha1 = os.environ.get('MESA_GIT_SHA1_OVERRIDE', get_git_sha1())[:10]
48
write_if_different('#define MESA_GIT_SHA1 " (git-' + git_sha1 + ')"')
50
write_if_different('#define MESA_GIT_SHA1 ""')