From ca2a06898f8a5967846590a4bd709363f5d6ce8a Mon Sep 17 00:00:00 2001 From: Ariadne Conill Date: Tue, 6 Aug 2024 09:23:10 -0700 Subject: [PATCH] cli: add integration for --print-variables with --env --- cli/main.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/cli/main.c b/cli/main.c index 3ce05d9..79247c5 100644 --- a/cli/main.c +++ b/cli/main.c @@ -525,6 +525,51 @@ maybe_add_module_definitions(pkgconf_client_t *client, pkgconf_pkg_t *world, pkg } } +static void +apply_env_variables(pkgconf_client_t *client, pkgconf_pkg_t *world, const char *env_prefix) +{ + (void) client; + pkgconf_node_t *world_iter; + + PKGCONF_FOREACH_LIST_ENTRY(world->required.head, world_iter) + { + pkgconf_dependency_t *dep = world_iter->data; + pkgconf_pkg_t *pkg = dep->match; + pkgconf_node_t *tuple_iter; + + if ((dep->flags & PKGCONF_PKG_DEPF_QUERY) != PKGCONF_PKG_DEPF_QUERY) + continue; + + if (dep->match == NULL) + continue; + + PKGCONF_FOREACH_LIST_ENTRY(pkg->vars.head, tuple_iter) + { + pkgconf_tuple_t *tuple = tuple_iter->data; + char havebuf[PKGCONF_ITEM_SIZE]; + char *p; + + snprintf(havebuf, sizeof havebuf, "%s_%s", env_prefix, tuple->key); + + for (p = havebuf; *p; p++) + { + switch (*p) + { + case ' ': + case '-': + *p = '_'; + break; + + default: + *p = toupper((unsigned char) *p); + } + } + + printf("%s='%s'\n", havebuf, tuple->value); + } + } +} + static bool apply_env(pkgconf_client_t *client, pkgconf_pkg_t *world, void *env_prefix_p, int maxdepth) { @@ -544,6 +589,9 @@ apply_env(pkgconf_client_t *client, pkgconf_pkg_t *world, void *env_prefix_p, in if (!apply_env_var(workbuf, client, world, maxdepth, pkgconf_pkg_libs, filter_libs, NULL)) return false; + if ((want_flags & PKG_VARIABLES) == PKG_VARIABLES) + apply_env_variables(client, world, want_env_prefix); + return true; }