dependencies: Use shlex to parse pkg-config cflags and libs

Escaping spaces with '\ ' is the only way that works with both
pkg-config and pkgconf, so quote that way and unquote inside Meson.
This should work on all platforms.

Also fix the unit test to do the same.

https://github.com/pkgconf/pkgconf/issues/153
This commit is contained in:
Nirbheek Chauhan 2017-11-03 13:26:41 +05:30
parent 22f459a7dd
commit 65edbf35ef
3 changed files with 19 additions and 14 deletions

View File

@ -16,9 +16,10 @@
# Custom logic for several other packages are in separate files.
import os
import shutil
import stat
import sys
import stat
import shlex
import shutil
from enum import Enum
from .. import mlog
@ -267,7 +268,7 @@ class PkgConfigDependency(ExternalDependency):
if ret != 0:
raise DependencyException('Could not generate cargs for %s:\n\n%s' %
(self.name, out))
self.compile_args = out.split()
self.compile_args = shlex.split(out)
def _set_libs(self):
libcmd = [self.name, '--libs']
@ -279,7 +280,7 @@ class PkgConfigDependency(ExternalDependency):
(self.name, out))
self.link_args = []
libpaths = []
for lib in out.split():
for lib in shlex.split(out):
# If we want to use only static libraries, we have to look for the
# file ourselves instead of depending on the compiler to find it
# with -lfoo or foo.lib. However, we can only do this if we already

View File

@ -1,10 +1,10 @@
prefix=@PREFIX@
libdir=${prefix}
includedir=${prefix}/include
datadir=${prefix}/data
Name: libfoo
Description: A foo library.
Version: 1.0
Libs: -L${libdir} -lfoo
Cflags: -I${includedir}
prefix=@PREFIX@
libdir=${prefix}
includedir=${prefix}/include
datadir=${prefix}/data
Name: libfoo
Description: A foo library.
Version: 1.0
Libs: -L${libdir} -lfoo
Cflags: -I${includedir}

View File

@ -8,6 +8,10 @@ else
prefix = '/'.join(prefix_parts)
endif
# Escape spaces
prefix_parts = prefix.split(' ')
prefix = '\ '.join(prefix_parts)
conf = configuration_data()
conf.set('PREFIX', prefix)
configure_file(input : 'foo.pc.in',