introduce PKG_CONFIG_PKGCONF1_SYSROOT_RULES for legacy pkgconf behavior

master
Ariadne Conill 2022-07-26 18:00:22 +00:00
parent f8aefea7ec
commit 6c70781aad
5 changed files with 43 additions and 18 deletions

View File

@ -1018,6 +1018,9 @@ main(int argc, char *argv[])
if (getenv("PKG_CONFIG_FDO_SYSROOT_RULES"))
want_client_flags |= PKGCONF_PKG_PKGF_FDO_SYSROOT_RULES;
if (getenv("PKG_CONFIG_PKGCONF1_SYSROOT_RULES"))
want_client_flags |= PKGCONF_PKG_PKGF_PKGCONF1_SYSROOT_RULES;
if ((want_flags & PKG_SHORT_ERRORS) == PKG_SHORT_ERRORS)
want_client_flags |= PKGCONF_PKG_PKGF_SIMPLIFY_ERRORS;

View File

@ -93,15 +93,18 @@ pkgconf_fragment_is_special(const char *string)
}
static inline void
pkgconf_fragment_munge(const pkgconf_client_t *client, char *buf, size_t buflen, const char *source, const char *sysroot_dir)
pkgconf_fragment_munge(const pkgconf_client_t *client, char *buf, size_t buflen, const char *source, const char *sysroot_dir, unsigned int flags)
{
*buf = '\0';
if (sysroot_dir == NULL)
sysroot_dir = pkgconf_tuple_find_global(client, "pc_sysrootdir");
if (!(flags & PKGCONF_PKG_PROPF_UNINSTALLED) || (client->flags & PKGCONF_PKG_PKGF_PKGCONF1_SYSROOT_RULES))
{
if (sysroot_dir == NULL)
sysroot_dir = pkgconf_tuple_find_global(client, "pc_sysrootdir");
if (sysroot_dir != NULL && pkgconf_fragment_should_munge(source, sysroot_dir))
pkgconf_strlcat(buf, sysroot_dir, buflen);
if (sysroot_dir != NULL && pkgconf_fragment_should_munge(source, sysroot_dir))
pkgconf_strlcat(buf, sysroot_dir, buflen);
}
pkgconf_strlcat(buf, source, buflen);
@ -110,27 +113,28 @@ pkgconf_fragment_munge(const pkgconf_client_t *client, char *buf, size_t buflen,
}
static inline char *
pkgconf_fragment_copy_munged(const pkgconf_client_t *client, const char *source)
pkgconf_fragment_copy_munged(const pkgconf_client_t *client, const char *source, unsigned int flags)
{
char mungebuf[PKGCONF_ITEM_SIZE];
pkgconf_fragment_munge(client, mungebuf, sizeof mungebuf, source, client->sysroot_dir);
pkgconf_fragment_munge(client, mungebuf, sizeof mungebuf, source, client->sysroot_dir, flags);
return strdup(mungebuf);
}
/*
* !doc
*
* .. c:function:: void pkgconf_fragment_add(const pkgconf_client_t *client, pkgconf_list_t *list, const char *string)
* .. c:function:: void pkgconf_fragment_add(const pkgconf_client_t *client, pkgconf_list_t *list, const char *string, unsigned int flags)
*
* Adds a `fragment` of text to a `fragment list`, possibly modifying the fragment if a sysroot is set.
*
* :param pkgconf_client_t* client: The pkgconf client being accessed.
* :param pkgconf_list_t* list: The fragment list.
* :param char* string: The string of text to add as a fragment to the fragment list.
* :param uint flags: Parsing-related flags for the package.
* :return: nothing
*/
void
pkgconf_fragment_add(const pkgconf_client_t *client, pkgconf_list_t *list, const char *string)
pkgconf_fragment_add(const pkgconf_client_t *client, pkgconf_list_t *list, const char *string, unsigned int flags)
{
pkgconf_fragment_t *frag;
@ -142,7 +146,7 @@ pkgconf_fragment_add(const pkgconf_client_t *client, pkgconf_list_t *list, const
frag = calloc(sizeof(pkgconf_fragment_t), 1);
frag->type = *(string + 1);
frag->data = pkgconf_fragment_copy_munged(client, string + 2);
frag->data = pkgconf_fragment_copy_munged(client, string + 2, flags);
PKGCONF_TRACE(client, "added fragment {%c, '%s'} to list @%p", frag->type, frag->data, list);
}
@ -161,7 +165,7 @@ pkgconf_fragment_add(const pkgconf_client_t *client, pkgconf_list_t *list, const
size_t len;
char *newdata;
pkgconf_fragment_munge(client, mungebuf, sizeof mungebuf, string, NULL);
pkgconf_fragment_munge(client, mungebuf, sizeof mungebuf, string, NULL, flags);
len = strlen(parent->data) + strlen(mungebuf) + 2;
newdata = malloc(len);
@ -686,6 +690,8 @@ pkgconf_fragment_parse(const pkgconf_client_t *client, pkgconf_list_t *list, pkg
for (i = 0; i < argc; i++)
{
PKGCONF_TRACE(client, "processing %s", argv[i]);
if (argv[i] == NULL)
{
PKGCONF_TRACE(client, "parsed fragment string is inconsistent: argc = %d while argv[%d] == NULL", argc, i);
@ -694,7 +700,7 @@ pkgconf_fragment_parse(const pkgconf_client_t *client, pkgconf_list_t *list, pkg
return false;
}
pkgconf_fragment_add(client, list, argv[i]);
pkgconf_fragment_add(client, list, argv[i], flags);
}
pkgconf_argv_free(argv);

View File

@ -262,6 +262,7 @@ PKGCONF_API void pkgconf_cross_personality_deinit(pkgconf_cross_personality_t *p
#define PKGCONF_PKG_PKGF_DONT_FILTER_INTERNAL_CFLAGS 0x2000
#define PKGCONF_PKG_PKGF_DONT_MERGE_SPECIAL_FRAGMENTS 0x4000
#define PKGCONF_PKG_PKGF_FDO_SYSROOT_RULES 0x8000
#define PKGCONF_PKG_PKGF_PKGCONF1_SYSROOT_RULES 0x10000
#define PKGCONF_PKG_DEPF_INTERNAL 0x1
@ -347,7 +348,7 @@ typedef struct pkgconf_fragment_render_ops_ {
typedef bool (*pkgconf_fragment_filter_func_t)(const pkgconf_client_t *client, const pkgconf_fragment_t *frag, void *data);
PKGCONF_API bool pkgconf_fragment_parse(const pkgconf_client_t *client, pkgconf_list_t *list, pkgconf_list_t *vars, const char *value, unsigned int flags);
PKGCONF_API void pkgconf_fragment_add(const pkgconf_client_t *client, pkgconf_list_t *list, const char *string);
PKGCONF_API void pkgconf_fragment_add(const pkgconf_client_t *client, pkgconf_list_t *list, const char *string, unsigned int flags);
PKGCONF_API void pkgconf_fragment_copy(const pkgconf_client_t *client, pkgconf_list_t *list, const pkgconf_fragment_t *base, bool is_private);
PKGCONF_API void pkgconf_fragment_copy_list(const pkgconf_client_t *client, pkgconf_list_t *list, const pkgconf_list_t *base);
PKGCONF_API void pkgconf_fragment_delete(pkgconf_list_t *list, pkgconf_fragment_t *node);

View File

@ -225,14 +225,14 @@ pkgconf_tuple_add(const pkgconf_client_t *client, pkgconf_list_t *list, const ch
dequote_value = dequote(value);
PKGCONF_TRACE(client, "adding tuple to @%p: %s => %s (parsed? %d)", list, key, dequote_value, parse);
tuple->key = strdup(key);
if (parse)
tuple->value = pkgconf_tuple_parse(client, list, dequote_value, flags);
else
tuple->value = strdup(dequote_value);
PKGCONF_TRACE(client, "adding tuple to @%p: %s => %s (parsed? %d)", list, key, tuple->value, parse);
pkgconf_node_insert(&tuple->iter, tuple, list);
free(dequote_value);
@ -290,7 +290,8 @@ pkgconf_tuple_parse(const pkgconf_client_t *client, pkgconf_list_t *vars, const
const char *ptr;
char *bptr = buf;
if (!(client->flags & PKGCONF_PKG_PKGF_FDO_SYSROOT_RULES))
if (!(client->flags & PKGCONF_PKG_PKGF_FDO_SYSROOT_RULES) &&
(!(flags & PKGCONF_PKG_PROPF_UNINSTALLED) || (client->flags & PKGCONF_PKG_PKGF_PKGCONF1_SYSROOT_RULES)))
{
if (*value == '/' && client->sysroot_dir != NULL && strncmp(value, client->sysroot_dir, strlen(client->sysroot_dir)))
bptr += pkgconf_strlcpy(buf, client->sysroot_dir, sizeof buf);
@ -329,6 +330,8 @@ pkgconf_tuple_parse(const pkgconf_client_t *client, pkgconf_list_t *vars, const
}
}
PKGCONF_TRACE(client, "lookup tuple %s", varname);
ptr += (pptr - ptr);
kv = pkgconf_tuple_find_global(client, varname);
if (kv != NULL)

View File

@ -8,6 +8,7 @@ tests_init \
do_not_eat_slash \
do_not_duplicate_sysroot_dir \
uninstalled \
uninstalled_pkgconf1 \
uninstalled_fdo
do_not_eat_slash_body()
@ -70,7 +71,18 @@ uninstalled_body()
export PKG_CONFIG_SYSROOT_DIR="/sysroot"
atf_check \
-o inline:"-lomg \n" \
-o inline:"-L/test/lib -lomg \n" \
pkgconf --libs omg
}
uninstalled_pkgconf1_body()
{
export PKG_CONFIG_PATH="${selfdir}/lib1"
export PKG_CONFIG_SYSROOT_DIR="/sysroot"
export PKG_CONFIG_PKGCONF1_SYSROOT_RULES="1"
atf_check \
-o inline:"-L/sysroot/test/lib -lomg \n" \
pkgconf --libs omg
}
@ -81,6 +93,6 @@ uninstalled_fdo_body()
export PKG_CONFIG_FDO_SYSROOT_RULES="1"
atf_check \
-o inline:"-L/sysroot/test/lib -lomg \n" \
-o inline:"-L/test/lib -lomg \n" \
pkgconf --libs omg
}