From 6ef4a853b516f7ab2b14baf8a34177c023d99ee5 Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Wed, 21 Dec 2016 20:06:17 -0600 Subject: [PATCH] libpkgconf: migrate pkgconf client fragment_is_system_dir() to a libpkgconf API --- doc/libpkgconf-fragment.rst | 10 ++++++++++ libpkgconf/fragment.c | 33 +++++++++++++++++++++++++++++++++ libpkgconf/libpkgconf.h | 1 + main.c | 24 ++---------------------- 4 files changed, 46 insertions(+), 22 deletions(-) diff --git a/doc/libpkgconf-fragment.rst b/doc/libpkgconf-fragment.rst index b8c2d85..e9029e8 100644 --- a/doc/libpkgconf-fragment.rst +++ b/doc/libpkgconf-fragment.rst @@ -15,6 +15,16 @@ which is composable, mergeable and reorderable. :param char* string: The string of text to add as a fragment to the fragment list. :return: nothing +.. c:function:: bool pkgconf_fragment_has_system_dir(const pkgconf_client_t *client, const pkgconf_fragment_t *frag) + + Checks if a `fragment` contains a `system path`. System paths are detected at compile time and optionally overridden by + the ``PKG_CONFIG_SYSTEM_INCLUDE_PATH`` and ``PKG_CONFIG_SYSTEM_LIBRARY_PATH`` environment variables. + + :param pkgconf_client_t* client: The pkgconf client object the fragment belongs to. + :param pkgconf_fragment_t* frag: The fragment being checked. + :return: true if the fragment contains a system path, else false + :rtype: bool + .. c:function:: void pkgconf_fragment_copy(pkgconf_list_t *list, const pkgconf_fragment_t *base, unsigned int flags, bool is_private) Copies a `fragment` to another `fragment list`, possibly removing a previous copy of the `fragment` diff --git a/libpkgconf/fragment.c b/libpkgconf/fragment.c index 12c7f6d..57efe34 100644 --- a/libpkgconf/fragment.c +++ b/libpkgconf/fragment.c @@ -238,6 +238,39 @@ pkgconf_fragment_exists(pkgconf_list_t *list, const pkgconf_fragment_t *base, un return pkgconf_fragment_lookup(list, base); } +/* + * !doc + * + * .. c:function:: bool pkgconf_fragment_has_system_dir(const pkgconf_client_t *client, const pkgconf_fragment_t *frag) + * + * Checks if a `fragment` contains a `system path`. System paths are detected at compile time and optionally overridden by + * the ``PKG_CONFIG_SYSTEM_INCLUDE_PATH`` and ``PKG_CONFIG_SYSTEM_LIBRARY_PATH`` environment variables. + * + * :param pkgconf_client_t* client: The pkgconf client object the fragment belongs to. + * :param pkgconf_fragment_t* frag: The fragment being checked. + * :return: true if the fragment contains a system path, else false + * :rtype: bool + */ +bool +pkgconf_fragment_has_system_dir(const pkgconf_client_t *client, const pkgconf_fragment_t *frag) +{ + const pkgconf_list_t *check_paths = NULL; + + switch (frag->type) + { + case 'L': + check_paths = &client->filter_libdirs; + break; + case 'I': + check_paths = &client->filter_includedirs; + break; + default: + return false; + } + + return pkgconf_path_match_list(frag->data, check_paths); +} + /* * !doc * diff --git a/libpkgconf/libpkgconf.h b/libpkgconf/libpkgconf.h index 1b7096b..98e1345 100644 --- a/libpkgconf/libpkgconf.h +++ b/libpkgconf/libpkgconf.h @@ -235,6 +235,7 @@ void pkgconf_fragment_filter(const pkgconf_client_t *client, pkgconf_list_t *des size_t pkgconf_fragment_render_len(const pkgconf_list_t *list); void pkgconf_fragment_render_buf(const pkgconf_list_t *list, char *buf, size_t len); char *pkgconf_fragment_render(const pkgconf_list_t *list); +bool pkgconf_fragment_has_system_dir(const pkgconf_client_t *client, const pkgconf_fragment_t *frag); /* fileio.c */ char *pkgconf_fgetline(char *line, size_t size, FILE *stream); diff --git a/main.c b/main.c index 8d45680..066b7c1 100644 --- a/main.c +++ b/main.c @@ -72,26 +72,6 @@ error_handler(const char *msg, const pkgconf_client_t *client, const void *data) return true; } -static bool -fragment_has_system_dir(const pkgconf_client_t *client, const pkgconf_fragment_t *frag) -{ - const pkgconf_list_t *check_paths = NULL; - - switch (frag->type) - { - case 'L': - check_paths = &client->filter_libdirs; - break; - case 'I': - check_paths = &client->filter_includedirs; - break; - default: - return false; - } - - return pkgconf_path_match_list(frag->data, check_paths); -} - static bool print_list_entry(const pkgconf_pkg_t *entry, void *data) { @@ -125,7 +105,7 @@ filter_cflags(const pkgconf_client_t *client, const pkgconf_fragment_t *frag, un (void) client; (void) flags; - if (fragment_has_system_dir(client, frag)) + if (pkgconf_fragment_has_system_dir(client, frag)) return false; if (frag->type == 'I') @@ -143,7 +123,7 @@ filter_libs(const pkgconf_client_t *client, const pkgconf_fragment_t *frag, unsi (void) client; (void) flags; - if (fragment_has_system_dir(client, frag)) + if (pkgconf_fragment_has_system_dir(client, frag)) return false; switch (frag->type)