libpkgconf: refactor building the dir lists into separate concerns

feature/tap-sh
William Pitcock 2018-05-09 17:07:26 -05:00
parent 854490c5b9
commit 6b0e346c28
5 changed files with 76 additions and 72 deletions

View File

@ -711,6 +711,7 @@ main(int argc, char *argv[])
char *logfile_arg = NULL; char *logfile_arg = NULL;
char *want_env_prefix = NULL; char *want_env_prefix = NULL;
unsigned int want_client_flags = PKGCONF_PKG_PKGF_NONE; unsigned int want_client_flags = PKGCONF_PKG_PKGF_NONE;
const pkgconf_cross_personality_t *personality;
want_flags = 0; want_flags = 0;
@ -789,7 +790,8 @@ main(int argc, char *argv[])
pkgconf_client_set_trace_handler(&pkg_client, error_handler, NULL); pkgconf_client_set_trace_handler(&pkg_client, error_handler, NULL);
} }
pkgconf_client_init(&pkg_client, error_handler, NULL, pkgconf_cross_personality_default()); personality = pkgconf_cross_personality_default();
pkgconf_client_init(&pkg_client, error_handler, NULL, personality);
while ((ret = pkg_getopt_long_only(argc, argv, "", options, NULL)) != -1) while ((ret = pkg_getopt_long_only(argc, argv, "", options, NULL)) != -1)
{ {
@ -983,7 +985,7 @@ main(int argc, char *argv[])
pkgconf_client_set_flags(&pkg_client, want_client_flags); pkgconf_client_set_flags(&pkg_client, want_client_flags);
/* at this point, want_client_flags should be set, so build the dir list */ /* at this point, want_client_flags should be set, so build the dir list */
pkgconf_pkg_dir_list_build(&pkg_client); pkgconf_client_dir_list_build(&pkg_client, personality);
if (required_pkgconfig_version != NULL) if (required_pkgconfig_version != NULL)
{ {

View File

@ -45,6 +45,27 @@ trace_path_list(const pkgconf_client_t *client, const char *desc, pkgconf_list_t
} }
} }
/*
* !doc
*
* .. c:function:: void pkgconf_client_dir_list_build(pkgconf_client_t *client)
*
* Bootstraps the package search paths. If the ``PKGCONF_PKG_PKGF_ENV_ONLY`` `flag` is set on the client,
* then only the ``PKG_CONFIG_PATH`` environment variable will be used, otherwise both the
* ``PKG_CONFIG_PATH`` and ``PKG_CONFIG_LIBDIR`` environment variables will be used.
*
* :param pkgconf_client_t* client: The pkgconf client object to bootstrap.
* :return: nothing
*/
void
pkgconf_client_dir_list_build(pkgconf_client_t *client, const pkgconf_cross_personality_t *personality)
{
pkgconf_path_build_from_environ("PKG_CONFIG_PATH", NULL, &client->dir_list, true);
if (!(client->flags & PKGCONF_PKG_PKGF_ENV_ONLY) && (pkgconf_path_build_from_environ("PKG_CONFIG_LIBDIR", NULL, &client->dir_list, true)) < 1)
pkgconf_path_copy_list(&client->dir_list, &personality->dir_list);
}
/* /*
* !doc * !doc
* *

View File

@ -210,6 +210,7 @@ PKGCONF_API pkgconf_error_handler_func_t pkgconf_client_get_error_handler(const
PKGCONF_API void pkgconf_client_set_error_handler(pkgconf_client_t *client, pkgconf_error_handler_func_t error_handler, void *error_handler_data); PKGCONF_API void pkgconf_client_set_error_handler(pkgconf_client_t *client, pkgconf_error_handler_func_t error_handler, void *error_handler_data);
PKGCONF_API pkgconf_error_handler_func_t pkgconf_client_get_trace_handler(const pkgconf_client_t *client); PKGCONF_API pkgconf_error_handler_func_t pkgconf_client_get_trace_handler(const pkgconf_client_t *client);
PKGCONF_API void pkgconf_client_set_trace_handler(pkgconf_client_t *client, pkgconf_error_handler_func_t trace_handler, void *trace_handler_data); PKGCONF_API void pkgconf_client_set_trace_handler(pkgconf_client_t *client, pkgconf_error_handler_func_t trace_handler, void *trace_handler_data);
PKGCONF_API void pkgconf_client_dir_list_build(pkgconf_client_t *client, const pkgconf_cross_personality_t *personality);
/* personality.c */ /* personality.c */
PKGCONF_API const pkgconf_cross_personality_t *pkgconf_cross_personality_default(void); PKGCONF_API const pkgconf_cross_personality_t *pkgconf_cross_personality_default(void);
@ -282,7 +283,6 @@ PKGCONF_API pkgconf_pkg_t *pkgconf_builtin_pkg_get(const char *name);
PKGCONF_API int pkgconf_compare_version(const char *a, const char *b); PKGCONF_API int pkgconf_compare_version(const char *a, const char *b);
PKGCONF_API pkgconf_pkg_t *pkgconf_scan_all(pkgconf_client_t *client, void *ptr, pkgconf_pkg_iteration_func_t func); PKGCONF_API pkgconf_pkg_t *pkgconf_scan_all(pkgconf_client_t *client, void *ptr, pkgconf_pkg_iteration_func_t func);
PKGCONF_API void pkgconf_pkg_dir_list_build(pkgconf_client_t *client);
/* parse.c */ /* parse.c */
PKGCONF_API pkgconf_pkg_t *pkgconf_pkg_new_from_file(pkgconf_client_t *client, const char *path, FILE *f); PKGCONF_API pkgconf_pkg_t *pkgconf_pkg_new_from_file(pkgconf_client_t *client, const char *path, FILE *f);

View File

@ -22,6 +22,54 @@ static pkgconf_cross_personality_t default_personality = {
.name = "default", .name = "default",
}; };
static inline void
build_default_search_path(pkgconf_list_t* dirlist)
{
#ifdef _WIN32
char namebuf[MAX_PATH];
char outbuf[MAX_PATH];
char *p;
int sizepath = GetModuleFileName(NULL, namebuf, sizeof namebuf);
char * winslash;
namebuf[sizepath] = '\0';
while ((winslash = strchr (namebuf, '\\')) != NULL)
{
*winslash = '/';
}
p = strrchr(namebuf, '/');
if (p == NULL)
pkgconf_path_split(PKG_DEFAULT_PATH, dirlist, true);
*p = '\0';
pkgconf_strlcpy(outbuf, namebuf, sizeof outbuf);
pkgconf_strlcat(outbuf, "/", sizeof outbuf);
pkgconf_strlcat(outbuf, "../lib/pkgconfig", sizeof outbuf);
pkgconf_path_add(outbuf, dirlist, true);
pkgconf_strlcpy(outbuf, namebuf, sizeof outbuf);
pkgconf_strlcat(outbuf, "/", sizeof outbuf);
pkgconf_strlcat(outbuf, "../share/pkgconfig", sizeof outbuf);
pkgconf_path_add(outbuf, dirlist, true);
#elif __HAIKU__
char **paths;
size_t count;
if (find_paths(B_FIND_PATH_DEVELOP_LIB_DIRECTORY, "pkgconfig", &paths, &count) == B_OK) {
for (size_t i = 0; i < count; i++)
pkgconf_path_add(paths[i], dirlist, true);
free(paths);
paths = NULL;
}
if (find_paths(B_FIND_PATH_DATA_DIRECTORY, "pkgconfig", &paths, &count) == B_OK) {
for (size_t i = 0; i < count; i++)
pkgconf_path_add(paths[i], dirlist, true);
free(paths);
paths = NULL;
}
#else
pkgconf_path_split(PKG_DEFAULT_PATH, dirlist, true);
#endif
}
/* /*
* !doc * !doc
* *
@ -38,6 +86,8 @@ pkgconf_cross_personality_default(void)
if (default_personality_init) if (default_personality_init)
return &default_personality; return &default_personality;
build_default_search_path(&default_personality.dir_list);
pkgconf_path_split(SYSTEM_LIBDIR, &default_personality.filter_libdirs, true); pkgconf_path_split(SYSTEM_LIBDIR, &default_personality.filter_libdirs, true);
pkgconf_path_split(SYSTEM_INCLUDEDIR, &default_personality.filter_includedirs, true); pkgconf_path_split(SYSTEM_INCLUDEDIR, &default_personality.filter_includedirs, true);

View File

@ -49,54 +49,6 @@ str_has_suffix(const char *str, const char *suffix)
return !strncasecmp(str + str_len - suf_len, suffix, suf_len); return !strncasecmp(str + str_len - suf_len, suffix, suf_len);
} }
static inline void
build_default_pkgconfig_path(pkgconf_list_t* dirlist)
{
#ifdef _WIN32
char namebuf[MAX_PATH];
char outbuf[MAX_PATH];
char *p;
int sizepath = GetModuleFileName(NULL, namebuf, sizeof namebuf);
char * winslash;
namebuf[sizepath] = '\0';
while ((winslash = strchr (namebuf, '\\')) != NULL)
{
*winslash = '/';
}
p = strrchr(namebuf, '/');
if (p == NULL)
pkgconf_path_split(PKG_DEFAULT_PATH, dirlist, true);
*p = '\0';
pkgconf_strlcpy(outbuf, namebuf, sizeof outbuf);
pkgconf_strlcat(outbuf, "/", sizeof outbuf);
pkgconf_strlcat(outbuf, "../lib/pkgconfig", sizeof outbuf);
pkgconf_path_add(outbuf, dirlist, true);
pkgconf_strlcpy(outbuf, namebuf, sizeof outbuf);
pkgconf_strlcat(outbuf, "/", sizeof outbuf);
pkgconf_strlcat(outbuf, "../share/pkgconfig", sizeof outbuf);
pkgconf_path_add(outbuf, dirlist, true);
#elif __HAIKU__
char **paths;
size_t count;
if (find_paths(B_FIND_PATH_DEVELOP_LIB_DIRECTORY, "pkgconfig", &paths, &count) == B_OK) {
for (size_t i = 0; i < count; i++)
pkgconf_path_add(paths[i], dirlist, true);
free(paths);
paths = NULL;
}
if (find_paths(B_FIND_PATH_DATA_DIRECTORY, "pkgconfig", &paths, &count) == B_OK) {
for (size_t i = 0; i < count; i++)
pkgconf_path_add(paths[i], dirlist, true);
free(paths);
paths = NULL;
}
#else
pkgconf_path_split(PKG_DEFAULT_PATH, dirlist, true);
#endif
}
static const char * static const char *
pkg_get_parent_dir(pkgconf_pkg_t *pkg, char *buf, size_t buflen) pkg_get_parent_dir(pkgconf_pkg_t *pkg, char *buf, size_t buflen)
{ {
@ -112,27 +64,6 @@ pkg_get_parent_dir(pkgconf_pkg_t *pkg, char *buf, size_t buflen)
return buf; return buf;
} }
/*
* !doc
*
* .. c:function:: void pkgconf_pkg_dir_list_build(pkgconf_client_t *client)
*
* Bootstraps the package search paths. If the ``PKGCONF_PKG_PKGF_ENV_ONLY`` `flag` is set on the client,
* then only the ``PKG_CONFIG_PATH`` environment variable will be used, otherwise both the
* ``PKG_CONFIG_PATH`` and ``PKG_CONFIG_LIBDIR`` environment variables will be used.
*
* :param pkgconf_client_t* client: The pkgconf client object to bootstrap.
* :return: nothing
*/
void
pkgconf_pkg_dir_list_build(pkgconf_client_t *client)
{
pkgconf_path_build_from_environ("PKG_CONFIG_PATH", NULL, &client->dir_list, true);
if (!(client->flags & PKGCONF_PKG_PKGF_ENV_ONLY) && (pkgconf_path_build_from_environ("PKG_CONFIG_LIBDIR", NULL, &client->dir_list, true)) < 1)
build_default_pkgconfig_path(&client->dir_list);
}
typedef void (*pkgconf_pkg_parser_keyword_func_t)(const pkgconf_client_t *client, pkgconf_pkg_t *pkg, const char *keyword, const size_t lineno, const ptrdiff_t offset, char *value); typedef void (*pkgconf_pkg_parser_keyword_func_t)(const pkgconf_client_t *client, pkgconf_pkg_t *pkg, const char *keyword, const size_t lineno, const ptrdiff_t offset, char *value);
typedef struct { typedef struct {
const char *keyword; const char *keyword;