mirror of
https://codeberg.org/dnkl/foot.git
synced 2026-02-05 04:06:08 -05:00
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 -DFUZZEL_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:
parent
6fd4f6000b
commit
286db002f8
4 changed files with 51 additions and 26 deletions
|
|
@ -1,3 +1,5 @@
|
||||||
|
sh = find_program('sh', native: true)
|
||||||
|
|
||||||
scdoc = dependency('scdoc', native: true)
|
scdoc = dependency('scdoc', native: true)
|
||||||
scdoc_prog = find_program(scdoc.get_pkgconfig_variable('scdoc'), native: true)
|
scdoc_prog = find_program(scdoc.get_pkgconfig_variable('scdoc'), native: true)
|
||||||
|
|
||||||
|
|
|
||||||
38
generate-version.sh
Executable file
38
generate-version.sh
Executable file
|
|
@ -0,0 +1,38 @@
|
||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
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 > /dev/null; then
|
||||||
|
workdir=$(pwd)
|
||||||
|
cd "${src_dir}"
|
||||||
|
git_version=$(git describe --always --tags)
|
||||||
|
git_branch=$(git rev-parse --abbrev-ref HEAD)
|
||||||
|
cd "${workdir}"
|
||||||
|
|
||||||
|
new_version="${git_version} ($(env LC_TIME=C date "+%b %d %Y"), branch '${git_branch}')"
|
||||||
|
else
|
||||||
|
new_version="${default_version}"
|
||||||
|
fi
|
||||||
|
|
||||||
|
new_version="#define FOOT_VERSION \"${new_version}\""
|
||||||
|
|
||||||
|
if [ -f "${out_file}" ]; then
|
||||||
|
old_version=$(cat "${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
|
||||||
1
main.c
1
main.c
|
|
@ -39,6 +39,7 @@
|
||||||
#include "slave.h"
|
#include "slave.h"
|
||||||
#include "terminal.h"
|
#include "terminal.h"
|
||||||
#include "tokenize.h"
|
#include "tokenize.h"
|
||||||
|
#include "version.h"
|
||||||
#include "vt.h"
|
#include "vt.h"
|
||||||
|
|
||||||
#define min(x, y) ((x) < (y) ? (x) : (y))
|
#define min(x, y) ((x) < (y) ? (x) : (y))
|
||||||
|
|
|
||||||
36
meson.build
36
meson.build
|
|
@ -1,6 +1,7 @@
|
||||||
project('foot', 'c',
|
project('foot', 'c',
|
||||||
version: '0.9.0',
|
version: '0.9.0',
|
||||||
license: 'MIT',
|
license: 'MIT',
|
||||||
|
meson_version: '>=0.47.0',
|
||||||
default_options: [
|
default_options: [
|
||||||
'c_std=c11',
|
'c_std=c11',
|
||||||
'warning_level=1',
|
'warning_level=1',
|
||||||
|
|
@ -9,32 +10,8 @@ project('foot', 'c',
|
||||||
|
|
||||||
is_debug_build = get_option('buildtype').startswith('debug')
|
is_debug_build = get_option('buildtype').startswith('debug')
|
||||||
|
|
||||||
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
|
|
||||||
|
|
||||||
add_project_arguments(
|
add_project_arguments(
|
||||||
['-D_GNU_SOURCE=200809L',
|
['-D_GNU_SOURCE=200809L'] + (is_debug_build ? ['-D_DEBUG'] : []),
|
||||||
'-DFOOT_VERSION=@0@'.format(version)] +
|
|
||||||
(is_debug_build ? ['-D_DEBUG'] : []),
|
|
||||||
language: 'c',
|
language: 'c',
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -78,6 +55,13 @@ foreach prot : [
|
||||||
command: [wscanner_prog, 'private-code', '@INPUT@', '@OUTPUT@'])
|
command: [wscanner_prog, 'private-code', '@INPUT@', '@OUTPUT@'])
|
||||||
endforeach
|
endforeach
|
||||||
|
|
||||||
|
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@'])
|
||||||
|
|
||||||
executable(
|
executable(
|
||||||
'foot',
|
'foot',
|
||||||
'base64.c', 'base64.h',
|
'base64.c', 'base64.h',
|
||||||
|
|
@ -99,7 +83,7 @@ executable(
|
||||||
'tokenize.c', 'tokenize.h',
|
'tokenize.c', 'tokenize.h',
|
||||||
'tllist.h',
|
'tllist.h',
|
||||||
'vt.c', 'vt.h',
|
'vt.c', 'vt.h',
|
||||||
wl_proto_src + wl_proto_headers,
|
wl_proto_src + wl_proto_headers, version,
|
||||||
dependencies: [threads, math, freetype, fontconfig, pixman, wayland_client, wayland_cursor, xkb],
|
dependencies: [threads, math, freetype, fontconfig, pixman, wayland_client, wayland_cursor, xkb],
|
||||||
install: true)
|
install: true)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue