From 230503157388a3d0e60ed3560ceb1524331121d0 Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Fri, 30 Dec 2016 11:13:04 -0600 Subject: [PATCH] libpkgconf: path: make the duplicate filtering opt-in. some path lists should not be deduped (compiler path lists, for example) --- doc/libpkgconf-path.rst | 3 +++ libpkgconf/client.c | 14 +++++++------- libpkgconf/libpkgconf.h | 6 +++--- libpkgconf/path.c | 19 +++++++++++-------- libpkgconf/pkg.c | 6 +++--- 5 files changed, 27 insertions(+), 21 deletions(-) diff --git a/doc/libpkgconf-path.rst b/doc/libpkgconf-path.rst index 5017305..6fb8dbc 100644 --- a/doc/libpkgconf-path.rst +++ b/doc/libpkgconf-path.rst @@ -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 diff --git a/libpkgconf/client.c b/libpkgconf/client.c index 139098c..4781023 100644 --- a/libpkgconf/client.c +++ b/libpkgconf/client.c @@ -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); } /* diff --git a/libpkgconf/libpkgconf.h b/libpkgconf/libpkgconf.h index e88792e..61bdc23 100644 --- a/libpkgconf/libpkgconf.h +++ b/libpkgconf/libpkgconf.h @@ -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); diff --git a/libpkgconf/path.c b/libpkgconf/path.c index bb3250d..1c26013 100644 --- a/libpkgconf/path.c +++ b/libpkgconf/path.c @@ -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; diff --git a/libpkgconf/pkg.c b/libpkgconf/pkg.c index 58376f6..03b984a 100644 --- a/libpkgconf/pkg.c +++ b/libpkgconf/pkg.c @@ -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; }