build: guard git version detection against missing .git directory
Some checks failed
Continuous integration build / compile (clang, alpine:edge, disabled) (push) Has been cancelled
Continuous integration build / compile (clang, alpine:edge, enabled) (push) Has been cancelled
Continuous integration build / compile (clang, archlinux:base-devel, disabled) (push) Has been cancelled
Continuous integration build / compile (clang, archlinux:base-devel, enabled) (push) Has been cancelled
Continuous integration build / compile (gcc, alpine:edge, disabled) (push) Has been cancelled
Continuous integration build / compile (gcc, alpine:edge, enabled) (push) Has been cancelled
Continuous integration build / compile (gcc, archlinux:base-devel, disabled) (push) Has been cancelled
Continuous integration build / compile (gcc, archlinux:base-devel, enabled) (push) Has been cancelled
Continuous integration build / format (push) Has been cancelled
Continuous integration build / scan-build (push) Has been cancelled

When building from a release tarball, there is no .git directory
and git rev-parse would either fail or pick up a parent repository's
HEAD. Guard the git version detection with fs.is_dir('.git') so
that tarball builds produce a clean version string.

Requires importing the fs module.

Signed-off-by: Rudi Heitbaum <rudi@heitbaum.com>
This commit is contained in:
Rudi Heitbaum 2026-06-02 22:42:58 +00:00 committed by Simon Ser
parent 1f9f0d2581
commit e5db9506b4

View file

@ -18,6 +18,8 @@ add_project_arguments(
language: 'c', language: 'c',
) )
fs = import('fs')
if get_option('buildtype').startswith('debug') if get_option('buildtype').startswith('debug')
add_project_arguments('-DDEBUG', language : 'c') add_project_arguments('-DDEBUG', language : 'c')
endif endif
@ -43,6 +45,7 @@ math = cc.find_library('m')
have_xwayland = wlroots.get_variable(pkgconfig: 'have_xwayland', internal: 'have_xwayland') == 'true' have_xwayland = wlroots.get_variable(pkgconfig: 'have_xwayland', internal: 'have_xwayland') == 'true'
version = '@0@'.format(meson.project_version()) version = '@0@'.format(meson.project_version())
if fs.is_dir('.git')
git = find_program('git', native: true, required: false) git = find_program('git', native: true, required: false)
if git.found() if git.found()
git_commit = run_command([git, 'rev-parse', '--short', 'HEAD'], check: false) git_commit = run_command([git, 'rev-parse', '--short', 'HEAD'], check: false)
@ -55,6 +58,7 @@ if git.found()
) )
endif endif
endif endif
endif
conf_data = configuration_data() conf_data = configuration_data()
conf_data.set10('CAGE_HAS_XWAYLAND', have_xwayland) conf_data.set10('CAGE_HAS_XWAYLAND', have_xwayland)