pkgconfig: Use the pc file we generated for libraries

pull/2757/head
Xavier Claessens 7 years ago
parent 9e541a0fff
commit 49977686b5
  1. 21
      mesonbuild/modules/pkgconfig.py
  2. 12
      test cases/common/51 pkgconfig-gen/meson.build

@ -24,7 +24,8 @@ from . import ExtensionModule
from ..interpreterbase import permittedKwargs from ..interpreterbase import permittedKwargs
class DepsHolder: class DepsHolder:
def __init__(self): def __init__(self, name):
self.name = name
self.pub_libs = [] self.pub_libs = []
self.pub_reqs = [] self.pub_reqs = []
self.priv_libs = [] self.priv_libs = []
@ -62,6 +63,8 @@ class DepsHolder:
if hasattr(obj, 'pcdep'): if hasattr(obj, 'pcdep'):
pcdeps = mesonlib.listify(obj.pcdep) pcdeps = mesonlib.listify(obj.pcdep)
processed_reqs += [i.name for i in pcdeps] processed_reqs += [i.name for i in pcdeps]
elif hasattr(obj, 'generated_pc'):
processed_reqs.append(obj.generated_pc)
elif isinstance(obj, dependencies.PkgConfigDependency): elif isinstance(obj, dependencies.PkgConfigDependency):
processed_reqs.append(obj.name) processed_reqs.append(obj.name)
elif isinstance(obj, dependencies.ThreadDependency): elif isinstance(obj, dependencies.ThreadDependency):
@ -73,6 +76,8 @@ class DepsHolder:
elif isinstance(obj, (build.SharedLibrary, build.StaticLibrary)): elif isinstance(obj, (build.SharedLibrary, build.StaticLibrary)):
processed_libs.append(obj) processed_libs.append(obj)
if public: if public:
if not hasattr(obj, 'generated_pc'):
obj.generated_pc = self.name
self.add_priv_libs(obj.get_dependencies()) self.add_priv_libs(obj.get_dependencies())
self.add_priv_libs(obj.get_external_deps()) self.add_priv_libs(obj.get_external_deps())
elif isinstance(obj, str): elif isinstance(obj, str):
@ -216,13 +221,6 @@ class PkgConfigModule(ExtensionModule):
if len(args) > 0: if len(args) > 0:
raise mesonlib.MesonException('Pkgconfig_gen takes no positional arguments.') raise mesonlib.MesonException('Pkgconfig_gen takes no positional arguments.')
deps = DepsHolder()
deps.add_pub_libs(kwargs.get('libraries', []))
deps.add_priv_libs(kwargs.get('libraries_private', []))
deps.add_pub_reqs(kwargs.get('requires', []))
deps.add_priv_reqs(kwargs.get('requires_private', []))
deps.add_cflags(kwargs.get('extra_cflags', []))
subdirs = mesonlib.stringlistify(kwargs.get('subdirs', ['.'])) subdirs = mesonlib.stringlistify(kwargs.get('subdirs', ['.']))
version = kwargs.get('version', None) version = kwargs.get('version', None)
if not isinstance(version, str): if not isinstance(version, str):
@ -241,6 +239,13 @@ class PkgConfigModule(ExtensionModule):
raise mesonlib.MesonException('URL is not a string.') raise mesonlib.MesonException('URL is not a string.')
conflicts = mesonlib.stringlistify(kwargs.get('conflicts', [])) conflicts = mesonlib.stringlistify(kwargs.get('conflicts', []))
deps = DepsHolder(filebase)
deps.add_pub_libs(kwargs.get('libraries', []))
deps.add_priv_libs(kwargs.get('libraries_private', []))
deps.add_pub_reqs(kwargs.get('requires', []))
deps.add_priv_reqs(kwargs.get('requires_private', []))
deps.add_cflags(kwargs.get('extra_cflags', []))
dversions = kwargs.get('d_module_versions', None) dversions = kwargs.get('d_module_versions', None)
if dversions: if dversions:
compiler = state.environment.coredata.compilers.get('d') compiler = state.environment.coredata.compilers.get('d')

@ -59,6 +59,12 @@ exposed_lib = shared_library('libexposed', 'simple.c')
internal_lib = shared_library('libinternal', 'simple.c') internal_lib = shared_library('libinternal', 'simple.c')
main_lib = shared_library('libmain', link_with : [exposed_lib, internal_lib]) main_lib = shared_library('libmain', link_with : [exposed_lib, internal_lib])
pkgg.generate(libraries : exposed_lib,
version : libver,
name : 'libexposed',
description : 'An exposed library in dependency test.'
)
# Declare a few different Dependency objects # Declare a few different Dependency objects
pc_dep = dependency('libfoo', required : false) pc_dep = dependency('libfoo', required : false)
threads_dep = dependency('threads', required : false) threads_dep = dependency('threads', required : false)
@ -68,6 +74,7 @@ custom2_dep = declare_dependency(link_args : ['-lcustom2'], compile_args : ['-DC
# Generate a PC file: # Generate a PC file:
# - Having libmain in libraries should pull implicitely libexposed and libinternal in Libs.private # - Having libmain in libraries should pull implicitely libexposed and libinternal in Libs.private
# - Having libexposed in libraries should remove it from Libs.private # - Having libexposed in libraries should remove it from Libs.private
# - We generated a pc file for libexposed so it should be in Requires instead of Libs
# - Having threads_dep in libraries should add '-pthread' in both Libs and Cflags # - Having threads_dep in libraries should add '-pthread' in both Libs and Cflags
# - Having custom_dep in libraries and libraries_private should only add it in Libs # - Having custom_dep in libraries and libraries_private should only add it in Libs
# - Having custom2_dep in libraries_private should not add its Cflags # - Having custom2_dep in libraries_private should not add its Cflags
@ -83,7 +90,8 @@ pkgg.generate(libraries : [main_lib, exposed_lib, threads_dep , custom_dep],
msg = 'Generated pc file doesn\'t have expected @0@: @1@' msg = 'Generated pc file doesn\'t have expected @0@: @1@'
out = run_command(envcmd, '-', pkgconfig_env, pkgconfig, 'dependency-test', '--print-requires').stdout().strip().split() out = run_command(envcmd, '-', pkgconfig_env, pkgconfig, 'dependency-test', '--print-requires').stdout().strip().split()
assert(out.length() == 0, msg.format('requires', out)) assert(out.contains('libexposed'), msg.format('requires', out))
assert(out.length() == 1, msg.format('requires', out))
out = run_command(envcmd, '-', pkgconfig_env, pkgconfig, 'dependency-test', '--print-requires-private').stdout().strip().split() out = run_command(envcmd, '-', pkgconfig_env, pkgconfig, 'dependency-test', '--print-requires-private').stdout().strip().split()
assert(out.contains('libfoo'), msg.format('requires.private', out)) assert(out.contains('libfoo'), msg.format('requires.private', out))
@ -95,14 +103,12 @@ assert(out.contains('-DCUSTOM'), msg.format('cflags', out))
assert(out.length() == 2, msg.format('cflags', out)) assert(out.length() == 2, msg.format('cflags', out))
out = run_command(envcmd, '-', pkgconfig_env, pkgconfig, 'dependency-test', '--libs-only-l', '--libs-only-other').stdout().strip().split() out = run_command(envcmd, '-', pkgconfig_env, pkgconfig, 'dependency-test', '--libs-only-l', '--libs-only-other').stdout().strip().split()
assert(out.contains('-llibexposed'), msg.format('libs', out))
assert(out.contains('-pthread'), msg.format('libs', out)) assert(out.contains('-pthread'), msg.format('libs', out))
assert(out.contains('-lcustom'), msg.format('libs', out)) assert(out.contains('-lcustom'), msg.format('libs', out))
assert(out.contains('-llibmain'), msg.format('libs', out)) assert(out.contains('-llibmain'), msg.format('libs', out))
assert(out.length() == 4, msg.format('libs', out)) assert(out.length() == 4, msg.format('libs', out))
out = run_command(envcmd, '-', pkgconfig_env, pkgconfig, 'dependency-test', '--libs-only-l', '--libs-only-other', '--static').stdout().strip().split() out = run_command(envcmd, '-', pkgconfig_env, pkgconfig, 'dependency-test', '--libs-only-l', '--libs-only-other', '--static').stdout().strip().split()
assert(out.contains('-llibexposed'), msg.format('libs.private', out))
assert(out.contains('-pthread'), msg.format('libs.private', out)) assert(out.contains('-pthread'), msg.format('libs.private', out))
assert(out.contains('-lcustom'), msg.format('libs.private', out)) assert(out.contains('-lcustom'), msg.format('libs.private', out))
assert(out.contains('-llibmain'), msg.format('libs.private', out)) assert(out.contains('-llibmain'), msg.format('libs.private', out))

Loading…
Cancel
Save