From c645c6fd7248fcc83425e0d97bf6bd201989dbf7 Mon Sep 17 00:00:00 2001 From: heinrich5991 Date: Sun, 19 Mar 2023 17:02:49 +0100 Subject: [PATCH 1/2] scripts/git_revision.py: Remove unused backcompat Compatibility with Python 3.2 and lower was already removed earlier. --- scripts/git_revision.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/scripts/git_revision.py b/scripts/git_revision.py index 59c036654..b7f7a0453 100644 --- a/scripts/git_revision.py +++ b/scripts/git_revision.py @@ -1,11 +1,8 @@ -import errno import subprocess try: git_hash = subprocess.check_output(["git", "rev-parse", "--short=16", "HEAD"], stderr=subprocess.DEVNULL).decode().strip() definition = f'"{git_hash}"' -except FileNotFoundError as e: - if e.errno != errno.ENOENT: - raise +except FileNotFoundError: definition = "0" except subprocess.CalledProcessError: definition = "0" From bb086b8393b71358cb0bb87f987989b1b847bef2 Mon Sep 17 00:00:00 2001 From: heinrich5991 Date: Sun, 19 Mar 2023 17:13:58 +0100 Subject: [PATCH 2/2] 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. --- scripts/git_revision.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/scripts/git_revision.py b/scripts/git_revision.py index b7f7a0453..ae9c9ec40 100644 --- a/scripts/git_revision.py +++ b/scripts/git_revision.py @@ -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};")