Commit graph

83 commits

Author SHA1 Message Date
Dan Nicholson
43f20b96a3 Fix one hash table optimization to use key=value
Commit 428335e changed some hash tables to be used as sets where the key
equals the value since glib has some optimization for that.
Unfortunately, the package list stripping table wasn't fixed corectly.
2012-12-04 13:04:01 -08:00
Dan Nicholson
428335e2b5 Optimize hash table when usage is only as a set
When searching for duplicate strings in the output list, a hash table is
used to keep track of which strings have been seen. This usage as a set
can be optimized as described in the documentation to not allocate or
free the hash table values:

http://developer.gnome.org/glib/stable/glib-Hash-Tables.html#glib-Hash-Tables.description
2012-12-03 08:25:40 -08:00
Dan Nicholson
a7b465806f Remove duplicate string list elements in place
Similar to the removal of duplicate packages, this can be more efficient
if we don't build a new list and instead just remove the elements in
place.
2012-12-03 07:34:00 -08:00
Dan Nicholson
360a614af8 Start from end of package lists when processing Requires
Prior to commit 6ecf318, the resolved list of required packages was
built in an appending way where each package on the command line or in
Requires would appear in the list in the order they appeared. With
6ecf318, that list building was changed to prepending, which had a
subtle change on the resolved order.

For example, suppose package a has "Requires: b c d". Previously, the
list would be built as a->b->c->d by appending each as they were
encountered. Now, the list is built by walking all the way down the
dependency chain for each package in a depth first manner and prepending
packages while unwinding. This would result in the package ilst being
a->d->c->b. This same effect happens with the command line packages
where previously requesting packages x and y would create a package list
of x->y and now produces a list of y->x.

While technically these should be the same since there are no
interdependencies, it's causes flags to be output in different order
than previously in pkg-config. This can be seen most readily in the
check-gtk test.

Instead, operate on the package lists backwards when building the
resolved package list.
2012-12-03 07:08:20 -08:00
Dan Nicholson
be455b79fe Traverse list backwards instead of copying and reversing
Walking a GSList backwards involved copying and reversing it so that the
the original list could remain undisturbed. This is wasteful with a
GList where we can just start at the end of the list and work backwards.
2012-12-03 07:05:43 -08:00
Dan Nicholson
428362266e 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).
2012-12-03 07:05:43 -08:00
Dan Nicholson
e8086bc54f Convert to doubly-linked GList
Using a doubly-linked list allows it to be easily traversed in both
directions and makes removing nodes in place much simpler. This adds an
extra pointer to each node and associated manipulation during any list
processing, but this trade seems acceptable over the repeated hacks to
work with singly-linked lists.
2012-12-03 07:02:27 -08:00
Dan Nicholson
840cf3c97e Use standard GSList functions to merge package lists
Using the GSList functions instead of manually adjusting the list
pointers seems safer and allows an easier path to using another glib
list type if necessary.
2012-11-29 05:54:29 -08:00
Dan Nicholson
e2910a6afd Remove extra spaces from list debugging output
Also, make pre- and post-sorting output aligned to easily ordering
differences.
2012-11-28 05:41:10 -08:00
Dan Nicholson
1d285978bb Use package filename rather than Name in debugging
The Package key member corresponds to the module filename with the .pc
stripped off while the name member corresponds to the Name field in the
.pc file. The latter is almost never used in practice and just makes
debugging more difficult.
2012-11-28 05:41:05 -08:00
Dan Nicholson
90ed8f193f Allow all combinations of --cflags and --libs variants
Use a bitmask to keep track of what Libs/Cflags to output. This makes it
simple to handle any combination of --cflags and --libs option variants.
A lot of excess code is removed in the process as all the flags options
can now be carried around in a single variable.

Freedesktop #54388 (https://bugs.freedesktop.org/show_bug.cgi?id=54388)
2012-11-03 11:07:59 -07:00
Dan Nicholson
90e0ec0f6f Nest copying and merging of flags to avoid repeated traversals
When merging the flags from all the packages together, each flags list
was being copied and then concatenated to then end of the combined list.
This was extremely inefficient because it caused the combined list to be
traversed multiple times to find the end. Instead, nest the copying and
merging of the flags together so the last element is always tracked and
can easily be appended to.

Freedesktop #54716 (https://bugs.freedesktop.org/show_bug.cgi?id=54716)
2012-10-30 06:01:42 -07:00
Dan Nicholson
3aa62167be Only match uninstalled packages that end in "-uninstalled" with hyphen
pkg-config(1) states that installed packages should be appended with
"-uninstalled". However, the code was checking only for trailing
"uninstalled" without the hyphen. Make the code consistent with the
documentation.

Freedesktop #54379
2012-10-13 09:25:34 -07:00
Dan Nicholson
6d6dd43e75 Support circular Requires loops
After the packages are parsed, pkg-config recurses through all the
required packages to generate one list. Before descending another level,
check to see if the package has already been handled and skip it. This
allows packages to require each other circularly by breaking the loop.

A test has been added resolving a two level deep circular dependency.

Freedesktop #7331
2012-10-13 08:14:35 -07:00
Dan Nicholson
3f1f6e79b7 Delay converting Requires entries to Packages until after parsing
When the parser encounters Requires or Requires.private, it immediately
tries to sees if we have a parsed package for that entry. If not it
tries to locate the needed file and parse it out. If there's a circular
dependency, this will eventually error opening too many files.

Instead, just store the requires entries so the parsing completes and
the package is added to the database. After parsing, the entries can be
resolved into Packages and any circular requires entries will find the
first package in the database.

This is a partial fix for Freedesktop #7331.
2012-10-13 08:14:35 -07:00
Dan Nicholson
6ecf318c92 Consistently resolve requires depth-first to fix non-l flag ordering
recursive_fill_list() is used to order Requires and Requires.private,
but it relied on fill_one_level() to make the list adjustments as it
descended the package tree. There were two issues with this approach:

1. It added all the dependencies from a package immediately rather than
   descending through each dependency first. This made it sort of mix
   between depth- and breadth-first resolving.

2. It did not add the requested package to the list, forcing the caller
   to add it.

This simplifies the code so that it descends all the way to the least
dependent package and prepends them as it unwinds. This ensures the
ordering will be sorted from most dependent to least dependent package.

Ordering of -l flags is corrected by a later sorting, but this fixes
ordering on non-l flags. Add a new test specifically for non-l Libs
flags.

Freedesktop #34504
2012-10-13 08:14:35 -07:00
Dan Nicholson
02ca585fa6 Make sure recursion only happens with requires
The function recursive_fill_list() is designed to descend lists of
packages, so it only makes sense to use with Requires and
Requires.private. Ensure it to make later code additions simpler.
2012-10-13 08:14:35 -07:00
Dan Nicholson
e12f8f17a2 Kill a bunch of unused code
From what I can tell, these single package variants have never been used
going back to pkg-config-0.4.0. pkg-config always uses the multipackage
versions that loop over the list of supplied packages.
2012-10-03 05:33:32 -07:00
Dan Nicholson
dfd03ae23e Use g_alloca instead of fooling around with platforms ourselves
Glib has been providing a g_alloca wrapper that handles all the platform
specifics since at least glib-1.3. Use it.
2012-05-29 16:41:17 -07:00
LRN
7ac6f32625 Don't use deprecated glib function to construct path on win32
g_win32_get_package_installation_subdirectory() has been deprecated
since GLib 2.18 and in recent (2.31) GLib versions disabled entirely by
default. This patch replaces usage of that function by
g_win32_get_package_installation_directory_of_module() and
g_build_filename(). Use the new functions and rework the code a bit so
it leaks less memory.

g_win32_get_package_installation_directory_of_module() is supported
since GLib 2.16. The minimal GLib version is bumped accordingly.

Freedesktop #45742
2012-05-21 21:08:49 -07:00
Dan Nicholson
02d99c6ab1 Use glib to parse argv strings instead of popt
Glib's g_shell_parse_argv offers basically a 1:1 replacement for
poptParseArgvString except that you have to free all the elements of
the array explicitly.
2012-05-14 14:19:10 -07:00
Tollef Fog Heen
b02c40bca4 Only treat real files (or symlinks to real files) as .pc files
Ignore any dangling symlinks.  Thanks to Ciaran Anscomb for patch
inspiration.

Fixes Freedesktop #23922
2011-05-15 14:08:21 +02:00
Tollef Fog Heen
7c45ef3c84 Drop dead code 2011-05-15 11:05:42 +02:00
Simon McVittie
01005bbbd0 Add --with-system-include-path etc.
Instead of hard-coding /usr/include, we now use the environment variable
PKG_CONFIG_SYSTEM_INCLUDE_PATH, defaulting to the argument of
./configure --with-system-include-path, which in turn defaults to
/usr/include.

Similarly, PKG_CONFIG_SYSTEM_LIBRARY_PATH defaults to /usr/lib or
/usr/lib:/usr/lib64 as appropriate.

(As currently implemented, this causes a behaviour change on Win32 -
the option -I/usr/include will now be filtered out.)

The intended usage is for Debian to configure pkg-config with
--with-system-include-path=/usr/include/$(DEB_HOST_GNU_TYPE):/usr/include
and the corresponding library path, for multiarch support
(<http://bugs.debian.org/482884>).

Based on work by Colin Walters <walters@verbum.org>
2011-04-13 22:56:53 +02:00
Tollef Fog Heen
03bd4a5528 Drop support for legacy -config scripts
We used to call gnome-config, gtk-config, glib-config and so on, which
was useful in the beginning of pkg-config.  This hasn't served any
practical purpose in recent years, so drop the support.
2010-09-01 20:48:57 +02:00
Tollef Fog Heen
726f8e4c13 Update rpmvercmp with bugfixes from RPM
Grab two minor bugfixes from RPM's rpmvercmp.
2010-05-08 22:15:36 +02:00
Tollef Fog Heen
66d49f1375 Clean up sysroot support a little bit
This should fix bug #16905 properly.
2009-12-06 22:40:13 +01:00
Tollef Fog Heen
2896188180 Constify a variable
Thanks to J.H.M. Dassen (Ray)
Bug #190
2009-12-06 22:08:21 +01:00
Tollef Fog Heen
e170895bc6 2009-03-30 Tollef Fog Heen <tfheen@err.no>
* pkg.c (add_virtual_pkgconfig_package): Add pc_path as a variable
	which you can use to get at the compiled-in PKG_CONFIG_PC_PATH.
2009-03-30 21:17:43 +02:00
Tollef Fog Heen
c5b07b4720 2009-03-30 Tollef Fog Heen <tfheen@err.no>
* pkg.c (add_virtual_pkgconfig_package): Fix URL to pkg-config.
2009-03-30 21:04:42 +02:00
Tollef Fog Heen
2e0493a343 2009-03-30 Tollef Fog Heen <tfheen@err.no>
* poptparse.c, popthelp.c, poptconfig.c, popt.c, pkg.c, findme.c,
	configure.in: Check for malloc.h and use that if it exists.
	Apparently this makes Win32 happier.  Thanks to Carlo Bramini for
	the patch.
2009-03-30 21:00:14 +02:00
Tollef Fog Heen
669bfe2e0d 2009-03-30 Tollef Fog Heen <tfheen@err.no>
* pkg.[ch], main.c, check/check-missing: Don't recurse Requires at
	all unless we need to.  Add check.  Again, thanks to Loïc Minier
	for most of the idea and the implementation.
2009-03-30 20:49:17 +02:00
Tollef Fog Heen
02d5ae3fb6 2009-03-30 Tollef Fog Heen <tfheen@err.no>
* pkg.[ch], parse.[ch], main.c, check/Makefile.am,
	check/check-missing, check/missing-requires-private.pc:
	Skip Requires.private unless we need to look at them for cflags.
	Add test case.  Thanks to Loïc Minier for most of the idea and the
	implementation.  Debian #475031
2009-03-30 20:40:53 +02:00
Tollef Fog Heen
69dafea1c8 2008-03-23 Tollef Fog Heen <tfheen@err.no>
* check/check-conflicts, check/conflicts-test.pc: New test,
       testing that conflicts work as they should.

       * pkg.c (verify_package): Make the conflicts check not only check
       package versions, but also package names.  This makes conflicts
       functional, something they were not before.
2008-03-23 21:39:07 +01:00
Tollef Fog Heen
3e6c5da35a pkg.c (string_list_to_string): Patch from Paul Bender so flags other
than -I and -L are passed through (with mangling) when
PKG_CONFIG_SYSROOT_DIR is set.
2008-01-31 02:27:33 +01:00
Tollef Fog Heen
ed75a7dd4b 2008-01-16 Tollef Fog Heen <tfheen@err.no>
* pkg.h, pkg.c (string_list_to_string), pkg-config.1, main.c
             (main): Add sysroot support and document same.  Triggered by
             setting PKG_CONFIG_SYSROOT_DIR in the environment.
2008-01-16 23:10:25 +01:00
Tollef Fog Heen
138f9219b4 * pkg.c (internal_get_package): Don't add the internal-only
pkg-config package twice.
2007-12-29 17:49:50 +01:00
Tollef Fog Heen
a376c715ea * pkg.c (verify_package): Apply patch from Matthias Clasen of
RedHat to prevent segfaults if a Conflicts line is encountered.
2007-12-29 16:46:25 +01:00
Tollef Fog Heen
8ac159cd5e * pkg.c (recursive_fill_list): Make sure to act recursively with
Requires.private, making them much more useful.  Special thanks to
Matthias Clasen for lots and lots of nagging.  Freedesktop #8788
2007-06-18 23:19:27 +02:00
Tollef Fog Heen
92d4e25061 2007-02-25 Tollef Fog Heen <tfheen@err.no>
* pkg.c (scan_dir): Use g_malloc, not malloc for pkgname.
2007-02-25 15:12:40 +01:00
Tollef Fog Heen
eae3abf93e 2006-08-16 Tollef Fog Heen <tfheen@err.no>
* pkg.c: Add internal pkg-config package which can be queried for
	version number, name and URL for now.  More information will be
	added later.
2006-08-16 21:04:56 +02:00
Tollef Fog Heen
0936824bf0 2006-08-16 Tollef Fog Heen <tfheen@err.no>
* pkg.c (packages_get_other_cflags, package_get_other_cflags)
	(packages_get_I_cflags): Always add all cflags.  Debian #340904
2006-08-16 20:42:38 +02:00
Tollef Fog Heen
ec5f06d60f Add --short-errors
2005-10-16  Tollef Fog Heen  <tfheen@err.no>

	* pkg.c (get_package_quiet): Add get_package_quiet which is just
	the same as get_package except it sets warn to false.

	* pkg.h: Add prototype for get_package_quiet.

	* main.c (main): Add --short-errors flag to suppress most of the
	output when a module is not found.
2005-10-16 17:31:41 +00:00
Tollef Fog Heen
6b35e49c2d Handle \ correctly on win32
2005-10-01  Tollef Fog Heen  <tfheen@err.no>

        * pkg.c(scan_dir): Turn backslashes into slashes or
        poptParseArgvString() will eat them when ${prefix} has been
        expanded in parse_libs().  Thanks to j^ for the patch.
2005-10-01 10:24:02 +00:00
Tollef Fog Heen
6d840e7046 Fix possible off-by-one
Apply last part of patch from freedesktop #4034 so we don't do silly
things if len is zero.
2005-10-01 10:13:57 +00:00
Arch Librarian
f4ef194406 2005-07-15 Tollef Fog Heen <tfheen@err.no>
Author: tfheen
Date: 2005-07-15 08:22:55 GMT
2005-07-15  Tollef Fog Heen  <tfheen@err.no>

        * pkg.c (package_get_var): Make sure to g_strdup all the return
        values and not return some values which should not be freed and
        some which should.  Yay valgrind.  Freedesktop #3682
2005-07-15 13:08:02 +00:00
Arch Librarian
29afc67918 2005-06-27 Tollef Fog Heen <tfheen@err.no>
Author: tfheen
Date: 2005-06-27 19:53:05 GMT
2005-06-27  Tollef Fog Heen  <tfheen@err.no>

    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
2005-07-14 13:07:31 +00:00
Arch Librarian
20d118d57a 2005-05-21 Tollef Fog Heen <tfheen@err.no>
Author: tfheen
Date: 2005-05-21 09:14:47 GMT
2005-05-21  Tollef Fog Heen  <tfheen@err.no>

    * check/check-libs-private: New test to check for support for
    private libraries.

    * check/simple.pc (prefix): Add Libs.private header.

    * check/Makefile.am (TESTS): Add check-libs-private test

    * pkg.h: Adjust function prototypes.

    * pkg.c: Add global ignore_private_libs variable.
    (scan_dir): Use the correct free function.  Stop leaking file
    descriptors.
    (package_get_l_libs, packages_get_l_libs, package_get_L_libs,
    packages_get_L_libs): Stop the recursive silliness and go back to
    old behaviour.
    (packages_get_all_libs): Adjust parameters to packages_get_*_libs
    (enable_private_libs, disable_private_libs): Trivial helper
    functions.

    * pkg-config.1: Update documentation wrt search path (Debian
    #308942), update docs for Libs.private and add the problematic
    handling of mixing = and non-= arguments to the bugs section.

    * parse.h: Adjust parameters for parse_package_file to get private
    libs or not.

    * parse.c (trim_and_sub): Fix memory leak.
    (_do_parse_libs): New function including what's common between
    parse_libs and parse_private_libs.
    (parse_libs_private): New function.  Handle private libraries.
    (parse_line): Add . to the list of valid characters in headers (so
    Libs.private works correctly.
    (parse_line): Fix memory leaks.
    (parse_line): Handle Libs.private.
    (parse_package_file): Fix memory leak.

    * main.c (main): Fix memory leak.

    * NEWS: Document changes to inter-library handling.

    * main.c (main): Handle inter-library dependencies old-style, but
    do private libraries too.  Adjust parameters to
    packages_get_*_libs.

    * configure.in: Change comment wrt inter-library handling to talk
    about private libraries instead.
2005-07-14 13:07:18 +00:00
Arch Librarian
6c3ec8f447 2005-04-13 Tollef Fog Heen <tfheen@err.no>
Author: tfheen
Date: 2005-04-13 15:47:18 GMT
2005-04-13  Tollef Fog Heen  <tfheen@err.no>

    * pkg.c (packages_get_l_libs, packages_get_L_libs): Duplicate
    singly linked list before putting it on list passed to
    string_list_strip_duplicates_from_back to avoid infinite loop when
    g_slist_copy tries to copy self-linked list.  This happens if the
    user specifies the same name on the command line twice.
2005-07-14 13:07:07 +00:00
Arch Librarian
986e4ebb03 2005-04-01 Tollef Fog Heen <tfheen@err.no>
Author: tfheen
Date: 2005-04-01 21:46:07 GMT
2005-04-01  Tollef Fog Heen  <tfheen@err.no>

    * configure.in: Try to detect whether this architecture supports
    inter-library dependencies.  If so, we default to assuming that
    this support is used and link to the minimal set of libraries
    rather than traversing the full depends set.

    * main.c (main): Only recurse if we want a static library list or
    if this architecture doesn't support inter-library dependencies.
    This will probably expose bugs for libraries which declare
    dependencies in their .pc files but don't actually link against
    each other.

    * pkg.c (packages_get_all_libs): Add recurse option
    (packages_get_L_libs): Add recurse option
    (package_get_L_libs): Add recurse option
    (packages_get_l_libs): Add recurse option
    (package_get_l_libs): Add recurse option

    * pkg.h: Update prototypes to handle the recurse option.
2005-07-14 13:06:42 +00:00