diff options
author | Dan Nicholson <dbn.lists@gmail.com> | 2012-11-19 10:45:41 -0800 |
---|---|---|
committer | Dan Nicholson <dbn.lists@gmail.com> | 2012-12-04 13:04:57 -0800 |
commit | 9adfd9ebfcb8a9656999116307c15061364bf7df (patch) | |
tree | 221281c51f3906aa1490fc15b0b6dbd6505af017 /pkg.c | |
parent | 5b6ec1b6e92b9de070a36df11eb123338228a85b (diff) | |
download | pkg-config-9adfd9ebfcb8a9656999116307c15061364bf7df.tar.gz |
Only strip duplicate arguments when they appear consecutivelyflag-order-fixes
pkg-config strips all duplicate arguments from the flag output string.
This is done for 2 reasons:
1. When a package shows up twice in the final package list after
resolving all Requires, stripping was used to ensure it's flags only
showed up once at the correct location.
2. An optimization so that the output string is not excessively long.
Since commit c6ec7869, 1. is no longer necessary as the final package
list only contains each package once. 2. causes problems when applied
too aggressively since some arguments have different semantics depending
on the prior or subsequent arguments.
To keep a bit of optimization, the stripping is reduced to only removing
consecutive duplicate arguments. This should ensure that the semantics
are kept intact while removing obviously unnecessary arguments.
The drawback is that some arguments will now appear multiple times in
the output when they previously would have only appeared once. Here we
have to rely on the tools using these arguments to handle the duplicates
appropriately since there is no way for pkg-config to encode all the
semantics of those arguments. Another thing that can help this situation
is if pkg-config is used for all packages in the Requires chain so that
the Libs/Cflags of each package only pertain to itself and don't encode
the compiling/linking rules of a 3rd party package.
Freedesktop #16101 (https://bugs.freedesktop.org/show_bug.cgi?id=16101)
Diffstat (limited to 'pkg.c')
-rw-r--r-- | pkg.c | 43 |
1 files changed, 13 insertions, 30 deletions
@@ -424,47 +424,30 @@ get_package_quiet (const char *name) return internal_get_package (name, FALSE); } +/* Strip consecutive duplicate arguments in the flag list. */ static GList * -flag_list_strip_duplicates (GList *list, gboolean forward) +flag_list_strip_duplicates (GList *list) { - GHashTable *table; GList *tmp; - table = g_hash_table_new (g_str_hash, g_str_equal); - for (tmp = forward ? list : g_list_last (list); - tmp != NULL; - tmp = forward ? g_list_next (tmp) : g_list_previous (tmp)) + /* Start at the 2nd element of the list so we don't have to check for an + * existing previous element. */ + for (tmp = g_list_next (list); tmp != NULL; tmp = g_list_next (tmp)) { - Flag *flag = tmp->data; + Flag *cur = tmp->data; + Flag *prev = tmp->prev->data; - debug_spew ("Seeing if arg %s is duplicate\n", flag->arg); - - if (!g_hash_table_lookup_extended (table, flag->arg, NULL, NULL)) - { - /* Unique flag. Track it and and move to the next. */ - g_hash_table_replace (table, flag->arg, flag->arg); - } - else + if (cur->type == prev->type && g_strcmp0 (cur->arg, prev->arg) == 0) { - GList *dup = tmp; - /* Remove the duplicate flag from the list and move to the last * element to prepare for the next iteration. */ - if (forward) - { - debug_spew (" removing duplicate \"%s\"\n", flag->arg); - tmp = g_list_previous (tmp); - } - else - { - debug_spew (" removing duplicate (from back) \"%s\"\n", - flag->arg); - tmp = g_list_next (tmp); - } + GList *dup = tmp; + + debug_spew (" removing duplicate \"%s\"\n", cur->arg); + tmp = g_list_previous (tmp); list = g_list_remove_link (list, dup); } } - g_hash_table_destroy (table); return list; } @@ -960,7 +943,7 @@ get_multi_merged (GList *pkgs, FlagType type, gboolean in_path_order, char *retval; list = fill_list (pkgs, type, in_path_order, include_private); - list = flag_list_strip_duplicates (list, in_path_order); + list = flag_list_strip_duplicates (list); retval = flag_list_to_string (list); g_list_free (list); |