build: remove version.py

After second thought version.py does not do anything useful. Meson has
built-in function vcs_tag that mostly replicate what version.py did. For
the build time we can just use __DATE__ and __TIME__. Of course this
changes time string format a little, but in my opinion it looks nicer in
fact.

Also it will use local time, instead UTC. But I would argue that date
string is only informative for users to check how old the specific mpv
build is. It doesn't have to be precise, it weren't for years anyway
before recent change.
This commit is contained in:
Kacper Michajłow 2023-07-30 12:34:55 +02:00 committed by Dudemanguy
parent 30bf811a8f
commit df7a094765
4 changed files with 13 additions and 49 deletions

8
common/meson.build Normal file
View File

@ -0,0 +1,8 @@
version_h = vcs_tag(
command: ['git', 'describe', '--always', '--tags', '--dirty'],
input: 'version.h.in',
output: 'version.h',
replace_string: '@VERSION@',
)
sources += version_h

3
common/version.h.in Normal file
View File

@ -0,0 +1,3 @@
#define VERSION "@VERSION@"
#define BUILDDATE __DATE__ " " __TIME__
#define MPVCOPYRIGHT "Copyright © 2000-2023 mpv/MPlayer/mplayer2 projects"

View File

@ -556,7 +556,6 @@ tools_directory = join_paths(source_root, 'TOOLS')
docutils_wrapper = find_program(join_paths(tools_directory, 'docutils-wrapper.py')) docutils_wrapper = find_program(join_paths(tools_directory, 'docutils-wrapper.py'))
file2string = find_program(join_paths(tools_directory, 'file2string.py')) file2string = find_program(join_paths(tools_directory, 'file2string.py'))
matroska = find_program(join_paths(tools_directory, 'matroska.py')) matroska = find_program(join_paths(tools_directory, 'matroska.py'))
version_py = find_program(join_paths(source_root, 'version.py'))
ebml_defs = custom_target('ebml_defs.inc', ebml_defs = custom_target('ebml_defs.inc',
output: 'ebml_defs.inc', output: 'ebml_defs.inc',
@ -568,13 +567,9 @@ ebml_types = custom_target('ebml_types.h',
command: [matroska, '--generate-header', '@OUTPUT@'], command: [matroska, '--generate-header', '@OUTPUT@'],
) )
version_h = custom_target('version.h', sources += [ebml_defs, ebml_types]
output: 'version.h',
command: [version_py, '@OUTPUT@'],
build_always_stale: true,
)
sources += [ebml_defs, ebml_types, version_h]
subdir('common')
subdir('etc') subdir('etc')
subdir('player') subdir('player')
subdir('sub') subdir('sub')

View File

@ -1,42 +0,0 @@
#!/usr/bin/env python3
import os
import sys
import time
from datetime import datetime,timezone
from shutil import which
from subprocess import check_output
srcdir = os.path.dirname(os.path.abspath(sys.argv[0]))
git_dir = os.path.join(srcdir, ".git")
git = which('git')
if git and os.path.exists(git_dir):
version = check_output([git, "-C", srcdir, "describe", "--always", "--tags",
"--dirty"], encoding="UTF-8")
version = version[1:].strip()
else:
version_path = os.path.join(srcdir, "VERSION")
with open(version_path, "r") as f:
version = f.readline().strip()
if len(sys.argv) < 2:
print(version)
sys.exit()
ts = float(os.environ.get('SOURCE_DATE_EPOCH', time.time()))
date = datetime.fromtimestamp(ts, timezone.utc)
OLD_REVISION = ""
NEW_REVISION = f'#define VERSION "{version}"'
BUILDDATE = f'#define BUILDDATE "{date.ctime()}"'
MPVCOPYRIGHT = f'#define MPVCOPYRIGHT "Copyright © 2000-2023 mpv/MPlayer/mplayer2 projects"'
if os.path.isfile(sys.argv[1]):
with open(sys.argv[1], "r") as f:
OLD_REVISION = f.readline().strip()
if NEW_REVISION != OLD_REVISION or NEW_REVISION.endswith('dirty"'):
with open(sys.argv[1], "w", encoding="utf-8") as f:
f.writelines(f"{l}{os.linesep}" for l in [NEW_REVISION, BUILDDATE, MPVCOPYRIGHT])