waf: migrate to version.py

Fixes https://github.com/mpv-player/mpv-build/issues/204
This commit is contained in:
Kacper Michajłow 2023-01-17 01:17:04 +01:00 committed by Dudemanguy
parent bc1af592db
commit 75e41478cc
3 changed files with 7 additions and 77 deletions

View File

@ -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")

View File

@ -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 <<EOF > "$version_h"
$NEW_REVISION
$BUILDDATE
$MPVCOPYRIGHT
EOF
fi

13
wscript
View File

@ -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: