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.
pull/119/head
William Pitcock 2017-03-24 00:05:42 -05:00
parent 9d05871d32
commit 541de8bd59
1 changed files with 22 additions and 0 deletions

22
main.c
View File

@ -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++;