pkgconfig: Fix flag deduplication

This is a regression introduced by 2cbf7caf5, generated pkg-config files
have many duplicated '-pthread' flags.
pull/4726/head
Xavier Claessens 6 years ago committed by Jussi Pakkanen
parent 1aca899a63
commit 83964f64fa
  1. 6
      mesonbuild/modules/pkgconfig.py
  2. 47
      run_unittests.py
  3. 4
      test cases/common/48 pkgconfig-gen/dependencies/meson.build

@ -192,7 +192,11 @@ class DependenciesHelper:
for x in xs: for x in xs:
# Don't de-dup unknown strings to avoid messing up arguments like: # Don't de-dup unknown strings to avoid messing up arguments like:
# ['-framework', 'CoreAudio', '-framework', 'CoreMedia'] # ['-framework', 'CoreAudio', '-framework', 'CoreMedia']
if x not in result or (libs and (isinstance(x, str) and not x.endswith(('-l', '-L')))): known_flags = ['-pthread']
cannot_dedup = libs and isinstance(x, str) and \
not x.startswith(('-l', '-L')) and \
x not in known_flags
if x not in result or cannot_dedup:
result.append(x) result.append(x)
return result return result
self.pub_libs = _fn(self.pub_libs, True) self.pub_libs = _fn(self.pub_libs, True)

@ -3657,26 +3657,30 @@ class LinuxlikeTests(BasePlatformTests):
privatedir2 = self.privatedir privatedir2 = self.privatedir
os.environ['PKG_CONFIG_LIBDIR'] = os.pathsep.join([privatedir1, privatedir2]) os.environ['PKG_CONFIG_LIBDIR'] = os.pathsep.join([privatedir1, privatedir2])
cmd = ['pkg-config', 'dependency-test'] self._run(['pkg-config', 'dependency-test', '--validate'])
out = self._run(cmd + ['--print-requires']).strip().split('\n') # pkg-config strips some duplicated flags so we have to parse the
self.assertEqual(sorted(out), sorted(['libexposed'])) # generated file ourself.
expected = {
out = self._run(cmd + ['--print-requires-private']).strip().split('\n') 'Requires': 'libexposed',
self.assertEqual(sorted(out), sorted(['libfoo >= 1.0'])) 'Requires.private': 'libfoo >= 1.0',
'Libs': '-L${libdir} -llibmain -pthread -lcustom',
out = self._run(cmd + ['--cflags-only-other']).strip().split() 'Libs.private': '-lcustom2 -L${libdir} -llibinternal',
self.check_pkg_flags_are_same(out, ['-pthread', '-DCUSTOM']) 'Cflags': '-I${includedir} -pthread -DCUSTOM',
}
out = self._run(cmd + ['--libs-only-l', '--libs-only-other']).strip().split() if is_osx() or is_haiku():
self.check_pkg_flags_are_same(out, ['-pthread', '-lcustom', expected['Cflags'] = expected['Cflags'].replace('-pthread ', '')
'-llibmain', '-llibexposed']) with open(os.path.join(privatedir2, 'dependency-test.pc')) as f:
matched_lines = 0
out = self._run(cmd + ['--libs-only-l', '--libs-only-other', '--static']).strip().split() for line in f:
self.check_pkg_flags_are_same(out, ['-pthread', '-lcustom', parts = line.split(':', 1)
'-llibmain', '-llibexposed', if parts[0] in expected:
'-llibinternal', '-lcustom2', key = parts[0]
'-lfoo']) val = parts[1].strip()
expected_val = expected[key]
self.assertEqual(expected_val, val)
matched_lines += 1
self.assertEqual(len(expected), matched_lines)
cmd = ['pkg-config', 'requires-test'] cmd = ['pkg-config', 'requires-test']
out = self._run(cmd + ['--print-requires']).strip().split('\n') out = self._run(cmd + ['--print-requires']).strip().split('\n')
@ -3686,11 +3690,6 @@ class LinuxlikeTests(BasePlatformTests):
out = self._run(cmd + ['--print-requires-private']).strip().split('\n') out = self._run(cmd + ['--print-requires-private']).strip().split('\n')
self.assertEqual(sorted(out), sorted(['libexposed', 'libfoo >= 1.0', 'libhello'])) self.assertEqual(sorted(out), sorted(['libexposed', 'libfoo >= 1.0', 'libhello']))
def check_pkg_flags_are_same(self, output, expected):
if is_osx() or is_haiku():
expected = [x for x in expected if x != '-pthread']
self.assertEqual(sorted(output), sorted(expected))
def test_pkg_unfound(self): def test_pkg_unfound(self):
testdir = os.path.join(self.unit_test_dir, '23 unfound pkgconfig') testdir = os.path.join(self.unit_test_dir, '23 unfound pkgconfig')
self.init(testdir) self.init(testdir)

@ -28,8 +28,8 @@ custom2_dep = declare_dependency(link_args : ['-lcustom2'], compile_args : ['-DC
# - Having pc_dep in libraries_private should add it in Requires.private # - Having pc_dep in libraries_private should add it in Requires.private
# - pc_dep_dup is the same library and same version, should be ignored # - pc_dep_dup is the same library and same version, should be ignored
# - notfound_dep is not required so it shouldn't appear in the pc file. # - notfound_dep is not required so it shouldn't appear in the pc file.
pkgg.generate(libraries : [main_lib, exposed_lib, threads_dep , custom_dep], pkgg.generate(libraries : [main_lib, exposed_lib, threads_dep, threads_dep, custom_dep, custom_dep, '-pthread'],
libraries_private : [custom_dep, custom2_dep, pc_dep, pc_dep_dup, notfound_dep], libraries_private : [custom_dep, custom2_dep, custom2_dep, pc_dep, pc_dep_dup, notfound_dep],
version : '1.0', version : '1.0',
name : 'dependency-test', name : 'dependency-test',
filebase : 'dependency-test', filebase : 'dependency-test',

Loading…
Cancel
Save