meson: revamp the debug build detection for the builddir lookup

Ifdef out any special behavior we want so we no longer leak this via
strings in the resulting binary. Ideally we want the compile to fail for
anything missed rather than surprising behavior when we try to access
files in the build directory.

Closes: #1230
Part-of: <https://gitlab.freedesktop.org/libinput/libinput/-/merge_requests/1396>
This commit is contained in:
Peter Hutterer 2026-01-07 08:32:54 +10:00 committed by Marge Bot
parent 48e367e841
commit 731d4452c3
3 changed files with 17 additions and 14 deletions

View file

@ -80,10 +80,11 @@ endif
config_h.set_quoted('HTTP_DOC_LINK', doc_url)
config_h.set('_GNU_SOURCE', '1')
if get_option('buildtype') == 'debug' or get_option('buildtype') == 'debugoptimized'
is_debug_build = get_option('buildtype') == 'debug' or get_option('buildtype') == 'debugoptimized'
if is_debug_build
config_h.set('IS_DEBUG_BUILD', '1')
config_h.set_quoted('MESON_BUILD_ROOT', meson.current_build_dir())
else
config_h.set_quoted('MESON_BUILD_ROOT', '')
endif
prefix = '''#define _GNU_SOURCE 1
@ -758,7 +759,7 @@ executable('ptraccel-debug',
# Don't run the test during a release build because we rely on the magic
# subtool lookup
if get_option('buildtype') == 'debug' or get_option('buildtype') == 'debugoptimized'
if is_debug_build
config_tool_option_test = configuration_data()
config_tool_option_test.set('DISABLE_WARNING', 'yes')
config_tool_option_test.set('MESON_ENABLED_DEBUG_GUI', get_option('debug-gui'))

View file

@ -36,6 +36,7 @@
static inline bool
builddir_lookup(char **builddir)
{
#ifdef IS_DEBUG_BUILD
char execdir[PATH_MAX];
char *pathsep;
ssize_t nread;
@ -65,4 +66,7 @@ builddir_lookup(char **builddir)
*builddir = safe_strdup(execdir);
return true;
#else
return false;
#endif
}

View file

@ -40,16 +40,14 @@ main(int argc, char **argv)
assert(!is_builddir);
assert(builddir == NULL);
} else if (streq(mode, "--builddir-is-set")) {
/* In the case of release builds, the builddir is
the empty string */
if (streq(MESON_BUILD_ROOT, "")) {
assert(!is_builddir);
assert(builddir == NULL);
} else {
assert(is_builddir);
assert(builddir);
assert(streq(MESON_BUILD_ROOT, builddir));
}
#ifdef IS_DEBUG_BUILD
assert(is_builddir);
assert(builddir);
assert(streq(MESON_BUILD_ROOT, builddir));
#else
assert(!is_builddir);
assert(builddir == NULL);
#endif
} else {
abort();
}