From: Arch Librarian Date: Thu, 14 Jul 2005 13:07:31 +0000 (+0000) Subject: 2005-06-27 Tollef Fog Heen X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=29afc67918972d43714dc271c5d5a8b32d2580e0;p=pkg-config 2005-06-27 Tollef Fog Heen Author: tfheen Date: 2005-06-27 19:53:05 GMT 2005-06-27 Tollef Fog Heen All those Requires.private changes are thanks to James Henstridge. Thanks! * check/private-dep.pc, check/public-dep.pc, check/requires-test.pc: New files, data for the check-requires-private test. * check/check-requires-private: New test to check for Requires.private support. * check/Makefile.am (EXTRA_DIST, TESTS): Add Requires.private test. * pkg.h (struct _Package): Add requires_private * pkg.c (get_requires_private, fill_list_single_package) (fill_list, verify_package, verify_package, get_merged) (get_merged_from_back, get_multi_merged) (get_multi_merged_from_back, package_get_l_libs) (packages_get_l_libs, package_get_L_libs, packages_get_L_libs) (package_get_other_libs, packages_get_other_libs) (package_get_I_cflags, packages_get_I_cflags) (package_get_other_cflags, packages_get_other_cflags): Handle private requires and cascading changes. * parse.c (parse_requires_private, parse_conflicts) (parse_package_file): Handle Requires.private --- diff --git a/ChangeLog b/ChangeLog index 7c74aac..caf8e3f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,33 @@ 2005-06-27 Tollef Fog Heen + All those Requires.private changes are thanks to James + Henstridge. Thanks! + + * check/private-dep.pc, check/public-dep.pc, + check/requires-test.pc: New files, data for the + check-requires-private test. + + * check/check-requires-private: New test to check for + Requires.private support. + + * check/Makefile.am (EXTRA_DIST, TESTS): Add Requires.private + test. + + * pkg.h (struct _Package): Add requires_private + + * pkg.c (get_requires_private, fill_list_single_package) + (fill_list, verify_package, verify_package, get_merged) + (get_merged_from_back, get_multi_merged) + (get_multi_merged_from_back, package_get_l_libs) + (packages_get_l_libs, package_get_L_libs, packages_get_L_libs) + (package_get_other_libs, packages_get_other_libs) + (package_get_I_cflags, packages_get_I_cflags) + (package_get_other_cflags, packages_get_other_cflags): Handle + private requires and cascading changes. + + * parse.c (parse_requires_private, parse_conflicts) + (parse_package_file): Handle Requires.private + * pkg.m4: Add PKG_CHECK_EXISTS to check if a module exists. Thanks to James Henstridge for the patch. diff --git a/check/Makefile.am b/check/Makefile.am index 94655f6..e2c15d9 100644 --- a/check/Makefile.am +++ b/check/Makefile.am @@ -1,3 +1,7 @@ -TESTS = check-cflags check-libs check-define-variable check-libs-private -EXTRA_DIST = $(TESTS) common simple.pc +TESTS = check-cflags check-libs check-define-variable \ + check-libs-private check-requires-private + +EXTRA_DIST = $(TESTS) common simple.pc requires-test.pc public-dep.pc \ + private-dep.pc + diff --git a/check/check-requires-private b/check/check-requires-private new file mode 100755 index 0000000..744d790 --- /dev/null +++ b/check/check-requires-private @@ -0,0 +1,27 @@ +#! /bin/sh + +set -e + +. ${srcdir}/common + +# expect cflags from requires-test and public-dep +ARGS="--cflags requires-test" +RESULT="-I/requires-test/include -I/public-dep/include" +run_test + +# still expect those cflags for static linking case +ARGS="--static --cflags requires-test" +RESULT="-I/requires-test/include -I/public-dep/include" +run_test + +# expect libs for just requires-test and public-dep +ARGS="--libs requires-test" +RESULT="-L/requires-test/lib -L/public-dep/lib -lrequires-test -lpublic-dep" +run_test + +# expect libs for requires-test, public-dep and private-dep in static case +ARGS="--static --libs requires-test" +RESULT="-L/requires-test/lib -L/private-dep/lib -L/public-dep/lib -lrequires-test -lprivate-dep -lpublic-dep" +run_test + + diff --git a/check/private-dep.pc b/check/private-dep.pc new file mode 100644 index 0000000..cb40139 --- /dev/null +++ b/check/private-dep.pc @@ -0,0 +1,6 @@ +Name: Requires test package +Description: Dummy pkgconfig test package for testing Requires/Requires.private +Version: 1.0.0 +Libs: -L/private-dep/lib -lprivate-dep +Cflags: -I/private-dep/include + diff --git a/check/public-dep.pc b/check/public-dep.pc new file mode 100644 index 0000000..7350e5d --- /dev/null +++ b/check/public-dep.pc @@ -0,0 +1,6 @@ +Name: Requires test package +Description: Dummy pkgconfig test package for testing Requires/Requires.private +Version: 1.0.0 +Libs: -L/public-dep/lib -lpublic-dep +Cflags: -I/public-dep/include + diff --git a/check/requires-test.pc b/check/requires-test.pc new file mode 100644 index 0000000..ed836cf --- /dev/null +++ b/check/requires-test.pc @@ -0,0 +1,8 @@ +Name: Requires test package +Description: Dummy pkgconfig test package for testing Requires/Requires.private +Version: 1.0.0 +Requires: public-dep +Requires.private: private-dep +Libs: -L/requires-test/lib -lrequires-test +Cflags: -I/requires-test/include + diff --git a/parse.c b/parse.c index 5fae5c4..dbb14df 100644 --- a/parse.c +++ b/parse.c @@ -562,6 +562,55 @@ parse_requires (Package *pkg, const char *str, const char *path) pkg->requires = g_slist_reverse (pkg->requires); } +static void +parse_requires_private (Package *pkg, const char *str, const char *path) +{ + GSList *parsed; + GSList *iter; + char *trimmed; + + if (pkg->requires_private) + { + verbose_error ("Requires.private field occurs twice in '%s'\n", path); + + exit (1); + } + + trimmed = trim_and_sub (pkg, str, path); + parsed = parse_module_list (pkg, trimmed, path); + g_free (trimmed); + + iter = parsed; + while (iter != NULL) + { + Package *req; + RequiredVersion *ver = iter->data; + + req = get_package (ver->name); + + if (req == NULL) + { + verbose_error ("Package '%s', required by '%s', not found\n", + ver->name, pkg->name ? pkg->name : path); + + exit (1); + } + + if (pkg->required_versions == NULL) + pkg->required_versions = g_hash_table_new (g_str_hash, g_str_equal); + + g_hash_table_insert (pkg->required_versions, ver->name, ver); + + pkg->requires_private = g_slist_prepend (pkg->requires_private, req); + + iter = g_slist_next (iter); + } + + g_slist_free (parsed); + + pkg->requires_private = g_slist_reverse (pkg->requires_private); +} + static void parse_conflicts (Package *pkg, const char *str, const char *path) { @@ -896,10 +945,12 @@ parse_line (Package *pkg, const char *untrimmed, const char *path, gboolean igno parse_description (pkg, p, path); else if (strcmp (tag, "Version") == 0) parse_version (pkg, p, path); + else if (strcmp (tag, "Requires.private") == 0) + parse_requires_private (pkg, p, path); else if (strcmp (tag, "Requires") == 0) - { + { if (ignore_requires == FALSE) - parse_requires (pkg, p, path); + parse_requires (pkg, p, path); else goto cleanup; } @@ -1052,6 +1103,11 @@ parse_package_file (const char *path, gboolean ignore_requires, gboolean ignore_ path); g_string_free (str, TRUE); fclose(f); + + /* make ->requires_private include a copy of the public requires too */ + pkg->requires_private = g_slist_concat(pkg->requires_private, + g_slist_copy (pkg->requires)); + return pkg; } diff --git a/pkg.c b/pkg.c index 7a3c943..435a4b4 100644 --- a/pkg.c +++ b/pkg.c @@ -506,6 +506,12 @@ get_requires (Package *pkg) return pkg->requires; } +static GSList * +get_requires_private (Package *pkg) +{ + return pkg->requires_private; +} + static int pathposcmp (gconstpointer a, gconstpointer b) { @@ -590,7 +596,8 @@ recursive_fill_list (Package *pkg, GetListFunc func, GSList **listp) static void fill_list_single_package (Package *pkg, GetListFunc func, - GSList **listp, gboolean in_path_order) + GSList **listp, gboolean in_path_order, + gboolean include_private) { /* First we get the list in natural/recursive order, then * stable sort by path position @@ -601,7 +608,9 @@ fill_list_single_package (Package *pkg, GetListFunc func, /* Get list of packages */ packages = NULL; packages = g_slist_append (packages, pkg); - recursive_fill_list (pkg, get_requires, &packages); + recursive_fill_list (pkg, + include_private ? get_requires_private : get_requires, + &packages); if (in_path_order) { @@ -626,7 +635,7 @@ fill_list_single_package (Package *pkg, GetListFunc func, static void fill_list (GSList *packages, GetListFunc func, - GSList **listp, gboolean in_path_order) + GSList **listp, gboolean in_path_order, gboolean include_private) { GSList *tmp; GSList *expanded; @@ -636,7 +645,9 @@ fill_list (GSList *packages, GetListFunc func, while (tmp != NULL) { expanded = g_slist_append (expanded, tmp->data); - recursive_fill_list (tmp->data, get_requires, &expanded); + recursive_fill_list (tmp->data, + include_private ? get_requires_private : get_requires, + &expanded); tmp = tmp->next; } @@ -740,7 +751,7 @@ verify_package (Package *pkg) /* Make sure we have the right version for all requirements */ - iter = pkg->requires; + iter = pkg->requires_private; while (iter != NULL) { @@ -776,7 +787,7 @@ verify_package (Package *pkg) * (inefficient algorithm, who cares) */ - recursive_fill_list (pkg, get_requires, &requires); + recursive_fill_list (pkg, get_requires_private, &requires); recursive_fill_list (pkg, get_conflicts, &conflicts); requires_iter = requires; @@ -918,13 +929,15 @@ verify_package (Package *pkg) } static char* -get_merged (Package *pkg, GetListFunc func, gboolean in_path_order) +get_merged (Package *pkg, GetListFunc func, gboolean in_path_order, + gboolean include_private) { GSList *list; GSList *dups_list = NULL; char *retval; - fill_list_single_package (pkg, func, &dups_list, in_path_order); + fill_list_single_package (pkg, func, &dups_list, in_path_order, + include_private); list = string_list_strip_duplicates (dups_list); @@ -938,13 +951,15 @@ get_merged (Package *pkg, GetListFunc func, gboolean in_path_order) } static char* -get_merged_from_back (Package *pkg, GetListFunc func, gboolean in_path_order) +get_merged_from_back (Package *pkg, GetListFunc func, gboolean in_path_order, + gboolean include_private) { GSList *list; GSList *dups_list = NULL; char *retval; - fill_list_single_package (pkg, func, &dups_list, in_path_order); + fill_list_single_package (pkg, func, &dups_list, in_path_order, + include_private); list = string_list_strip_duplicates_from_back (dups_list); @@ -958,14 +973,15 @@ get_merged_from_back (Package *pkg, GetListFunc func, gboolean in_path_order) } static char* -get_multi_merged (GSList *pkgs, GetListFunc func, gboolean in_path_order) +get_multi_merged (GSList *pkgs, GetListFunc func, gboolean in_path_order, + gboolean include_private) { GSList *tmp; GSList *dups_list = NULL; GSList *list; char *retval; - fill_list (pkgs, func, &dups_list, in_path_order); + fill_list (pkgs, func, &dups_list, in_path_order, include_private); list = string_list_strip_duplicates (dups_list); @@ -979,14 +995,15 @@ get_multi_merged (GSList *pkgs, GetListFunc func, gboolean in_path_order) } static char* -get_multi_merged_from_back (GSList *pkgs, GetListFunc func, gboolean in_path_order) +get_multi_merged_from_back (GSList *pkgs, GetListFunc func, + gboolean in_path_order, gboolean include_private) { GSList *tmp; GSList *dups_list = NULL; GSList *list; char *retval; - fill_list (pkgs, func, &dups_list, in_path_order); + fill_list (pkgs, func, &dups_list, in_path_order, include_private); list = string_list_strip_duplicates_from_back (dups_list); @@ -1006,7 +1023,8 @@ package_get_l_libs (Package *pkg) * order, so static linking works. */ if (pkg->l_libs_merged == NULL) - pkg->l_libs_merged = get_merged_from_back (pkg, get_l_libs, FALSE); + pkg->l_libs_merged = get_merged_from_back (pkg, get_l_libs, FALSE, + !ignore_private_libs); return pkg->l_libs_merged; } @@ -1014,7 +1032,8 @@ package_get_l_libs (Package *pkg) char * packages_get_l_libs (GSList *pkgs) { - return get_multi_merged_from_back (pkgs, get_l_libs, FALSE); + return get_multi_merged_from_back (pkgs, get_l_libs, FALSE, + !ignore_private_libs); } char * @@ -1022,7 +1041,8 @@ package_get_L_libs (Package *pkg) { /* We want these in search path order so the -L flags don't override PKG_CONFIG_PATH */ if (pkg->L_libs_merged == NULL) - pkg->L_libs_merged = get_merged (pkg, get_L_libs, TRUE); + pkg->L_libs_merged = get_merged (pkg, get_L_libs, TRUE, + !ignore_private_libs); return pkg->L_libs_merged; } @@ -1030,14 +1050,15 @@ package_get_L_libs (Package *pkg) char * packages_get_L_libs (GSList *pkgs) { - return get_multi_merged (pkgs, get_L_libs, TRUE); + return get_multi_merged (pkgs, get_L_libs, TRUE, !ignore_private_libs); } char * package_get_other_libs (Package *pkg) { if (pkg->other_libs_merged == NULL) - pkg->other_libs_merged = get_merged (pkg, get_other_libs, TRUE); + pkg->other_libs_merged = get_merged (pkg, get_other_libs, TRUE, + !ignore_private_libs); return pkg->other_libs_merged; } @@ -1045,7 +1066,7 @@ package_get_other_libs (Package *pkg) char * packages_get_other_libs (GSList *pkgs) { - return get_multi_merged (pkgs, get_other_libs, TRUE); + return get_multi_merged (pkgs, get_other_libs, TRUE, !ignore_private_libs); } char * @@ -1088,7 +1109,7 @@ package_get_I_cflags (Package *pkg) { /* sort by path position so PKG_CONFIG_PATH affects -I flag order */ if (pkg->I_cflags_merged == NULL) - pkg->I_cflags_merged = get_merged (pkg, get_I_cflags, TRUE); + pkg->I_cflags_merged = get_merged (pkg, get_I_cflags, TRUE, FALSE); return pkg->I_cflags_merged; } @@ -1097,14 +1118,14 @@ char * packages_get_I_cflags (GSList *pkgs) { /* sort by path position so PKG_CONFIG_PATH affects -I flag order */ - return get_multi_merged (pkgs, get_I_cflags, TRUE); + return get_multi_merged (pkgs, get_I_cflags, TRUE, FALSE); } char * package_get_other_cflags (Package *pkg) { if (pkg->other_cflags_merged == NULL) - pkg->other_cflags_merged = get_merged (pkg, get_other_cflags, TRUE); + pkg->other_cflags_merged = get_merged (pkg, get_other_cflags, TRUE, FALSE); return pkg->other_cflags_merged; } @@ -1112,7 +1133,7 @@ package_get_other_cflags (Package *pkg) char * packages_get_other_cflags (GSList *pkgs) { - return get_multi_merged (pkgs, get_other_cflags, TRUE); + return get_multi_merged (pkgs, get_other_cflags, TRUE, FALSE); } char * diff --git a/pkg.h b/pkg.h index 774d896..02ff1f3 100644 --- a/pkg.h +++ b/pkg.h @@ -57,6 +57,7 @@ struct _Package char *url; char *pcfiledir; /* directory it was loaded from */ GSList *requires; + GSList *requires_private; GSList *l_libs; char *l_libs_merged; GSList *L_libs;