From 05ff82e1532f9446aa41f6a0b02db7c1c48b37c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kacper=20Michaj=C5=82ow?= Date: Sun, 2 Feb 2025 13:00:09 -0600 Subject: [PATCH] build: use a more user-friendly version string for shallow clones If the cloned repo is shallow (e.g. like the default github actions settings), the git describe command won't actually be able to fetch any tags and will instead just get a hash. The resulting binary version string will end up being that git hash. While it does tell you the exact commit, it's not exactly helpful when wanting to know the general version at a glance. For the case where we do have a git directory but no available tags, build a version string using the mpv version + the commit hash. Fixes #15789. --- common/meson.build | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/common/meson.build b/common/meson.build index 99441df9d3..e4d362a0a2 100644 --- a/common/meson.build +++ b/common/meson.build @@ -1,8 +1,27 @@ +git = find_program('git', required: false) +if not git.found() + git = '' +endif + +generate_ver = ''' +#!/usr/bin/env python3 +import os +import sys +from subprocess import DEVNULL, check_output +git_cmd = [sys.argv[1], "--git-dir=" + os.path.join(sys.argv[2], ".git"), + "--work-tree=" + sys.argv[2]] +describe_cmd = git_cmd + ["describe", "--abbrev=9", "--tags", "--dirty"] +try: + ver = check_output(describe_cmd, stderr=DEVNULL, encoding="UTF-8") +except Exception: + describe_cmd += ["--always"] + ver = check_output(describe_cmd, stderr=DEVNULL, encoding="UTF-8") + ver = f"v{sys.argv[3]}-dev-g{ver}" +sys.stdout.write(ver) +''' + version_h = vcs_tag( - command: ['git', - '--git-dir=' + join_paths(source_root, '.git'), - '--work-tree=' + source_root, - 'describe', '--always', '--tags', '--dirty'], + command: [python, '-c', generate_ver, git, source_root, meson.project_version().replace('-UNKNOWN', '')], fallback: 'v' + meson.project_version(), input: 'version.h.in', output: 'version.h',