From c4f9168191a24c017fc0f50a8724538783cd147a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Sat, 19 Oct 2019 21:47:21 +0200 Subject: [PATCH] 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) --- doc/meson.build | 2 ++ generate-version.sh | 32 ++++++++++++++++++++++++++++++++ main.c | 1 + meson.build | 33 +++++++++------------------------ 4 files changed, 44 insertions(+), 24 deletions(-) create mode 100755 generate-version.sh diff --git a/doc/meson.build b/doc/meson.build index afb6e05..b4dccb3 100644 --- a/doc/meson.build +++ b/doc/meson.build @@ -1,3 +1,5 @@ +sh = find_program('sh', native: true) + scdoc = dependency('scdoc', native: true) scdoc_prog = find_program(scdoc.get_pkgconfig_variable('scdoc'), native: true) diff --git a/generate-version.sh b/generate-version.sh new file mode 100755 index 0000000..014d1b9 --- /dev/null +++ b/generate-version.sh @@ -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 diff --git a/main.c b/main.c index d111337..a8d6ab9 100644 --- a/main.c +++ b/main.c @@ -22,6 +22,7 @@ #define LOG_MODULE "main" #include "log.h" +#include "version.h" static volatile sig_atomic_t aborted = 0; diff --git a/meson.build b/meson.build index acdc381..9e8fb2c 100644 --- a/meson.build +++ b/meson.build @@ -10,28 +10,6 @@ project('yambar', 'c', is_debug_build = get_option('buildtype').startswith('debug') plugs_as_libs = get_option('core-plugins-as-shared-libraries') -version = '"@0@"'.format(meson.project_version()) - -sh = find_program('sh', native: true) -git = find_program('git', required: false, native: true) - -if git.found() - commit_hash = run_command( - [sh.path(), '-c', - '@0@ --git-dir="$MESON_SOURCE_ROOT/.git" describe --always --tags'.format( - git.path())]) - - branch = run_command( - [sh.path(), '-c', - '@0@ "--git-dir=$MESON_SOURCE_ROOT/.git" rev-parse --abbrev-ref HEAD'.format( - git.path())]) - - if commit_hash.returncode() == 0 and branch.returncode() == 0 - version = '"@0@ (" __DATE__ ", branch \'@1@\')"'.format( - commit_hash.stdout().strip(), branch.stdout().strip()) - endif -endif - # Common dependencies cc = meson.get_compiler('c') dl = cc.find_library('dl') @@ -59,8 +37,7 @@ wlroots = dependency('wlroots', required: get_option('backend-wayland')) backend_wayland = wayland_client.found() and wayland_cursor.found() and wlroots.found() add_project_arguments( - ['-D_GNU_SOURCE', - '-DYAMBAR_VERSION=@0@'.format(version)] + + ['-D_GNU_SOURCE'] + (is_debug_build ? ['-D_DEBUG'] : []) + (backend_x11 ? ['-DENABLE_X11'] : []) + (backend_wayland ? ['-DENABLE_WAYLAND'] : []) + @@ -87,6 +64,13 @@ subdir('decorations') subdir('particles') subdir('modules') +generate_version_sh = files('generate-version.sh') +version = custom_target( + 'generate_version', + build_always_stale: true, + output: 'version.h', + command: [generate_version_sh, meson.project_version(), '@SOURCE_DIR@', '@OUTPUT@']) + yambar = executable( 'yambar', 'color.h', @@ -102,6 +86,7 @@ yambar = executable( 'tag.c', 'tag.h', 'tllist.h', 'yml.c', 'yml.h', + version, dependencies: [bar, freetype, fontconfig, pixman, yaml, threads, dl] + decorations + particles + modules, build_rpath: '$ORIGIN/modules:$ORIGIN/decorations:$ORIGIN/particles',