From 541de8bd597f8e57e600b81d093ccedd6c253c6c Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Fri, 24 Mar 2017 00:05:42 -0500 Subject: [PATCH] main: handle query selectors that are only usable for single packages correctly --print-requires, --print-requires-private, --print-provides, --modversion, --print-variable and --print-variables are inquiring information about a package, not about a dependency graph. in such cases, we should not try to solve the problem set to determine if it is satisfiable, as any invocation of these commands are trying to inquire about a specific package. instead, just solve the problem set for a single level (so we can load the package itself) which is far more useful behaviour when scanning .pc files for their dependency metadata. as an aside, this allows us to successfully scan .pc files which are otherwise unsatisfiable. --- main.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/main.c b/main.c index 8c1610d..126be16 100644 --- a/main.c +++ b/main.c @@ -62,6 +62,7 @@ static pkgconf_client_t pkg_client; static uint64_t want_flags; static int maximum_traverse_depth = 2000; +static size_t maximum_package_count = 0; static char *want_variable = NULL; @@ -850,6 +851,21 @@ main(int argc, char *argv[]) if ((want_flags & PKG_DONT_DEFINE_PREFIX) == PKG_DONT_DEFINE_PREFIX) want_client_flags &= ~PKGCONF_PKG_PKGF_REDEFINE_PREFIX; + /* if these selectors are used, it means that we are inquiring about a single package. + * so signal to libpkgconf that we do not want to use the dependency resolver for more than one level, + * and also limit the SAT problem to a single package. + */ + if ((want_flags & PKG_REQUIRES) == PKG_REQUIRES || + (want_flags & PKG_REQUIRES_PRIVATE) == PKG_REQUIRES_PRIVATE || + (want_flags & PKG_PROVIDES) == PKG_PROVIDES || + (want_flags & PKG_VARIABLES) == PKG_VARIABLES || + (want_flags & PKG_MODVERSION) == PKG_MODVERSION || + want_variable != NULL) + { + maximum_package_count = 1; + maximum_traverse_depth = 1; + } + if (getenv("PKG_CONFIG_ALLOW_SYSTEM_CFLAGS") != NULL) want_flags |= PKG_KEEP_SYSTEM_CFLAGS; @@ -995,6 +1011,12 @@ main(int argc, char *argv[]) if (package == NULL) break; + /* check if there is a limit to the number of packages allowed to be included, if so and we have hit + * the limit, stop adding packages to the queue. + */ + if (maximum_package_count > 0 && pkgq.length > maximum_package_count) + break; + while (isspace((unsigned int)package[0])) package++;