mirror of
https://github.com/mpv-player/mpv
synced 2025-03-11 08:37:59 +00:00
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.
This commit is contained in:
parent
8e97f41849
commit
05ff82e153
@ -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',
|
||||
|
Loading…
Reference in New Issue
Block a user