Remove duplicate packages after resolving requires

Makes the resolved package list be correctly serialized with each
package only appearing once. This provides more consistency between the
various flag outputs by ensuring that the flags from each package are
only grabbed once. This makes a difference since the duplicate flag
stripping happens from the end of the output (-l) or the beginning of
the output (-L/-I/other).
This commit is contained in:
Dan Nicholson 2012-11-15 06:32:36 -08:00
parent e8086bc54f
commit 428362266e
3 changed files with 47 additions and 5 deletions

View file

@ -6,7 +6,6 @@ set -e
RESULT="-DPATH2 -DFOO -DPATH1 -I/path/include"
run_test --cflags flag-dup-1 flag-dup-2
RESULT="-DPATH1 -DFOO -DPATH2 -I/path/include"
run_test --cflags flag-dup-2 flag-dup-1
RESULT="-Wl,--whole-archive --Wl,--no-whole-archive -Xlinker -R /path/lib \

View file

@ -14,10 +14,9 @@ PKG_CONFIG_LIBDIR=${srcdir}/gtk
# -I/gtk/include/glib-2.0 -I/gtk/lib/glib-2.0/include -I/gtk/include/pixman-1 \
# -I/gtk/include -I/gtk/include/freetype2
RESULT="-DGSEAL_ENABLE -pthread -I/gtk/include/gtk-3.0 \
-I/gtk/include/pango-1.0 -I/gtk/include -I/gtk/include/freetype2 \
-I/gtk/include/glib-2.0 -I/gtk/lib/glib-2.0/include \
-I/gtk/include/gdk-pixbuf-2.0 -I/gtk/include/cairo -I/gtk/include/pixman-1 \
-I/gtk/include/atk-1.0"
-I/gtk/include/pango-1.0 -I/gtk/include/atk-1.0 -I/gtk/include/cairo \
-I/gtk/include/gdk-pixbuf-2.0 -I/gtk/include -I/gtk/include/freetype2 \
-I/gtk/include/pixman-1 -I/gtk/include/glib-2.0 -I/gtk/lib/glib-2.0/include"
run_test --cflags gtk+-3.0
run_test --cflags --static gtk+-3.0

44
pkg.c
View file

@ -671,6 +671,43 @@ merge_flag_lists (GList *packages, GetListFunc func, GList **listp)
}
}
/* Work backwards from the end of the package list to remove duplicate
* packages. This could happen because the package was specified multiple
* times on the command line, or because multiple packages require the same
* package. When we have duplicate dependencies, starting from the end of the
* list ensures that the dependency shows up later in the package list and
* Libs will come out correctly. */
static GList *
package_list_strip_duplicates (GList *packages)
{
GList *cur;
GHashTable *requires;
requires = g_hash_table_new (g_str_hash, g_str_equal);
for (cur = g_list_last (packages); cur != NULL; cur = g_list_previous (cur))
{
Package *pkg = cur->data;
if (g_hash_table_lookup (requires, pkg->key) != NULL)
{
GList *dup = cur;
/* Remove the duplicate package from the list */
debug_spew ("Removing duplicate package %s\n", pkg->key);
cur = cur->next;
packages = g_list_delete_link (packages, dup);
}
else
{
/* Unique package. Track it and move to the next. */
g_hash_table_insert (requires, pkg->key, pkg);
}
}
g_hash_table_destroy (requires);
return packages;
}
static void
fill_list (GList *packages, GetListFunc func,
GList **listp, gboolean in_path_order, gboolean include_private)
@ -689,6 +726,13 @@ fill_list (GList *packages, GetListFunc func,
tmp = tmp->next;
}
/* Remove duplicate packages from the recursive list. This should provide a
* serialized package list where all interdependencies are resolved
* consistently. */
spew_package_list (" pre-remove", expanded);
expanded = package_list_strip_duplicates (expanded);
spew_package_list ("post-remove", expanded);
if (in_path_order)
{
spew_package_list ("original", expanded);