[PATCH libinput 1/5] tools: if the execdir is the builddir, add it to the path
Pekka Paalanen
ppaalanen at gmail.com
Thu Jun 28 08:08:04 UTC 2018
On Thu, 28 Jun 2018 09:51:39 +1000
Peter Hutterer <peter.hutterer at who-t.net> wrote:
> 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 <peter.hutterer at who-t.net>
> ---
> 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
Hi Peter,
this is an interesting idea. My worry is that
tools_execdir_is_builddir() might incorrectly return NULL and you
wouldn't know, so I would propose to add a test that specifically tests
this function to return the correct path when running under the test
suite. Probably quite difficult to test the opposite too?
The code looks correct to me, but I haven't read it in the context of
the surrounding code. I might some day steal this for Weston. :-)
Thanks,
pq
>
> 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
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 833 bytes
Desc: OpenPGP digital signature
URL: <https://lists.freedesktop.org/archives/wayland-devel/attachments/20180628/861e9fe2/attachment-0001.sig>
More information about the wayland-devel
mailing list