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 <peter.hutterer@who-t.net>
This commit is contained in:
Peter Hutterer 2018-06-27 14:24:54 +10:00
parent 6be9c3c84e
commit 00fdbe3951
3 changed files with 19 additions and 4 deletions

View file

@ -31,7 +31,11 @@ add_project_arguments(cppflags, language : 'cpp')
config_h = configuration_data() config_h = configuration_data()
config_h.set('_GNU_SOURCE', '1') config_h.set('_GNU_SOURCE', '1')
if get_option('buildtype') == 'debug' or get_option('buildtype') == 'debugoptimized'
config_h.set_quoted('MESON_BUILD_ROOT', meson.build_root()) config_h.set_quoted('MESON_BUILD_ROOT', meson.build_root())
else
config_h.set_quoted('MESON_BUILD_ROOT', '')
endif
prefix = '''#define _GNU_SOURCE 1 prefix = '''#define _GNU_SOURCE 1
#include <assert.h> #include <assert.h>

View file

@ -477,6 +477,11 @@ tools_execdir_is_builddir(void)
char *pathsep; char *pathsep;
ssize_t sz; 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); sz = readlink("/proc/self/exe", execdir, sizeof(execdir) - 1);
if (sz <= 0 || sz == sizeof(execdir) - 1) if (sz <= 0 || sz == sizeof(execdir) - 1)
return NULL; return NULL;

View file

@ -36,9 +36,15 @@ int main(int argc, char **argv) {
if (streq(mode, "--builddir-is-null")) { if (streq(mode, "--builddir-is-null")) {
assert(builddir == NULL); assert(builddir == NULL);
} else if (streq(mode, "--builddir-is-set")) { } 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(builddir == NULL);
} else {
assert(builddir != NULL); assert(builddir != NULL);
assert(streq(MESON_BUILD_ROOT, builddir)); assert(streq(MESON_BUILD_ROOT, builddir));
free(builddir); free(builddir);
}
} else { } else {
abort(); abort();
} }