6445: scripts/git_revision.py: Allow to pass in the git shortrev r=def- a=heinrich5991

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.

## Checklist

- [x] Tested the change ingame
- [ ] Provided screenshots if it is a visual change
- [ ] Tested in combination with possibly related configuration options
- [ ] Written a unit test (especially base/) or added coverage to integration test
- [ ] Considered possible null pointers and out of bounds array indexing
- [ ] Changed no physics that affect existing maps
- [ ] Tested the change with [ASan+UBSan or valgrind's memcheck](https://github.com/ddnet/ddnet/#using-addresssanitizer--undefinedbehavioursanitizer-or-valgrinds-memcheck) (optional)


Co-authored-by: heinrich5991 <heinrich5991@gmail.com>
This commit is contained in:
bors[bot] 2023-03-19 17:19:32 +00:00 committed by GitHub
commit 8d5ee109c7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1,12 +1,12 @@
import errno
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 as e:
if e.errno != errno.ENOENT:
raise
definition = "0"
except subprocess.CalledProcessError:
else:
definition = "0"
print(f"const char *GIT_SHORTREV_HASH = {definition};")