Commit graph

390 commits

Author SHA1 Message Date
Dan Nicholson
ec11c93ef8 Explicitly set --exists as the default option
This happened basically by accident before when "pkg-config foo" was run
because the code wouldn't find any options set and just fall through to
the end after processing the package arguments. However, it would act
differently in that Requires.private was only enabled with an explicit
--exists.
2012-12-11 11:59:40 -08:00
Dan Nicholson
d1b7dd42d1 Enforce exclusive output options
Currently, any output option (e.g., --version or --libs) will be set as
valid and what's output is at the mercy of the order of the output
handling code in main(). However, most combinations of output would make
no sense to be used together. For example, mixing --modversion and
--print-provides provides no way to differentiate between the output
from the options. Further, mixing --variable and --cflags currently
causes an error because there's no space separating the option outputs.

Instead, keep track of when an output option has been set and ignore
subsequent output options. There are currently two exceptions:

1. Any combination of --cflags* and --libs* are allowed.

2. Both --print-requires and --print-requires-private can be used
   together as the user may just not care which is private.

Freedesktop #54391 (https://bugs.freedesktop.org/show_bug.cgi?id=54391)
2012-12-11 11:59:40 -08:00
Dan Nicholson
469a3d6366 Use flags for --cflags/--libs options
With the output options gathered in a callback, we can be more clever
with the --cflags/--libs options and set the flags mask straight off
without using the intermediate booleans.
2012-12-11 11:59:40 -08:00
Dan Nicholson
d65b2e58d0 Handle output mode options in callback
This will provide one function to handle all the various options the
user could supply sanely.
2012-12-11 11:59:40 -08:00
Dan Nicholson
1b47b03c2a Convert ints used as bools to gbooleans
This matches the GOption documentation that G_OPTION_ARG_NONE should use
a gboolean.
2012-12-11 11:59:40 -08:00
Dan Nicholson
30e7f31318 Split out package processing to separate function to cleanup main
The code handling processing of the packages from the command line was
in an awkward block in main. Split it out to a separate function to keep
main mostly about output.
2012-12-11 11:59:40 -08:00
Dan Nicholson
a15bb1e72e Cleanup local variable declarations
Having the option entries within main and requiring the option variables
to be static is just wrong. Just declare them at file scope like every
other program does.
2012-12-11 11:59:40 -08:00
Dan Nicholson
cd2520a004 Fix hardcoded version if check-debug 2012-12-11 11:58:57 -08:00
Dan Nicholson
454dd17b30 Update README.win32 to reflect current pkg-config behavior
Freedesktop #54427 (https://bugs.freedesktop.org/show_bug.cgi?id=54427)
2012-12-08 19:57:17 -08:00
Dan Nicholson
30245b2a89 Document PKG*INSTALLDIR autoconf macros in manpage
Freedesktop #54463 (https://bugs.freedesktop.org/show_bug.cgi?id=54463)
2012-12-08 12:37:12 -08:00
Michał Sawicz
69beecddb5 Allow ~ through unescaped
freedesktop #57078 (https://bugs.freedesktop.org/show_bug.cgi?id=57078)
2012-12-08 12:11:55 -08:00
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
d6337ec986 Always use --static test results for indirect depencency results
Often the expected results for the indirect dependency tests fell behind
because it's not a typical test scenario. However, since the results are
always the same as --static, they can just use the same results and the
test can be run conditionally without --static based on configuration.
2012-11-29 19:18:41 -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
160177d8d2 Add a gtk testcase to provide something with complex interactions
The pkg-config testsuite has pretty good coverage of the implementation,
but it lacks a complex case that tests the interactions of non-trivial
.pc files. gtk is a very common package that meets this goal. This is a
snapshot from my F16 system, and it should provide a good way to see how
changes in the implementation regress a real world case.
2012-11-28 05:59:49 -08:00
Dan Nicholson
f5b93bf1b1 Test stripping of duplicate flags
pkg-config aggressively strips all duplicate arguments from the final
output it builds. This is not only and optimization, but it also allows
the flag ordering to work correctly when a package on the command line
is required by another on the command line.
2012-11-28 05:52:13 -08:00
Dan Nicholson
3e54448158 Test ordering of flags based on package depth and path
The current tests are good at checking whether gathering the Cflags or
Libs from one or two packages works correctly, but they don't check the
sorting algorithm much at all. In particular, the interactions between
the package order in the Requires chain and in the path can make the
sorting of the flags subtly different.
2012-11-28 05:52:06 -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
d630bf3c75 Remove pkg-config.in script
A relic from the past, the pkg-config.in script exists from a time when
pkg-config was implemented as a shell script. This time is long since
gone and the script is far different than the C implementation. Find it
in git if you want to see how a shell script once did pkg-config.
2012-10-31 08:36:57 -07:00
Dan Nicholson
d6a14488db Move --print-variables handling after --exists for consistency
The --print-variables output is inconsistent with other printing options
when --exists is supplied or not. Move the handling after --exists like
--print-requires and others requiring a valid package list so that
--exists is given it takes priority and exits early.

Freedesktop #54384 (https://bugs.freedesktop.org/show_bug.cgi?id=54384)
2012-10-30 17:54:55 -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
1184d2085a Don't crash on --print-variables when there are no variables
Apparently g_hash_table_foreach doesn't check for NULL input, so make
sure we don't call it to print the variables if the variable list is
empty.

Freedesktop #54721
2012-10-13 09:06:18 -07:00
Adrian Bunk
a14d489fbc remove the .cvsignore file
No longer needed after the switch to git.
2012-10-13 08:46:37 -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
6b07296902 Install pkg-config link with $host- prefix
If pkg-config is used in a multiarch or cross-compiling scenario it's
likely pkg-config needs to behave differently for each of them. It's
possible to handle this through environment variables with one
pkg-config, but another option is to have one pkg-config per platform,
each with the host alias prefixed to the program.

PKG_PROG_PKG_CONFIG supports this type of installation, and this is also
how autoconf/libtool handle other build tools like compilers and
linkers.

The host-prefixed tool is installed as a hardlink where supported and a
copy otherwise. This is how gcc handles it's host-prefixed versions.
This feature can be turned off by passing --disable-host-tool to
configure.

Freedesktop #130
2012-10-13 08:08:42 -07:00
Dan Nicholson
65e37fe303 check: Test version comparisons within Requires fields
Verification of versions in Requires and friends happens differently
than the version comparison for command-line packages.
2012-10-03 05:33:32 -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
9a54c588a5 check: Test all variants of --cflags and --libs
Make sure that the --*-only-* variants of --cflags and --libs do the
right thing. This should probably be extended to cover a chain of
packages to get the ordering right, but this is good for now.
2012-10-03 05:33:31 -07:00
Dan Nicholson
0a5d54d091 check: Ensure unknown options fail 2012-10-03 05:33:31 -07:00
Dan Nicholson
d4c0c14ba8 check: Ensure debugging output works correctly
This might be a little fragile, but it makes sure to exercise the
debug_spew function.
2012-10-03 05:33:31 -07:00
Dan Nicholson
4f7d2a1b28 check: Test -uninstalled functionality
Test the usage of -uninstalled packages with two .pc files: inst.pc and
inst-uninstalled.pc. pkg-config should prefer the -uninstalled version
unless PKG_CONFIG_DISABLE_UNINSTALLED is set. It should also use the
default value of pc_top_builddir unless PKG_CONFIG_TOP_BUILD_DIR is set.
2012-10-03 05:33:31 -07:00
Dan Nicholson
83aef0efd9 Fix formatting for --print-provides in man page 2012-10-03 05:33:31 -07:00
Dan Nicholson
4426d487eb check: Test sysroot support
Checks that pkg-config prepends PKG_CONFIG_SYSROOT_DIR to -I and -L when
they don't point to system directories.
2012-10-03 05:33:31 -07:00
Dan Nicholson
42f30aee2e check: Test pkg-config version
Test that --version prints the current version and
--atleast-pkgconfig-version validates it.
2012-10-02 05:51:22 -07:00
Dan Nicholson
aba2c047cf check: Enhance --print-requires tests
Make the --print-requires and --print-requires-private tests actually
resolve Requires and output a specific version test.
2012-10-02 05:51:22 -07:00
Dan Nicholson
0e6ea44d68 check: Check path handling
Add a test for pkg-config's path handling. The first test covers
PKG_CONFIG_PATH, and the second covers the built-in path. For this one
we need to unset the PKG_CONFIG_LIBDIR that normally is set during the
tests. Since we can't rely on the contents of the default path, we just
check to see that the built-in path matches what was specified in
configure. To do this, we need to add a bunch of variables to config.sh
so the variable resolves. These variables don't need to be exported,
though.
2012-10-02 05:51:22 -07:00
Dan Nicholson
c7e12356bc check: Exercise all printing options
Add tests for checking the output of various options that print
information. For --list-all, a subdirectory with only two packages has
been added so that its output doesn't change when more test packages are
added to the check directory.
2012-09-29 09:57:46 -07:00
Dan Nicholson
31a9f900e1 check: Test --define-variable corner cases 2012-09-29 09:09:30 -07:00