From 00fdbe3951d7717b03c46b31d1712c45fe492cf1 Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Wed, 27 Jun 2018 14:24:54 +1000 Subject: [PATCH] tools: don't add the debug behavior for release builds When the meson build type is something other than the debug types, we don't need the special behavior where we adjust executable paths and data dir lookup for tools run directly from the builddir. This avoids leaking the build dir into the final executables. Signed-off-by: Peter Hutterer --- meson.build | 6 +++++- tools/shared.c | 5 +++++ tools/test-builddir-lookup.c | 12 +++++++++--- 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/meson.build b/meson.build index 815afba8..7d21f364 100644 --- a/meson.build +++ b/meson.build @@ -31,7 +31,11 @@ add_project_arguments(cppflags, language : 'cpp') config_h = configuration_data() config_h.set('_GNU_SOURCE', '1') -config_h.set_quoted('MESON_BUILD_ROOT', meson.build_root()) +if get_option('buildtype') == 'debug' or get_option('buildtype') == 'debugoptimized' + config_h.set_quoted('MESON_BUILD_ROOT', meson.build_root()) +else + config_h.set_quoted('MESON_BUILD_ROOT', '') +endif prefix = '''#define _GNU_SOURCE 1 #include diff --git a/tools/shared.c b/tools/shared.c index 74c0cdad..3cda4573 100644 --- a/tools/shared.c +++ b/tools/shared.c @@ -477,6 +477,11 @@ tools_execdir_is_builddir(void) char *pathsep; ssize_t sz; + /* In the case of release builds, the builddir is + the empty string */ + if (streq(MESON_BUILD_ROOT, "")) + return NULL; + sz = readlink("/proc/self/exe", execdir, sizeof(execdir) - 1); if (sz <= 0 || sz == sizeof(execdir) - 1) return NULL; diff --git a/tools/test-builddir-lookup.c b/tools/test-builddir-lookup.c index fc50b0f6..821ca70f 100644 --- a/tools/test-builddir-lookup.c +++ b/tools/test-builddir-lookup.c @@ -36,9 +36,15 @@ int main(int argc, char **argv) { if (streq(mode, "--builddir-is-null")) { assert(builddir == NULL); } else if (streq(mode, "--builddir-is-set")) { - assert(builddir != NULL); - assert(streq(MESON_BUILD_ROOT, builddir)); - free(builddir); + /* In the case of release builds, the builddir is + the empty string */ + if (streq(MESON_BUILD_ROOT, "")) { + assert(builddir == NULL); + } else { + assert(builddir != NULL); + assert(streq(MESON_BUILD_ROOT, builddir)); + free(builddir); + } } else { abort(); }