From 731d4452c33647b76217ce8f6b20e69f6cc355f3 Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Wed, 7 Jan 2026 08:32:54 +1000 Subject: [PATCH] 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: --- meson.build | 9 +++++---- src/builddir.h | 4 ++++ test/test-builddir-lookup.c | 18 ++++++++---------- 3 files changed, 17 insertions(+), 14 deletions(-) diff --git a/meson.build b/meson.build index ca56c97b..68a06b28 100644 --- a/meson.build +++ b/meson.build @@ -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')) diff --git a/src/builddir.h b/src/builddir.h index 1f90a563..74203bdc 100644 --- a/src/builddir.h +++ b/src/builddir.h @@ -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 } diff --git a/test/test-builddir-lookup.c b/test/test-builddir-lookup.c index ae118fb1..15e3eeae 100644 --- a/test/test-builddir-lookup.c +++ b/test/test-builddir-lookup.c @@ -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(); }