2021-10-16 03:58:25 +00:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
|
|
|
import os
|
|
|
|
import sys
|
|
|
|
import time
|
|
|
|
|
|
|
|
from datetime import datetime,timezone
|
|
|
|
from shutil import which
|
2022-11-12 14:27:07 +00:00
|
|
|
from subprocess import check_output
|
2021-10-16 03:58:25 +00:00
|
|
|
|
|
|
|
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",
|
2022-11-12 14:27:07 +00:00
|
|
|
"--dirty"], encoding="UTF-8")
|
2021-10-16 03:58:25 +00:00
|
|
|
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()
|
|
|
|
|
2023-07-29 09:13:55 +00:00
|
|
|
ts = float(os.environ.get('SOURCE_DATE_EPOCH', time.time()))
|
|
|
|
date = datetime.fromtimestamp(ts, timezone.utc)
|
2021-10-16 03:58:25 +00:00
|
|
|
|
|
|
|
OLD_REVISION = ""
|
2023-07-29 09:13:55 +00:00
|
|
|
NEW_REVISION = f'#define VERSION "{version}"'
|
|
|
|
BUILDDATE = f'#define BUILDDATE "{date.ctime()}"'
|
|
|
|
MPVCOPYRIGHT = f'#define MPVCOPYRIGHT "Copyright © 2000-2023 mpv/MPlayer/mplayer2 projects"'
|
2021-10-16 03:58:25 +00:00
|
|
|
|
|
|
|
if os.path.isfile(sys.argv[1]):
|
|
|
|
with open(sys.argv[1], "r") as f:
|
2023-07-29 09:13:55 +00:00
|
|
|
OLD_REVISION = f.readline().strip()
|
2021-10-16 03:58:25 +00:00
|
|
|
|
2023-07-29 09:13:55 +00:00
|
|
|
if NEW_REVISION != OLD_REVISION or NEW_REVISION.endswith('dirty"'):
|
2021-10-16 03:58:25 +00:00
|
|
|
with open(sys.argv[1], "w", encoding="utf-8") as f:
|
2023-07-29 09:13:55 +00:00
|
|
|
f.writelines(f"{l}{os.linesep}" for l in [NEW_REVISION, BUILDDATE, MPVCOPYRIGHT])
|