meson: fix version generation from git

run_command() was only run at configure time, meaning the generated
version (that was passed on to the sources via -DYAMBAR_VERSION)
became stale.

Fix by implementing a shell script that generates a header file, and
wrap this in a custom target that is run every time (but the generated
file is only updated when the version changes)
This commit is contained in:
Daniel Eklöf 2019-10-19 21:47:21 +02:00
parent e9d5c620a4
commit c4f9168191
No known key found for this signature in database
GPG key ID: 5BBD4992C116573F
4 changed files with 44 additions and 24 deletions

32
generate-version.sh Executable file
View file

@ -0,0 +1,32 @@
#!/usr/bin/bash
set -e
default_version=${1}
src_dir=${2}
out_file=${3}
# echo "default version: ${default_version}"
# echo "source directory: ${src_dir}"
# echo "output file: ${out_file}"
if [[ $(command -v git) ]]; then
new_version="$(git describe --always --tags) ($(env LC_TIME=C date "+%b %d %Y"), branch '$(git rev-parse --abbrev-ref HEAD)')"
else
new_version="${default_version}"
fi
new_version="#define YAMBAR_VERSION \"${new_version}\""
if [[ -f "${out_file}" ]]; then
old_version=$(<"${out_file}")
else
old_version=""
fi
# echo "old version: ${old_version}"
# echo "new version: ${new_version}"
if [[ "${old_version}" != "${new_version}" ]]; then
echo "${new_version}" > "${out_file}"
fi