summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDudemanguy <random342@airmail.cc>2021-10-15 22:58:25 -0500
committerDudemanguy <random342@airmail.cc>2021-11-14 19:13:10 +0000
commit37549b6faae0767ae0813ea1da76a8d6587c4dfe (patch)
tree1971e6767973d1c87dc74e1edbc69a7d60a71b3b
parentc478a1efbaf0ccee46d11036be6b921e5a4d5036 (diff)
downloadmpv-37549b6faae0767ae0813ea1da76a8d6587c4dfe.tar.bz2
mpv-37549b6faae0767ae0813ea1da76a8d6587c4dfe.tar.xz
build: add version.py for generating version.h
version.h is essential for building, and its generation was done by a shell script. Strictly speaking, python should in general be more portable (windows), and would be better for the upcoming meson build to simply just execute a python script. version.py has some small differences with version.sh which shouldn't matter but they are noted below. - version.sh accepted several arguments that seemed useless (like --cwd). These were removed from version.py. - version.py takes either no arguments (prints the version) or it takes exactly one argument specifying the complete path of where the header should be generated. - version.sh attempted to read a file named "snapshot_version". The comments noted that this was for "daily tarball snapshots". Such a file does not exist in the source tree, and it's not really clear that anyone actually uses this. This logic was removed from version.py. - version.py reads the SOURCE_DATE_EPOCH environment variable. Some distros use this for reproducible builds. Technically you could also just disable the build date but this is only a couple of extra lines and maybe it's prettier than UNKNOWN. - version.py also doesn't attempt to display timezone information in the build date. It only shows UTC time.
-rwxr-xr-xversion.py45
1 files changed, 45 insertions, 0 deletions
diff --git a/version.py b/version.py
new file mode 100755
index 0000000000..7da2d5a459
--- /dev/null
+++ b/version.py
@@ -0,0 +1,45 @@
+#!/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()
+
+date = datetime.utcfromtimestamp(int(os.environ.get('SOURCE_DATE_EPOCH', time.time())))
+if date == "":
+ date = datetime.now(timezone.utc).astimezone()
+date_str = date.strftime("%a %b %d %I:%M:%S %Y")
+
+NEW_REVISION = "#define VERSION \"" + version + "\"\n"
+OLD_REVISION = ""
+BUILDDATE = "#define BUILDDATE \"" + date_str + "\"\n"
+MPVCOPYRIGHT = "#define MPVCOPYRIGHT \"Copyright \u00A9 2000-2021 mpv/MPlayer/mplayer2 projects\"" + "\n"
+
+if os.path.isfile(sys.argv[1]):
+ with open(sys.argv[1], "r") as f:
+ OLD_REVISION = f.readline()
+
+if NEW_REVISION != OLD_REVISION:
+ with open(sys.argv[1], "w", encoding="utf-8") as f:
+ f.writelines([NEW_REVISION, BUILDDATE, MPVCOPYRIGHT])
+