mirror of
https://gitlab.freedesktop.org/libinput/libinput.git
synced 2025-12-20 17:20:04 +01:00
util: change the builddir_lookup() to return a boolean
All but one callers of this function only care about yes/no, so let's change it to only return the build dir in the one case it's needed. Part-of: <https://gitlab.freedesktop.org/libinput/libinput/-/merge_requests/1175>
This commit is contained in:
parent
d8482a2540
commit
0fc52abd79
6 changed files with 22 additions and 25 deletions
|
|
@ -30,10 +30,10 @@
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Try to figure out the directory we're executing from and if it matches
|
* Try to figure out the directory we're executing from and if it matches
|
||||||
* the builddir, return that directory. Otherwise, return NULL.
|
* the builddir true and set builddir (if not NULL) to the given builddir.
|
||||||
*/
|
*/
|
||||||
static inline char *
|
static inline bool
|
||||||
builddir_lookup(void)
|
builddir_lookup(char **builddir)
|
||||||
{
|
{
|
||||||
char execdir[PATH_MAX];
|
char execdir[PATH_MAX];
|
||||||
char *pathsep;
|
char *pathsep;
|
||||||
|
|
@ -42,11 +42,11 @@ builddir_lookup(void)
|
||||||
/* In the case of release builds, the builddir is
|
/* In the case of release builds, the builddir is
|
||||||
the empty string */
|
the empty string */
|
||||||
if (streq(MESON_BUILD_ROOT, ""))
|
if (streq(MESON_BUILD_ROOT, ""))
|
||||||
return NULL;
|
return false;
|
||||||
|
|
||||||
nread = readlink("/proc/self/exe", execdir, sizeof(execdir) - 1);
|
nread = readlink("/proc/self/exe", execdir, sizeof(execdir) - 1);
|
||||||
if (nread <= 0 || nread == sizeof(execdir) - 1)
|
if (nread <= 0 || nread == sizeof(execdir) - 1)
|
||||||
return NULL;
|
return false;
|
||||||
|
|
||||||
/* readlink doesn't terminate the string and readlink says
|
/* readlink doesn't terminate the string and readlink says
|
||||||
anything past sz is undefined */
|
anything past sz is undefined */
|
||||||
|
|
@ -54,11 +54,14 @@ builddir_lookup(void)
|
||||||
|
|
||||||
pathsep = strrchr(execdir, '/');
|
pathsep = strrchr(execdir, '/');
|
||||||
if (!pathsep)
|
if (!pathsep)
|
||||||
return NULL;
|
return false;
|
||||||
|
|
||||||
*pathsep = '\0';
|
*pathsep = '\0';
|
||||||
if (!streq(execdir, MESON_BUILD_ROOT))
|
if (!streq(execdir, MESON_BUILD_ROOT))
|
||||||
return NULL;
|
return false;
|
||||||
|
|
||||||
return safe_strdup(execdir);
|
if (builddir)
|
||||||
|
*builddir = safe_strdup(execdir);
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4961,16 +4961,13 @@ litest_parse_argv(int argc, char **argv, int *njobs_out)
|
||||||
JOBS_SINGLE,
|
JOBS_SINGLE,
|
||||||
JOBS_CUSTOM
|
JOBS_CUSTOM
|
||||||
} want_jobs = JOBS_DEFAULT;
|
} want_jobs = JOBS_DEFAULT;
|
||||||
char *builddir;
|
|
||||||
char *jobs_env;
|
char *jobs_env;
|
||||||
int jobs = 0;
|
int jobs = 0;
|
||||||
|
|
||||||
/* If we are not running from the builddir, we assume we're running
|
/* If we are not running from the builddir, we assume we're running
|
||||||
* against the system as installed */
|
* against the system as installed */
|
||||||
builddir = builddir_lookup();
|
if (!builddir_lookup(NULL))
|
||||||
if (!builddir)
|
|
||||||
use_system_rules_quirks = true;
|
use_system_rules_quirks = true;
|
||||||
free(builddir);
|
|
||||||
|
|
||||||
if (in_debugger)
|
if (in_debugger)
|
||||||
want_jobs = JOBS_SINGLE;
|
want_jobs = JOBS_SINGLE;
|
||||||
|
|
|
||||||
|
|
@ -28,21 +28,24 @@
|
||||||
int
|
int
|
||||||
main(int argc, char **argv)
|
main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
char *builddir;
|
char *builddir = NULL;
|
||||||
char *mode;
|
char *mode;
|
||||||
|
|
||||||
assert(argc == 2);
|
assert(argc == 2);
|
||||||
mode = argv[1];
|
mode = argv[1];
|
||||||
|
|
||||||
builddir = builddir_lookup();
|
bool is_builddir = builddir_lookup(&builddir);
|
||||||
if (streq(mode, "--builddir-is-null")) {
|
if (streq(mode, "--builddir-is-null")) {
|
||||||
|
assert(!is_builddir);
|
||||||
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
|
/* In the case of release builds, the builddir is
|
||||||
the empty string */
|
the empty string */
|
||||||
if (streq(MESON_BUILD_ROOT, "")) {
|
if (streq(MESON_BUILD_ROOT, "")) {
|
||||||
|
assert(!is_builddir);
|
||||||
assert(builddir == NULL);
|
assert(builddir == NULL);
|
||||||
} else {
|
} else {
|
||||||
|
assert(is_builddir);
|
||||||
assert(builddir);
|
assert(builddir);
|
||||||
assert(streq(MESON_BUILD_ROOT, builddir));
|
assert(streq(MESON_BUILD_ROOT, builddir));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -166,10 +166,8 @@ main(int argc, char **argv)
|
||||||
|
|
||||||
/* Overriding the data dir means no custom override file */
|
/* Overriding the data dir means no custom override file */
|
||||||
if (!data_path) {
|
if (!data_path) {
|
||||||
char *builddir = builddir_lookup();
|
if (builddir_lookup(NULL)) {
|
||||||
if (builddir) {
|
|
||||||
data_path = LIBINPUT_QUIRKS_SRCDIR;
|
data_path = LIBINPUT_QUIRKS_SRCDIR;
|
||||||
free(builddir);
|
|
||||||
} else {
|
} else {
|
||||||
data_path = LIBINPUT_QUIRKS_DIR;
|
data_path = LIBINPUT_QUIRKS_DIR;
|
||||||
override_file = LIBINPUT_QUIRKS_OVERRIDE_FILE;
|
override_file = LIBINPUT_QUIRKS_OVERRIDE_FILE;
|
||||||
|
|
|
||||||
|
|
@ -1799,19 +1799,16 @@ print_device_quirks(struct record_device *dev)
|
||||||
struct quirks_context *quirks;
|
struct quirks_context *quirks;
|
||||||
const char *data_path = LIBINPUT_QUIRKS_DIR;
|
const char *data_path = LIBINPUT_QUIRKS_DIR;
|
||||||
const char *override_file = LIBINPUT_QUIRKS_OVERRIDE_FILE;
|
const char *override_file = LIBINPUT_QUIRKS_OVERRIDE_FILE;
|
||||||
char *builddir = NULL;
|
|
||||||
|
|
||||||
if (stat(dev->devnode, &st) < 0)
|
if (stat(dev->devnode, &st) < 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if ((builddir = builddir_lookup())) {
|
if (builddir_lookup(NULL)) {
|
||||||
setenv("LIBINPUT_QUIRKS_DIR", LIBINPUT_QUIRKS_SRCDIR, 0);
|
setenv("LIBINPUT_QUIRKS_DIR", LIBINPUT_QUIRKS_SRCDIR, 0);
|
||||||
data_path = LIBINPUT_QUIRKS_SRCDIR;
|
data_path = LIBINPUT_QUIRKS_SRCDIR;
|
||||||
override_file = NULL;
|
override_file = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
free(builddir);
|
|
||||||
|
|
||||||
quirks = quirks_init_subsystem(data_path,
|
quirks = quirks_init_subsystem(data_path,
|
||||||
override_file,
|
override_file,
|
||||||
quirks_log_handler,
|
quirks_log_handler,
|
||||||
|
|
|
||||||
|
|
@ -538,10 +538,8 @@ tools_open_device(const char **paths, bool verbose, bool *grab)
|
||||||
static void
|
static void
|
||||||
tools_setenv_quirks_dir(void)
|
tools_setenv_quirks_dir(void)
|
||||||
{
|
{
|
||||||
char *builddir = builddir_lookup();
|
if (builddir_lookup(NULL)) {
|
||||||
if (builddir) {
|
|
||||||
setenv("LIBINPUT_QUIRKS_DIR", LIBINPUT_QUIRKS_SRCDIR, 0);
|
setenv("LIBINPUT_QUIRKS_DIR", LIBINPUT_QUIRKS_SRCDIR, 0);
|
||||||
free(builddir);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -765,8 +763,9 @@ setup_path(void)
|
||||||
const char *path = getenv("PATH");
|
const char *path = getenv("PATH");
|
||||||
char new_path[PATH_MAX];
|
char new_path[PATH_MAX];
|
||||||
const char *extra_path = LIBINPUT_TOOL_PATH;
|
const char *extra_path = LIBINPUT_TOOL_PATH;
|
||||||
char *builddir = builddir_lookup();
|
char *builddir = NULL;
|
||||||
|
|
||||||
|
builddir_lookup(&builddir);
|
||||||
snprintf(new_path,
|
snprintf(new_path,
|
||||||
sizeof(new_path),
|
sizeof(new_path),
|
||||||
"%s:%s",
|
"%s:%s",
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue