2018-03-02 02:22:44 +00:00
|
|
|
import errno
|
2018-03-01 15:50:29 +00:00
|
|
|
import subprocess
|
2018-03-02 02:31:45 +00:00
|
|
|
try:
|
|
|
|
from subprocess import DEVNULL
|
|
|
|
except ImportError:
|
|
|
|
import os
|
|
|
|
DEVNULL = open(os.devnull, 'wb')
|
2018-03-01 15:50:29 +00:00
|
|
|
try:
|
2018-03-02 02:31:45 +00:00
|
|
|
git_hash = subprocess.check_output(["git", "rev-parse", "--short=16", "HEAD"], stderr=DEVNULL).decode().strip()
|
2018-03-01 15:50:29 +00:00
|
|
|
definition = '"{}"'.format(git_hash)
|
2018-03-02 02:22:44 +00:00
|
|
|
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"
|
2018-03-01 15:50:29 +00:00
|
|
|
print("const char *GIT_SHORTREV_HASH = {};".format(definition))
|