When running libinput tools from the builddir, look up the subtools in the builddir as well. Otherwise, add the install prefix to the list of lookup locations.
This ensures that a) we're running builddir stuff against builddir stuff, but also b) that we're not running builddir stuff against installed stuff because that may give us false positives. Signed-off-by: Peter Hutterer <[email protected]> --- Similar-ish to the git approach Emil suggested in [1] but git is a lot more involved here. Since we only need this for debugging tools, we can pick the simpler approach here and simply ignore most of the corner cases. [1] https://lists.freedesktop.org/archives/wayland-devel/2018-June/038658.html meson.build | 1 + tools/shared.c | 31 ++++++++++++++++++++++++++++++- tools/shared.h | 3 +++ 3 files changed, 34 insertions(+), 1 deletion(-) diff --git a/meson.build b/meson.build index 58e909b6..5580086f 100644 --- a/meson.build +++ b/meson.build @@ -31,6 +31,7 @@ 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()) prefix = '''#define _GNU_SOURCE 1 #include <assert.h> diff --git a/tools/shared.c b/tools/shared.c index f2ed1fd0..776b3d3e 100644 --- a/tools/shared.c +++ b/tools/shared.c @@ -467,18 +467,47 @@ out: return is_touchpad; } +/* Try to read the directory we're executing from and if it matches the + * builddir, return it as path. Otherwise, return NULL. + */ +char * +tools_execdir_is_builddir(void) +{ + char execdir[PATH_MAX]; + char *pathsep; + ssize_t sz; + + sz = readlink("/proc/self/exe", execdir, sizeof(execdir)); + if (sz <= 0 || sz == sizeof(execdir)) + return NULL; + + pathsep = strrchr(execdir, '/'); + if (!pathsep) + return NULL; + + *pathsep = '\0'; + if (!streq(execdir, MESON_BUILD_ROOT)) + return NULL; + + return safe_strdup(execdir); +} + static inline void setup_path(void) { const char *path = getenv("PATH"); char new_path[PATH_MAX]; + char *builddir; + + builddir = tools_execdir_is_builddir(); snprintf(new_path, sizeof(new_path), "%s:%s", - LIBINPUT_TOOL_PATH, + builddir ? builddir : LIBINPUT_TOOL_PATH, path ? path : ""); setenv("PATH", new_path, 1); + free(builddir); } int diff --git a/tools/shared.h b/tools/shared.h index e30bc39f..364babe6 100644 --- a/tools/shared.h +++ b/tools/shared.h @@ -119,4 +119,7 @@ tools_list_device_quirks(struct quirks_context *ctx, void (*callback)(void *userdata, const char *str), void *userdata); +char * +tools_execdir_is_builddir(void); + #endif -- 2.17.1 _______________________________________________ wayland-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/wayland-devel
