Bug 3571

Summary: pkg-config gets confused when paths contain whitespace
Product: pkg-config Reporter: Stefan Seefeld <seefeld>
Component: srcAssignee: Tollef Fog Heen <tfheen>
Status: RESOLVED FIXED QA Contact:
Severity: normal    
Priority: high CC: dmacks
Version: unspecified   
Hardware: All   
OS: All   
Whiteboard:
i915 platform: i915 features:
Attachments: patch to let pkg-config support variables containing whitespace

Description Stefan Seefeld 2005-06-17 21:52:03 UTC
pkg-config seems to get confused when variables in .pc files contain
whitespace. 
Example: I generate a .pc file from configure where the value
corresponds to a detected filename (such as 
build/temp.darwin-6.8-Power\ Macintosh-2.2).
I tried quoting ("") as well as escaping ('\') without success.
The documentation is silent on the matter.
Is there a workaround ?
Comment 1 Stefan Seefeld 2005-06-18 17:51:30 UTC
Created attachment 2917 [details]
Xorg log file

patch 1/2 to make pkgconfig pass quoted whitespace through
Comment 2 Stefan Seefeld 2005-06-18 17:52:30 UTC
Created attachment 2918 [details]
Testcase for the bug, sorry, that I've just pasted it in the report at first.

patch 2/2 to make pkgconfig pass quoted whitespace through
Comment 3 Stefan Seefeld 2005-06-18 17:57:32 UTC
Huh, it appears the attachments don't carry enough information to be useful.
The first applies to parse.c, the second to poptparse.c.

With these 'pkg-config --cflags ...' will output include and library paths 
with quoted whitespace ('\ '). I'm not sure whether this is sufficient / correct,
as pkg-config doesn't appear to have a test suite to look for regressions, and
the docs (man page) are unfortunately quite sparse.
Comment 4 James Henstridge 2005-06-27 20:37:22 UTC
If you want to produce a useful diff, pass the "-u" flag to diff (u==unified
diff).  This will include the file names and some context around the lines you
changed.  It would also be a good idea to concatenate the two unified diffs
before attaching them, since they will probably get reviewed as a unit.

Lastly, it would be good to make the diff against the latest version of the
software.
Comment 5 Stefan Seefeld 2005-08-12 23:07:31 UTC
I just now find the reply from James to my initial report / patches. For
some reason I didn't receive notification, even though my email appears to
be correct. FWIW.

I'm going to rewrite the patch against pkgconfig 0.19 and resubmit that.
Comment 6 Stefan Seefeld 2005-08-16 03:45:15 UTC
Created attachment 2890 [details]
patch to let pkg-config support variables containing whitespace

This tarball contains a patch to make pkg-config support whitespace in
variables,
together with a new test to demonstrate this feature.
It is a minimal patch to get the feature working. It still looks a bit fragile,

i.e. some cases may not work as expected. I modified 'parse_cflags' and 
'parse_libs' to not stop at whitespace while in quoted mode, and I modified
poptParseArgvString() to preserve quotation marks in the generated result.

Let me know if anything else is needed.

PS: the patch is against the current cvs version.
Comment 7 Daniel Macks 2005-09-08 21:56:15 UTC
Could gscanner be used to parse apart the lines into whitespace-delimited
chunks, with automatic quoted-string handling, instead of manually going through
character-by-character?
Comment 8 Stefan Seefeld 2005-09-26 12:27:56 UTC
I'm not sure whether the last comment was addressed at me. While I agree my patch
is a bit hacky (in particular since I patched code that seems to be a mirror of
some other library) I'm probably least suited to work on this feature, given my
lack of experience with GNOME APIs.
I hope the requested feature (and at least parts of this patch) will eventually
materialize in a release nevertheless, as unfortunately whitespace in file names
is more frequent than one would hope.
Meanwhile I'll have to work around this by not using pkg-config.
Comment 9 Daniel Macks 2005-09-26 13:07:40 UTC
My comment 7 was a general thought about the fundamental way pkg-config
currently parses lines (a custom-written parser that needs patches like this,
and perhaps non-obvious hoop-jumping by .pc file authors). I didn't mean it as a
critique of a patch that solves a specific problem with that existing parser.
I'm a Mac user and programmer who uses pkg-config, and I'm annoyed that OS X
makes such heavy use of whitespace in filenames because it exposes how few unix
programs deal with it cleanly.

While I was pondering, I thought "parsing a text string that contains tokens or
flags and possible token/flag arguments is by no means a rare or new task" and
noticed that glib, which pkgconfig already uses, already has some toolbox
routines that could be useful for a rewrite of the flag collection routines. If
someone wants to go crazy, the whole thing could *maybe* even be rewritten using
something as simple as getopt_long().
Comment 10 Murray Cumming 2009-03-20 03:41:38 UTC
Isn't a maintainer interested in this bug?
Comment 11 Murray Cumming 2010-05-04 05:03:32 UTC
Hello? Is anyone maintaining pkg-config? Fixing this (via the patch, or a better one if you want it) would make life easier for people using Windows.
Comment 12 Tollef Fog Heen 2010-05-23 14:12:12 UTC
Fixed in:


commit 69a7eaa6763bb0920e2b539fffbad51348d94deb
Author: Tollef Fog Heen <tfheen@err.no>
Date:   Sun May 23 22:59:46 2010 +0200

    Make it possible to escape paths containing special shell characters
    
    Allow paths and other components to contain shell metacharacters, but
    escape them on output.  White space has to be escaped in the input
    files using quotes or backslashes
    
    Freedesktop.org #3571

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.