From 4ba414f74a84a7cc96d7e2d6a11bab3de722cbbf Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Sat, 7 Jan 2017 15:04:34 -0600 Subject: [PATCH] fragment: handle oddball fragments like -framework more accurately --- libpkgconf/fragment.c | 17 +++++++++++++++-- tests/framework.sh | 4 ++-- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/libpkgconf/fragment.c b/libpkgconf/fragment.c index 02fe9b8..6a64508 100644 --- a/libpkgconf/fragment.c +++ b/libpkgconf/fragment.c @@ -47,6 +47,10 @@ pkgconf_fragment_is_unmergeable(const char *string) if (!strncmp(string, check_fragments[i].token, check_fragments[i].len)) return true; + /* only one pair of {-flag, arg} may be merged together */ + if (strchr(string, ' ') != NULL) + return false; + return false; } @@ -145,7 +149,8 @@ pkgconf_fragment_add(const pkgconf_client_t *client, pkgconf_list_t *list, const { pkgconf_fragment_t *parent = list->tail->data; - if (pkgconf_fragment_is_unmergeable(parent->data)) + /* only attempt to merge 'special' fragments together */ + if (!parent->type && pkgconf_fragment_is_unmergeable(parent->data)) { size_t len; char *newdata; @@ -162,6 +167,14 @@ pkgconf_fragment_add(const pkgconf_client_t *client, pkgconf_list_t *list, const free(parent->data); parent->data = newdata; + /* use a copy operation to force a dedup */ + pkgconf_node_delete(&parent->iter, list); + pkgconf_fragment_copy(list, parent, 0, false); + + /* the fragment list now (maybe) has the copied node, so free the original */ + free(parent->data); + free(parent); + return; } } @@ -261,7 +274,7 @@ pkgconf_fragment_should_merge(const pkgconf_fragment_t *base) case 'I': return true; default: - return parent->type == base->type; + return !base->type || parent->type == base->type; } } diff --git a/tests/framework.sh b/tests/framework.sh index 602c6d4..c87c0c9 100755 --- a/tests/framework.sh +++ b/tests/framework.sh @@ -12,9 +12,9 @@ libs_body() -o inline:"-F/test/lib -framework framework-1 \n" \ pkgconf --libs framework-1 atf_check \ - -o inline:"-F/test/lib -framework framework-2 -F/test/lib -framework framework-1 \n" \ + -o inline:"-F/test/lib -framework framework-2 -framework framework-1 \n" \ pkgconf --libs framework-2 atf_check \ - -o inline:"-F/test/lib -framework framework-1 -F/test/lib -framework framework-2 \n" \ + -o inline:"-F/test/lib -framework framework-2 -framework framework-1 \n" \ pkgconf --libs framework-1 framework-2 }