Bug 10640 - pkgconfig sorts --cflags and --libs incorrectly when multiple packages are given
Summary: pkgconfig sorts --cflags and --libs incorrectly when multiple packages are given
Status: RESOLVED WONTFIX
Alias: None
Product: pkg-config
Classification: Unclassified
Component: src (show other bugs)
Version: unspecified
Hardware: All All
: medium normal
Assignee: Tollef Fog Heen
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2007-04-13 12:37 UTC by Peter O'Gorman, The Written Word, Inc.
Modified: 2011-01-13 10:27 UTC (History)
1 user (show)

See Also:
i915 platform:
i915 features:


Attachments
Patch to make pkg.c sort output in order packages were given (2.00 KB, text/x-patch)
2007-04-13 12:42 UTC, Peter O'Gorman, The Written Word, Inc.
Details
new pkg.c patch that does not include unnecessary chunk (1.65 KB, patch)
2007-04-15 09:20 UTC, Peter O'Gorman, The Written Word, Inc.
Details | Splinter Review
a working patch (1.44 KB, patch)
2007-07-20 09:22 UTC, Peter O'Gorman, The Written Word, Inc.
Details | Splinter Review

Description Peter O'Gorman, The Written Word, Inc. 2007-04-13 12:37:16 UTC
pkg-config doesn't deterministically list paths with --libs and
--cflags. We want an ordered listing. Consider the following:
  $ PKG_CONFIG_PATH=/opt/TWWfsw/libpango18/lib/pkgconfig:\
  /opt/TWWfsw/libglib26/lib/pkgconfig:\
  /opt/TWWfsw/fcpackage22/lib/pkgconfig:\
  /opt/TWWfsw/libttf21/lib/pkgconfig:/opt/TWWfsw/gettext014/lib/pkgconfig
  /opt/TWWfsw/pkgconfig/bin/pkg-config --cflags pangoxft
  -I/opt/TWWfsw/libpango18/include -I/opt/TWWfsw/libglib26/include
  -I/opt/TWWfsw/libglib26/lib/include -I/opt/TWWfsw/fcpackage22/include
  -I/opt/TWWfsw/libttf21/include/freetype2
  -I/opt/TWWfsw/gettext014/include  

  $ PKG_CONFIG_PATH=/opt/TWWfsw/libpango18/lib/pkgconfig:\
  /opt/TWWfsw/libglib26/lib/pkgconfig:\
  /opt/TWWfsw/fcpackage22/lib/pkgconfig:\
  /opt/TWWfsw/libttf21/lib/pkgconfig:/opt/TWWfsw/gettext014/lib/pkgconfig
  /opt/TWWfsw/pkgconfig/bin/pkg-config --cflags pangox
  -I/opt/TWWfsw/libpango18/include -I/usr/X11R6/include
  -I/opt/TWWfsw/libglib26/include -I/opt/TWWfsw/libglib26/lib/include
  -I/opt/TWWfsw/gettext014/include  

  $ PKG_CONFIG_PATH=/opt/TWWfsw/libpango18/lib/pkgconfig:\
  /opt/TWWfsw/libglib26/lib/pkgconfig:\
  /opt/TWWfsw/fcpackage22/lib/pkgconfig:\
  /opt/TWWfsw/libttf21/lib/pkgconfig:/opt/TWWfsw/gettext014/lib/pkgconfig
  /opt/TWWfsw/pkgconfig/bin/pkg-config --cflags pangoxft pangox
  -I/opt/TWWfsw/libpango18/include -I/usr/X11R6/include
  -I/opt/TWWfsw/libglib26/include -I/opt/TWWfsw/libglib26/lib/include
  -I/opt/TWWfsw/fcpackage22/include
  -I/opt/TWWfsw/libttf21/include/freetype2
  -I/opt/TWWfsw/gettext014/include  

Why isn't the output of the last command the --cflags of pangoxft
followed by the --cflags of pangox with duplicates in pangox removed?
Comment 1 Peter O'Gorman, The Written Word, Inc. 2007-04-13 12:42:26 UTC
Created attachment 9598 [details]
Patch to make pkg.c sort output in order packages were given

The attached patch fixes the issue for us.
Comment 2 Peter O'Gorman, The Written Word, Inc. 2007-04-15 09:20:23 UTC
Created attachment 9614 [details] [review]
new pkg.c patch that does not include unnecessary chunk
Comment 3 Peter O'Gorman, The Written Word, Inc. 2007-07-20 09:22:04 UTC
Created attachment 10814 [details] [review]
a working patch

It helps if the patch actually works :)
Comment 4 Daniel Macks 2007-08-30 11:51:18 UTC
pangox specifies that the -I for X11R6 comes before the -I for libglib26 but pangoxft does not specify -I for X11R6 at all. Your proposed bahavior for "pkgconfig pangoxft pangox" sounds like -I for libglib26 would come first (since they are triggered by pangoxft, which is listed first), and then X11R6 would come later (since it's triggered by pangox, which is listed later, and is not a dup of an earlier flag). Is swapping flag ordering a good idea?
Comment 5 Peter O'Gorman, The Written Word, Inc. 2007-08-30 12:12:27 UTC
(In reply to comment #4)
> pangox specifies that the -I for X11R6 comes before the -I for libglib26 but
> pangoxft does not specify -I for X11R6 at all. Your proposed bahavior for
> "pkgconfig pangoxft pangox" sounds like -I for libglib26 would come first
> (since they are triggered by pangoxft, which is listed first), and then X11R6
> would come later (since it's triggered by pangox, which is listed later, and is
> not a dup of an earlier flag). Is swapping flag ordering a good idea?

The -I/usr/X11R6/include part of the issue here, it means that include files in that directory are being included in preference to the ones that are referenced by , for example, the fcpackage22 package. With the attached patch, the output is (we updated some packages):
-I/opt/TWWfsw/libpango18/include
-I/opt/TWWfsw/libglib26/include
-I/opt/TWWfsw/libglib26/lib/include
-I/opt/TWWfsw/fcpackage22/include
-I/opt/TWWfsw/libttf23/include/freetype2
-I/opt/TWWfsw/libttf23/include
-I/opt/TWWfsw/gettext014/include
-I/usr/X11R6/include  

So, now the compiler will see the same files as it would if you had done:
CFLAGS = `pkg-config --cflags pangoxft`
CFLAGS += `pkg-config --cflags pangox`

Which is what we want.
Comment 6 Daniel Macks 2007-08-30 12:48:23 UTC
I just discussed this with Peter, and we are unable to agree on what the "correct" order of flags should be when multiple packages are specified to a single pkgconfig command. Here's our chatlog:

<dmacks> pogma: /me if pangox wants X11R6 headers in preference to libglib26's, why should requesting flags for "pangoxft and pangox" discard that preference?

<pogma> dmacks: if you want to do that change the order that you request them

<dmacks> ?

<dmacks> I don't think requester should have to know the preferences/precedences/etc of what he's requesting.

<pogma> if you do pkg-config --cflags pangox pangoxft and pkg-config pangoxft pangox, you will get a different inclde order

<dmacks> Do either of those results violate the ordering within either one's results?

<dmacks> What the hell is the utility program that takes a list of ordered pairs and makes a single list that preserves all orderings?

<pogma> dmacks: We simply want the same files to be found had you invoked pkg-config multiple times, once per package. pkg-config currently does some non-deterministic thing

<dmacks> Well it's gotta be deterministic'ed by *something*. How does it choose?

<dmacks> (seems like "pc foo bar" is requesting a coherent set of flags for the two of them, not simply stringing one after the other.

<dmacks> Ahah! "tsort"

<pogma> dmacks: So it is an argument about whether tsort is the better method for -I flags

<dmacks> pogma: I think so. I don't actually have a clue what the existing logic is, but given the choice between "foo bar" listing all of foo followed by all of bar (with dups removed) vs tsorting, I'd say tsort.
Comment 7 Peter O'Gorman, The Written Word, Inc. 2011-01-13 10:27:09 UTC
Seems pointless to leave this open


Use of freedesktop.org services, including Bugzilla, is subject to our Code of Conduct. How we collect and use information is described in our Privacy Policy.