summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Nicholson <dbn.lists@gmail.com>2012-11-19 10:45:41 -0800
committerDan Nicholson <dbn.lists@gmail.com>2012-12-04 13:04:57 -0800
commit9adfd9ebfcb8a9656999116307c15061364bf7df (patch)
tree221281c51f3906aa1490fc15b0b6dbd6505af017
parent5b6ec1b6e92b9de070a36df11eb123338228a85b (diff)
downloadpkg-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)
-rwxr-xr-xcheck/check-duplicate-flags7
-rwxr-xr-xcheck/check-gtk14
-rw-r--r--pkg.c43
3 files changed, 25 insertions, 39 deletions
diff --git a/check/check-duplicate-flags b/check/check-duplicate-flags
index 4e0bcab..110da5b 100755
--- a/check/check-duplicate-flags
+++ b/check/check-duplicate-flags
@@ -4,11 +4,12 @@ set -e
. ${srcdir}/common
-RESULT="-DPATH2 -DPATH1 -DFOO -I/path/include"
+RESULT="-DPATH2 -DFOO -DPATH1 -DFOO -I/path/include"
run_test --cflags flag-dup-1 flag-dup-2
run_test --cflags flag-dup-2 flag-dup-1
-RESULT="-L/path/lib -lpath2 -lpath1 -Wl,--whole-archive -lm \
---Wl,--no-whole-archive -R -Xlinker /path/lib"
+RESULT="-L/path/lib -lpath2 -Wl,--whole-archive -lm --Wl,--no-whole-archive \
+-Xlinker -R -Xlinker /path/lib -lpath1 -Wl,--whole-archive -lm \
+--Wl,--no-whole-archive -Xlinker -R -Xlinker /path/lib"
run_test --libs flag-dup-1 flag-dup-2
run_test --libs flag-dup-2 flag-dup-1
diff --git a/check/check-gtk b/check/check-gtk
index e42892b..7fd01bb 100755
--- a/check/check-gtk
+++ b/check/check-gtk
@@ -16,7 +16,8 @@ PKG_CONFIG_LIBDIR=${srcdir}/gtk
RESULT="-DGSEAL_ENABLE -pthread -I/gtk/include/gtk-3.0 \
-I/gtk/include/pango-1.0 -I/gtk/include/atk-1.0 -I/gtk/include/cairo \
-I/gtk/include/pixman-1 -I/gtk/include -I/gtk/include/gdk-pixbuf-2.0 \
--I/gtk/include/glib-2.0 -I/gtk/lib/glib-2.0/include -I/gtk/include/freetype2"
+-I/gtk/include -I/gtk/include/pango-1.0 -I/gtk/include/glib-2.0 \
+-I/gtk/lib/glib-2.0/include -I/gtk/include/freetype2 -I/gtk/include"
run_test --cflags gtk+-3.0
run_test --cflags --static gtk+-3.0
@@ -28,7 +29,8 @@ run_test --cflags --static gtk+-3.0
# -lglib-2.0
RESULT="-L/gtk/lib -lgtk-3 -lgdk-3 -lpangocairo-1.0 -latk-1.0 -lcairo-gobject \
-lcairo -lgdk_pixbuf-2.0 -lgio-2.0 -lpangoft2-1.0 -lpango-1.0 -lgobject-2.0 \
--lgthread-2.0 -lgmodule-2.0 -pthread -lrt -lglib-2.0 -lfreetype -lfontconfig"
+-lgthread-2.0 -pthread -lrt -lgmodule-2.0 -pthread -lrt -lglib-2.0 -lfreetype \
+-lfontconfig"
if [ "$list_indirect_deps" = no ]; then
run_test --libs gtk+-3.0
fi
@@ -47,10 +49,10 @@ fi
# -lpango-1.0 -lfontconfig -lexpat -lfreetype -lgobject-2.0 -lffi \
# -lgmodule-2.0 -ldl -lgthread-2.0 -lglib-2.0 -lrt
RESULT="-L/gtk/lib -lgtk-3 -lgdk-3 -lpangocairo-1.0 -latk-1.0 -lcairo-gobject \
--lcairo -lpixman-1 -lXrender -lX11 -lpthread -lxcb -lXau -lgdk_pixbuf-2.0 \
--lpng12 -lm -lgio-2.0 -lz -lresolv -lpangoft2-1.0 -lpango-1.0 -lgobject-2.0 \
--lffi -lgthread-2.0 -lgmodule-2.0 -pthread -ldl -lglib-2.0 -lrt -lfontconfig \
--lexpat -lfreetype"
+-lcairo -lz -lpixman-1 -lpng12 -lz -lm -lXrender -lX11 -lpthread -lxcb -lXau \
+-lgdk_pixbuf-2.0 -lm -lpng12 -lz -lm -lgio-2.0 -lz -lresolv -lpangoft2-1.0 \
+-lpango-1.0 -lgobject-2.0 -lffi -lgthread-2.0 -pthread -lrt -lgmodule-2.0 \
+-pthread -lrt -ldl -lglib-2.0 -lrt -lfreetype -lfontconfig -lexpat -lfreetype"
if [ "$list_indirect_deps" = yes ]; then
run_test --libs gtk+-3.0
fi
diff --git a/pkg.c b/pkg.c
index 7cd48d4..45ac840 100644
--- a/pkg.c
+++ b/pkg.c
@@ -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);