Merge pull request #3086 from sarum9in/declare-link-whole

Add declare_dependency() link_whole parameter
pull/3191/head
Jussi Pakkanen 7 years ago committed by GitHub
commit e98ae58d0e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      docs/markdown/Reference-manual.md
  2. 4
      docs/markdown/snippets/declare_dependency-link_whole.md
  3. 4
      mesonbuild/build.py
  4. 3
      mesonbuild/dependencies/base.py
  5. 5
      mesonbuild/interpreter.py
  6. 2
      mesonbuild/modules/gnome.py
  7. 1
      test cases/common/145 whole archive/exe3/meson.build
  8. 1
      test cases/common/145 whole archive/exe4/meson.build
  9. 18
      test cases/common/145 whole archive/meson.build
  10. 4
      test cases/common/145 whole archive/sh_func2_dep_func1/meson.build
  11. 6
      test cases/common/145 whole archive/sh_func2_transdep_func1/meson.build

@ -267,6 +267,8 @@ keyword arguments.
- `include_directories`, the directories to add to header search path
- `link_args`, link arguments to use
- `link_with`, libraries to link against
- `link_whole`, libraries to link fully, same as [`executable`](#executable)
Since 0.46.0
- `sources`, sources to add to targets (or generated header files
that should be built before sources including them are built)
- `version`, the version of this dependency, such as `1.2.3`

@ -0,0 +1,4 @@
## declare_dependency() supports link_whole
`declare_dependency()` supports `link_whole` parameter.
`link_whole` propagates to build target that uses dependency.

@ -838,12 +838,14 @@ This will become a hard error in a future Meson release.''')
self.add_include_dirs(dep.include_directories)
for l in dep.libraries:
self.link(l)
for l in dep.whole_libraries:
self.link_whole(l)
# Those parts that are external.
extpart = dependencies.InternalDependency('undefined',
[],
dep.compile_args,
dep.link_args,
[], [], [])
[], [], [], [])
self.external_deps.append(extpart)
# Deps of deps.
self.add_deps(dep.ext_deps)

@ -145,7 +145,7 @@ class Dependency:
class InternalDependency(Dependency):
def __init__(self, version, incdirs, compile_args, link_args, libraries, sources, ext_deps):
def __init__(self, version, incdirs, compile_args, link_args, libraries, whole_libraries, sources, ext_deps):
super().__init__('internal', {})
self.version = version
self.is_found = True
@ -153,6 +153,7 @@ class InternalDependency(Dependency):
self.compile_args = compile_args
self.link_args = link_args
self.libraries = libraries
self.whole_libraries = whole_libraries
self.sources = sources
self.ext_deps = ext_deps

@ -1390,7 +1390,7 @@ permitted_kwargs = {'add_global_arguments': {'language'},
'configure_file': {'input', 'output', 'configuration', 'command', 'install_dir', 'capture', 'install'},
'custom_target': {'input', 'output', 'command', 'install', 'install_dir', 'build_always', 'capture', 'depends', 'depend_files', 'depfile', 'build_by_default'},
'dependency': {'default_options', 'fallback', 'language', 'main', 'method', 'modules', 'optional_modules', 'native', 'required', 'static', 'version'},
'declare_dependency': {'include_directories', 'link_with', 'sources', 'dependencies', 'compile_args', 'link_args', 'version'},
'declare_dependency': {'include_directories', 'link_with', 'sources', 'dependencies', 'compile_args', 'link_args', 'link_whole', 'version'},
'executable': exe_kwargs,
'find_program': {'required', 'native'},
'generator': {'arguments', 'output', 'depfile', 'capture', 'preserve_path_from'},
@ -1622,6 +1622,7 @@ class Interpreter(InterpreterBase):
raise InterpreterException('Version must be a string.')
incs = extract_as_list(kwargs, 'include_directories', unholder=True)
libs = extract_as_list(kwargs, 'link_with', unholder=True)
libs_whole = extract_as_list(kwargs, 'link_whole', unholder=True)
sources = extract_as_list(kwargs, 'sources')
sources = listify(self.source_strings_to_files(sources), unholder=True)
deps = extract_as_list(kwargs, 'dependencies', unholder=True)
@ -1641,7 +1642,7 @@ class Interpreter(InterpreterBase):
raise InterpreterException('''Entries in "link_with" may only be self-built targets,
external dependencies (including libraries) must go to "dependencies".''')
dep = dependencies.InternalDependency(version, incs, compile_args,
link_args, libs, sources, final_deps)
link_args, libs, libs_whole, sources, final_deps)
return DependencyHolder(dep)
@noKwargs

@ -1350,7 +1350,7 @@ G_END_DECLS'''
# - add relevant directories to include dirs
incs = [build.IncludeDirs(state.subdir, ['.'] + vapi_includes, False)]
sources = [vapi_target] + vapi_depends
rv = InternalDependency(None, incs, [], [], link_with, sources, [])
rv = InternalDependency(None, incs, [], [], link_with, [], sources, [])
created_values.append(rv)
return ModuleReturnValue(rv, created_values)

@ -0,0 +1 @@
exe3 = executable('prog3', '../prog.c', link_with : sh_func2_dep_func1)

@ -0,0 +1 @@
exe4 = executable('prog4', '../prog.c', link_with : sh_func2_transdep_func1)

@ -30,3 +30,21 @@ subdir('sh_only_link_whole')
subdir('exe2')
# Test that both func1 and func2 are accessible from shared library
test('prog2', exe2)
# Test 3: link_whole can be used in declare_dependency()
func1_dep = declare_dependency(link_whole : [st_func1])
# Use dependency to link func1 into shared library
subdir('sh_func2_dep_func1')
# Link exe3 with shared library
subdir('exe3')
# Test that both func1 and func2 are accessible from shared library
test('prog3', exe3)
# Test 4: link_whole can be used in transitive declare_dependency()
func1_trans_dep = declare_dependency(dependencies : func1_dep)
# Use transitive dependency to link func1 into shared library
subdir('sh_func2_transdep_func1')
# Link exe4 with shared library
subdir('exe4')
# Test that both func1 and func2 are accessible from shared library
test('prog4', exe4)

@ -0,0 +1,4 @@
# Same as sh_func2_linked_func1, # func2.c does not depend on func1(),
# so without link_whole compiler would throw func1() away.
# This is the same version of the test with a dependency object instead.
sh_func2_dep_func1 = shared_library('sh_func2_dep_func1', '../func2.c', dependencies : func1_dep)

@ -0,0 +1,6 @@
# Same as sh_func2_dep_func1 but dependency is transitive.
# func2.c does not have any reference to func1() so without link_whole compiler
# should throw func1() out.
sh_func2_transdep_func1 = shared_library(
'sh_func2_transdep_func1', '../func2.c',
dependencies : func1_trans_dep)
Loading…
Cancel
Save