mirror of
https://gitlab.freedesktop.org/libinput/libinput.git
synced 2025-12-20 05:40: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
|
||||
* the builddir, return that directory. Otherwise, return NULL.
|
||||
* the builddir true and set builddir (if not NULL) to the given builddir.
|
||||
*/
|
||||
static inline char *
|
||||
builddir_lookup(void)
|
||||
static inline bool
|
||||
builddir_lookup(char **builddir)
|
||||
{
|
||||
char execdir[PATH_MAX];
|
||||
char *pathsep;
|
||||
|
|
@ -42,11 +42,11 @@ builddir_lookup(void)
|
|||
/* In the case of release builds, the builddir is
|
||||
the empty string */
|
||||
if (streq(MESON_BUILD_ROOT, ""))
|
||||
return NULL;
|
||||
return false;
|
||||
|
||||
nread = readlink("/proc/self/exe", execdir, sizeof(execdir) - 1);
|
||||
if (nread <= 0 || nread == sizeof(execdir) - 1)
|
||||
return NULL;
|
||||
return false;
|
||||
|
||||
/* readlink doesn't terminate the string and readlink says
|
||||
anything past sz is undefined */
|
||||
|
|
@ -54,11 +54,14 @@ builddir_lookup(void)
|
|||
|
||||
pathsep = strrchr(execdir, '/');
|
||||
if (!pathsep)
|
||||
return NULL;
|
||||
return false;
|
||||
|
||||
*pathsep = '\0';
|
||||
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_CUSTOM
|
||||
} want_jobs = JOBS_DEFAULT;
|
||||
char *builddir;
|
||||
char *jobs_env;
|
||||
int jobs = 0;
|
||||
|
||||
/* If we are not running from the builddir, we assume we're running
|
||||
* against the system as installed */
|
||||
builddir = builddir_lookup();
|
||||
if (!builddir)
|
||||
if (!builddir_lookup(NULL))
|
||||
use_system_rules_quirks = true;
|
||||
free(builddir);
|
||||
|
||||
if (in_debugger)
|
||||
want_jobs = JOBS_SINGLE;
|
||||
|
|
|
|||
|
|
@ -28,21 +28,24 @@
|
|||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
char *builddir;
|
||||
char *builddir = NULL;
|
||||
char *mode;
|
||||
|
||||
assert(argc == 2);
|
||||
mode = argv[1];
|
||||
|
||||
builddir = builddir_lookup();
|
||||
bool is_builddir = builddir_lookup(&builddir);
|
||||
if (streq(mode, "--builddir-is-null")) {
|
||||
assert(!is_builddir);
|
||||
assert(builddir == NULL);
|
||||
} 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(!is_builddir);
|
||||
assert(builddir == NULL);
|
||||
} else {
|
||||
assert(is_builddir);
|
||||
assert(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 */
|
||||
if (!data_path) {
|
||||
char *builddir = builddir_lookup();
|
||||
if (builddir) {
|
||||
if (builddir_lookup(NULL)) {
|
||||
data_path = LIBINPUT_QUIRKS_SRCDIR;
|
||||
free(builddir);
|
||||
} else {
|
||||
data_path = LIBINPUT_QUIRKS_DIR;
|
||||
override_file = LIBINPUT_QUIRKS_OVERRIDE_FILE;
|
||||
|
|
|
|||
|
|
@ -1799,19 +1799,16 @@ print_device_quirks(struct record_device *dev)
|
|||
struct quirks_context *quirks;
|
||||
const char *data_path = LIBINPUT_QUIRKS_DIR;
|
||||
const char *override_file = LIBINPUT_QUIRKS_OVERRIDE_FILE;
|
||||
char *builddir = NULL;
|
||||
|
||||
if (stat(dev->devnode, &st) < 0)
|
||||
return;
|
||||
|
||||
if ((builddir = builddir_lookup())) {
|
||||
if (builddir_lookup(NULL)) {
|
||||
setenv("LIBINPUT_QUIRKS_DIR", LIBINPUT_QUIRKS_SRCDIR, 0);
|
||||
data_path = LIBINPUT_QUIRKS_SRCDIR;
|
||||
override_file = NULL;
|
||||
}
|
||||
|
||||
free(builddir);
|
||||
|
||||
quirks = quirks_init_subsystem(data_path,
|
||||
override_file,
|
||||
quirks_log_handler,
|
||||
|
|
|
|||
|
|
@ -538,10 +538,8 @@ tools_open_device(const char **paths, bool verbose, bool *grab)
|
|||
static void
|
||||
tools_setenv_quirks_dir(void)
|
||||
{
|
||||
char *builddir = builddir_lookup();
|
||||
if (builddir) {
|
||||
if (builddir_lookup(NULL)) {
|
||||
setenv("LIBINPUT_QUIRKS_DIR", LIBINPUT_QUIRKS_SRCDIR, 0);
|
||||
free(builddir);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -765,8 +763,9 @@ setup_path(void)
|
|||
const char *path = getenv("PATH");
|
||||
char new_path[PATH_MAX];
|
||||
const char *extra_path = LIBINPUT_TOOL_PATH;
|
||||
char *builddir = builddir_lookup();
|
||||
char *builddir = NULL;
|
||||
|
||||
builddir_lookup(&builddir);
|
||||
snprintf(new_path,
|
||||
sizeof(new_path),
|
||||
"%s:%s",
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue