Skip to content

Commit

Permalink
Nirbheek/fix pkgconfig library dedup (mesonbuild#3813)
Browse files Browse the repository at this point in the history
* Add a test case for bad de-dup of -framework args

mesonbuild#3800

* pkgconfig: Don't naively de-dup all arguments

Honestly don't know what I was smoking. Of course the `Libs:` field in
a pkg-config file can have arguments other than -l and -L

Closes mesonbuild#3800

* pkgconfig module: Fix needlessly aggressive de-dup
  • Loading branch information
nirbheek authored Jul 1, 2018
1 parent 76184bb commit 2cbf7ca
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 11 deletions.
21 changes: 15 additions & 6 deletions mesonbuild/dependencies/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -589,9 +589,12 @@ def _set_libs(self):
if ret != 0:
raise DependencyException('Could not generate libs for %s:\n\n%s' %
(self.name, out))
# These libraries should be safe to de-dup
link_args = OrderedSet()
link_args = []
# Library paths should be safe to de-dup
libpaths = OrderedSet()
# Track -lfoo libraries to avoid duplicate work
libs_found = OrderedSet()
# Track not-found libraries to know whether to add library paths
libs_notfound = []
libtype = 'static' if self.static else 'default'
# We always look for the file ourselves instead of depending on the
Expand All @@ -609,6 +612,9 @@ def _set_libs(self):
libpaths.add(lib[2:])
continue
elif lib.startswith('-l'):
# Don't resolve the same -lfoo argument again
if lib in libs_found:
continue
if self.clib_compiler:
args = self.clib_compiler.find_library(lib[2:], self.env,
list(libpaths), libtype)
Expand All @@ -618,10 +624,11 @@ def _set_libs(self):
else:
args = None
if args:
libs_found.add(lib)
# Replace -l arg with full path to library if available
# else, library is provided by the compiler and can't be resolved
if not args[0].startswith('-l'):
lib = args[0]
# else, library is provided by the compiler and can't be resolved
else:
# Library wasn't found, maybe we're looking in the wrong
# places or the library will be provided with LDFLAGS or
Expand All @@ -645,10 +652,12 @@ def _set_libs(self):
raise DependencyException('Got a libtools specific "%s" dependencies'
'but we could not compute the actual shared'
'library path' % lib)
lib = shared_lib
self.is_libtool = True
link_args.add(lib)
self.link_args = list(link_args)
lib = shared_lib
if lib in link_args:
continue
link_args.append(lib)
self.link_args = link_args
# Add all -Lbar args if we have -lfoo args in link_args
if libs_notfound:
# Order of -L flags doesn't matter with ld, but it might with other
Expand Down
10 changes: 6 additions & 4 deletions mesonbuild/modules/pkgconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,16 +170,18 @@ def format_reqs(self, reqs):
return ', '.join(result)

def remove_dups(self):
def _fn(xs):
def _fn(xs, libs=False):
# Remove duplicates whilst preserving original order
result = []
for x in xs:
if x not in result:
# Don't de-dup unknown strings to avoid messing up arguments like:
# ['-framework', 'CoreAudio', '-framework', 'CoreMedia']
if x not in result or (libs and (isinstance(x, str) and not x.endswith(('-l', '-L')))):
result.append(x)
return result
self.pub_libs = _fn(self.pub_libs)
self.pub_libs = _fn(self.pub_libs, True)
self.pub_reqs = _fn(self.pub_reqs)
self.priv_libs = _fn(self.priv_libs)
self.priv_libs = _fn(self.priv_libs, True)
self.priv_reqs = _fn(self.priv_reqs)
self.cflags = _fn(self.cflags)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ l = shared_library('faa_pkg', 'faa.c', install: true)

pkg = import('pkgconfig')
pkg.generate(name: 'faa_pkg',
libraries: l,
libraries: [l, '-framework', 'CoreFoundation', '-framework', 'CoreMedia'],
description: 'FAA, a pkg-config test library')

0 comments on commit 2cbf7ca

Please sign in to comment.