ddnet/scripts/git_revision.py

18 lines
495 B
Python
Raw Normal View History

import errno
import subprocess
try:
from subprocess import DEVNULL
except ImportError:
import os
DEVNULL = open(os.devnull, 'wb')
try:
git_hash = subprocess.check_output(["git", "rev-parse", "--short=16", "HEAD"], stderr=DEVNULL).decode().strip()
definition = '"{}"'.format(git_hash)
except FileNotFoundError as e:
if e.errno != errno.ENOENT:
raise
definition = "0"
except subprocess.CalledProcessError:
2020-12-02 14:22:26 +00:00
definition = "0"
print("const char *GIT_SHORTREV_HASH = {};".format(definition))