scripts/git_revision.py: Allow to pass in the git shortrev

Use the `DDNET_GIT_SHORTREV_HASH` variable for this. This allows builds
that do not use `git` to still have this kind of version information.
This commit is contained in:
heinrich5991 2023-03-19 17:13:58 +01:00
parent c645c6fd72
commit bb086b8393

View file

@ -1,9 +1,12 @@
import os
import subprocess
git_hash = os.environ.get("DDNET_GIT_SHORTREV_HASH")
try:
git_hash = subprocess.check_output(["git", "rev-parse", "--short=16", "HEAD"], stderr=subprocess.DEVNULL).decode().strip()
git_hash = git_hash or subprocess.check_output(["git", "rev-parse", "--short=16", "HEAD"], stderr=subprocess.DEVNULL).decode().strip()
except (FileNotFoundError, subprocess.CalledProcessError):
pass
if git_hash is not None:
definition = f'"{git_hash}"'
except FileNotFoundError:
definition = "0"
except subprocess.CalledProcessError:
else:
definition = "0"
print(f"const char *GIT_SHORTREV_HASH = {definition};")