diff --git a/version.py b/version.py index e90394dfa1..cec74c252c 100755 --- a/version.py +++ b/version.py @@ -6,15 +6,16 @@ import time from datetime import datetime,timezone from shutil import which -from subprocess import check_output +from subprocess import check_output, DEVNULL 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): + # stdin is set to DEVNULL to workaround waf preforking issues version = check_output([git, "-C", srcdir, "describe", "--always", "--tags", - "--dirty"], encoding="UTF-8") + "--dirty"], stdin=DEVNULL, encoding="UTF-8") version = version[1:].strip() else: version_path = os.path.join(srcdir, "VERSION") diff --git a/version.sh b/version.sh deleted file mode 100755 index 825ae0beca..0000000000 --- a/version.sh +++ /dev/null @@ -1,66 +0,0 @@ -#!/bin/sh - -export LC_ALL=C - -version_h="version.h" -print=yes - -for ac_option do - ac_arg=$(echo $ac_option | cut -d '=' -f 2-) - case "$ac_option" in - --extra=*) - extra="-$ac_arg" - ;; - --versionh=*) - version_h="$(pwd)/$ac_arg" - print=no - ;; - --cwd=*) - cwd="$ac_arg" - ;; - *) - echo "Unknown parameter: $ac_option" >&2 - exit 1 - ;; - - esac -done - -if test "$cwd" ; then - cd "$cwd" -fi - -# Extract revision number from file used by daily tarball snapshots -# or from "git describe" output -git_revision=$(cat snapshot_version 2> /dev/null) -test "$git_revision" || test ! -e .git || git_revision="$(git describe \ - --match "v[0-9]*" --always --tags --dirty | sed 's/^v//')" -version="$git_revision" - -# other tarballs extract the version number from the VERSION file -if test ! "$version"; then - version="$(cat VERSION 2> /dev/null)" -fi - -test "$version" || version=UNKNOWN - -VERSION="${version}${extra}" - -if test "$print" = yes ; then - echo "$VERSION" - exit 0 -fi - -NEW_REVISION="#define VERSION \"${VERSION}\"" -OLD_REVISION=$(head -n 1 "$version_h" 2> /dev/null) -BUILDDATE="#define BUILDDATE \"$(date)\"" -MPVCOPYRIGHT="#define MPVCOPYRIGHT \"Copyright © 2000-2023 mpv/MPlayer/mplayer2 projects\"" - -# Update version.h only on revision changes to avoid spurious rebuilds -if test "$NEW_REVISION" != "$OLD_REVISION"; then - cat < "$version_h" -$NEW_REVISION -$BUILDDATE -$MPVCOPYRIGHT -EOF -fi diff --git a/wscript b/wscript index a2c036da8e..0eb1788b48 100644 --- a/wscript +++ b/wscript @@ -1018,7 +1018,7 @@ def configure(ctx): ctx.add_os_flags('LIBRARY_PATH') - ctx.load('compiler_c') + ctx.load('compiler_c python') ctx.load('waf_customizations') ctx.load('dependencies') ctx.load('detections.compiler_swift') @@ -1075,16 +1075,11 @@ def configure(ctx): Logs.error("WARNING: Building mpv with waf is deprecated and will be removed the future! It is recommended to switch to meson as soon as possible.") def __write_version__(ctx): - ctx.env.VERSIONH_ST = '--versionh="%s"' - ctx.env.CWD_ST = '--cwd="%s"' - ctx.env.VERSIONSH_CWD = [ctx.srcnode.abspath()] - ctx( - source = 'version.sh', + source = 'version.py', target = 'generated/version.h', - rule = 'sh ${SRC} ${CWD_ST:VERSIONSH_CWD} ${VERSIONH_ST:TGT}', - always = True, - update_outputs = True) + rule = '${PYTHON} ${SRC} ${TGT}', + always = True) def build(ctx): if ctx.options.variant not in ctx.all_envs: