libpkgconf: path: make the duplicate filtering opt-in. some path lists should not be deduped (compiler path lists, for example)

feature/tap-sh
William Pitcock 2016-12-30 11:13:04 -06:00
parent bad0da0c03
commit 2305031573
5 changed files with 27 additions and 21 deletions

View File

@ -12,6 +12,7 @@ variables.
:param char* text: The path text to add as a path node.
:param pkgconf_list_t* dirlist: The path list to add the path node to.
:param bool filter: Whether to perform duplicate filtering.
:return: nothing
.. c:function:: size_t pkgconf_path_split(const char *text, pkgconf_list_t *dirlist)
@ -20,6 +21,7 @@ variables.
:param char* text: The path text to split and add as path nodes.
:param pkgconf_list_t* dirlist: The path list to have the path nodes added to.
:param bool filter: Whether to perform duplicate filtering.
:return: number of path nodes added to the path list
:rtype: size_t
@ -31,6 +33,7 @@ variables.
:param char* environ: The environment variable to look up.
:param char* fallback: The fallback paths to use if the environment variable is not set.
:param pkgconf_list_t* dirlist: The path list to add the path nodes to.
:param bool filter: Whether to perform duplicate filtering.
:return: number of path nodes added to the path list
:rtype: size_t

View File

@ -54,15 +54,15 @@ pkgconf_client_init(pkgconf_client_t *client, pkgconf_error_handler_func_t error
if (client->error_handler == NULL)
client->error_handler = pkgconf_default_error_handler;
pkgconf_path_build_from_environ("PKG_CONFIG_SYSTEM_LIBRARY_PATH", SYSTEM_LIBDIR, &client->filter_libdirs);
pkgconf_path_build_from_environ("PKG_CONFIG_SYSTEM_INCLUDE_PATH", SYSTEM_INCLUDEDIR, &client->filter_includedirs);
pkgconf_path_build_from_environ("PKG_CONFIG_SYSTEM_LIBRARY_PATH", SYSTEM_LIBDIR, &client->filter_libdirs, false);
pkgconf_path_build_from_environ("PKG_CONFIG_SYSTEM_INCLUDE_PATH", SYSTEM_INCLUDEDIR, &client->filter_includedirs, false);
/* GCC uses these environment variables to define system include paths, so we should check them. */
pkgconf_path_build_from_environ("LIBRARY_PATH", NULL, &client->filter_libdirs);
pkgconf_path_build_from_environ("CPATH", NULL, &client->filter_includedirs);
pkgconf_path_build_from_environ("C_INCLUDE_PATH", NULL, &client->filter_includedirs);
pkgconf_path_build_from_environ("CPLUS_INCLUDE_PATH", NULL, &client->filter_includedirs);
pkgconf_path_build_from_environ("OBJC_INCLUDE_PATH", NULL, &client->filter_includedirs);
pkgconf_path_build_from_environ("LIBRARY_PATH", NULL, &client->filter_libdirs, false);
pkgconf_path_build_from_environ("CPATH", NULL, &client->filter_includedirs, false);
pkgconf_path_build_from_environ("C_INCLUDE_PATH", NULL, &client->filter_includedirs, false);
pkgconf_path_build_from_environ("CPLUS_INCLUDE_PATH", NULL, &client->filter_includedirs, false);
pkgconf_path_build_from_environ("OBJC_INCLUDE_PATH", NULL, &client->filter_includedirs, false);
}
/*

View File

@ -271,9 +271,9 @@ void pkgconf_audit_log(pkgconf_client_t *client, const char *format, ...) PRINTF
void pkgconf_audit_log_dependency(pkgconf_client_t *client, const pkgconf_pkg_t *dep, const pkgconf_dependency_t *depnode);
/* path.c */
void pkgconf_path_add(const char *text, pkgconf_list_t *dirlist);
size_t pkgconf_path_split(const char *text, pkgconf_list_t *dirlist);
size_t pkgconf_path_build_from_environ(const char *environ, const char *fallback, pkgconf_list_t *dirlist);
void pkgconf_path_add(const char *text, pkgconf_list_t *dirlist, bool filter);
size_t pkgconf_path_split(const char *text, pkgconf_list_t *dirlist, bool filter);
size_t pkgconf_path_build_from_environ(const char *environ, const char *fallback, pkgconf_list_t *dirlist, bool filter);
bool pkgconf_path_match_list(const char *path, const pkgconf_list_t *dirlist);
void pkgconf_path_free(pkgconf_list_t *dirlist);

View File

@ -66,10 +66,11 @@ path_list_contains_entry(const char *text, pkgconf_list_t *dirlist)
*
* :param char* text: The path text to add as a path node.
* :param pkgconf_list_t* dirlist: The path list to add the path node to.
* :param bool filter: Whether to perform duplicate filtering.
* :return: nothing
*/
void
pkgconf_path_add(const char *text, pkgconf_list_t *dirlist)
pkgconf_path_add(const char *text, pkgconf_list_t *dirlist, bool filter)
{
pkgconf_path_t *node;
#ifdef PKGCONF_CACHE_INODES
@ -78,10 +79,10 @@ pkgconf_path_add(const char *text, pkgconf_list_t *dirlist)
if (stat(text, &st) == -1)
return;
if (path_list_contains_entry(text, dirlist, &st))
if (filter && path_list_contains_entry(text, dirlist, &st))
return;
#else
if (path_list_contains_entry(text, dirlist))
if (filter && path_list_contains_entry(text, dirlist))
return;
#endif
@ -103,11 +104,12 @@ pkgconf_path_add(const char *text, pkgconf_list_t *dirlist)
*
* :param char* text: The path text to split and add as path nodes.
* :param pkgconf_list_t* dirlist: The path list to have the path nodes added to.
* :param bool filter: Whether to perform duplicate filtering.
* :return: number of path nodes added to the path list
* :rtype: size_t
*/
size_t
pkgconf_path_split(const char *text, pkgconf_list_t *dirlist)
pkgconf_path_split(const char *text, pkgconf_list_t *dirlist, bool filter)
{
size_t count = 0;
char *workbuf, *p, *iter;
@ -118,7 +120,7 @@ pkgconf_path_split(const char *text, pkgconf_list_t *dirlist)
iter = workbuf = strdup(text);
while ((p = strtok(iter, PKG_CONFIG_PATH_SEP_S)) != NULL)
{
pkgconf_path_add(p, dirlist);
pkgconf_path_add(p, dirlist, filter);
count++, iter = NULL;
}
@ -138,20 +140,21 @@ pkgconf_path_split(const char *text, pkgconf_list_t *dirlist)
* :param char* environ: The environment variable to look up.
* :param char* fallback: The fallback paths to use if the environment variable is not set.
* :param pkgconf_list_t* dirlist: The path list to add the path nodes to.
* :param bool filter: Whether to perform duplicate filtering.
* :return: number of path nodes added to the path list
* :rtype: size_t
*/
size_t
pkgconf_path_build_from_environ(const char *environ, const char *fallback, pkgconf_list_t *dirlist)
pkgconf_path_build_from_environ(const char *environ, const char *fallback, pkgconf_list_t *dirlist, bool filter)
{
const char *data;
data = getenv(environ);
if (data != NULL)
return pkgconf_path_split(data, dirlist);
return pkgconf_path_split(data, dirlist, filter);
if (fallback != NULL)
return pkgconf_path_split(fallback, dirlist);
return pkgconf_path_split(fallback, dirlist, filter);
/* no fallback and no environment variable, thusly no nodes added */
return 0;

View File

@ -116,10 +116,10 @@ pkgconf_pkg_dir_list_build(pkgconf_client_t *client, unsigned int flags)
if (client->dir_list.head != NULL || client->dir_list.tail != NULL)
return;
pkgconf_path_build_from_environ("PKG_CONFIG_PATH", NULL, &client->dir_list);
pkgconf_path_build_from_environ("PKG_CONFIG_PATH", NULL, &client->dir_list, true);
if (!(flags & PKGCONF_PKG_PKGF_ENV_ONLY))
pkgconf_path_build_from_environ("PKG_CONFIG_LIBDIR", get_default_pkgconfig_path(), &client->dir_list);
pkgconf_path_build_from_environ("PKG_CONFIG_LIBDIR", get_default_pkgconfig_path(), &client->dir_list, true);
}
typedef void (*pkgconf_pkg_parser_keyword_func_t)(const pkgconf_client_t *client, pkgconf_pkg_t *pkg, const ptrdiff_t offset, char *value);
@ -530,7 +530,7 @@ pkgconf_pkg_find(pkgconf_client_t *client, const char *name, unsigned int flags)
pkgconf_pkg_t *pkg;
pkg = pkgconf_pkg_new_from_file(client, name, f);
pkgconf_path_add(pkg_get_parent_dir(pkg), &client->dir_list);
pkgconf_path_add(pkg_get_parent_dir(pkg), &client->dir_list, true);
return pkg;
}