Skip to content

Commit

Permalink
Add a only_exts argument to the dep.partial_dependency method
Browse files Browse the repository at this point in the history
So that one can create a dependency objects for fully statically
linked objects from all its dependencies (in a recursive way)
  • Loading branch information
thiblahute authored and eerii committed Sep 24, 2024
1 parent dbad301 commit 99c3210
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 20 deletions.
64 changes: 44 additions & 20 deletions mesonbuild/dependencies/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import typing as T
from enum import Enum

from .. import mlog, mesonlib
from .. import mlog, mesonlib, build
from ..compilers import clib_langs
from ..mesonlib import LibType, MachineChoice, MesonException, HoldableObject, version_compare_many
from ..options import OptionKey
Expand Down Expand Up @@ -203,7 +203,8 @@ def get_exe_args(self, compiler: 'Compiler') -> T.List[str]:

def get_partial_dependency(self, *, compile_args: bool = False,
link_args: bool = False, links: bool = False,
includes: bool = False, sources: bool = False) -> 'Dependency':
includes: bool = False, sources: bool = False,
only_exts: bool = False) -> 'Dependency':
"""Create a new dependency that contains part of the parent dependency.
The following options can be inherited:
Expand Down Expand Up @@ -308,17 +309,37 @@ def is_built(self) -> bool:
def get_partial_dependency(self, *, compile_args: bool = False,
link_args: bool = False, links: bool = False,
includes: bool = False, sources: bool = False,
extra_files: bool = False) -> InternalDependency:
final_compile_args = self.compile_args.copy() if compile_args else []
final_link_args = self.link_args.copy() if link_args else []
final_libraries = self.libraries.copy() if links else []
final_whole_libraries = self.whole_libraries.copy() if links else []
final_sources = self.sources.copy() if sources else []
final_extra_files = self.extra_files.copy() if extra_files else []
final_includes = self.include_directories.copy() if includes else []
extra_files: bool = False, only_exts: bool = False) -> InternalDependency:
final_compile_args = self.compile_args.copy() if compile_args and not only_exts else []
final_link_args = self.link_args.copy() if link_args and not only_exts else []
final_libraries = self.libraries.copy() if links and not only_exts else []
final_whole_libraries = self.whole_libraries.copy() if links and not only_exts else []
final_sources = self.sources.copy() if sources and not only_exts else []
final_extra_files = self.extra_files.copy() if extra_files and not only_exts else []
final_includes = self.include_directories.copy() if includes and not only_exts else []
final_deps = [d.get_partial_dependency(
compile_args=compile_args, link_args=link_args, links=links,
includes=includes, sources=sources) for d in self.ext_deps]
includes=includes, sources=sources, only_exts=False) for d in self.ext_deps]
if only_exts:
for library in self.libraries:
final_deps += [d.get_partial_dependency(
compile_args=compile_args, link_args=link_args, links=links,
includes=includes, sources=sources, only_exts=False) for d in library.external_deps]
for target in library.link_targets:
if not isinstance(target, build.StaticLibrary):
continue
final_deps += [d.get_partial_dependency(
compile_args=compile_args, link_args=link_args, links=links,
includes=includes, sources=sources, only_exts=False) for d in target.external_deps]
for whole_target in library.link_whole_targets:
final_deps += [d.get_partial_dependency(
compile_args=compile_args, link_args=link_args, links=links,
includes=includes, sources=sources, only_exts=False) for d in whole_target.external_deps]
for library in self.whole_libraries:
final_deps += [d.get_partial_dependency(
compile_args=compile_args, link_args=link_args, links=links,
includes=includes, sources=sources, only_exts=False) for d in library.external_deps]

return InternalDependency(
self.version, final_includes, final_compile_args,
final_link_args, final_libraries, final_whole_libraries,
Expand Down Expand Up @@ -400,17 +421,18 @@ def get_compiler(self) -> T.Union['MissingCompiler', 'Compiler']:

def get_partial_dependency(self, *, compile_args: bool = False,
link_args: bool = False, links: bool = False,
includes: bool = False, sources: bool = False) -> Dependency:
includes: bool = False, sources: bool = False,
only_exts: bool = False) -> Dependency:
new = copy.copy(self)
if not compile_args:
if not compile_args and not only_exts:
new.compile_args = []
if not link_args:
if not link_args and not only_exts:
new.link_args = []
if not sources:
if not sources and not only_exts:
new.sources = []
if not includes:
if not includes and not only_exts:
pass # TODO maybe filter compile_args?
if not sources:
if not sources and not only_exts:
new.sources = []

return new
Expand Down Expand Up @@ -471,7 +493,8 @@ def __init__(self, name: str, environment: 'Environment') -> None:

def get_partial_dependency(self, *, compile_args: bool = False,
link_args: bool = False, links: bool = False,
includes: bool = False, sources: bool = False) -> 'NotFoundDependency':
includes: bool = False, sources: bool = False,
only_exts: bool = False) -> 'NotFoundDependency':
return copy.copy(self)


Expand Down Expand Up @@ -508,11 +531,12 @@ def get_link_args(self, language: T.Optional[str] = None, raw: bool = False) ->

def get_partial_dependency(self, *, compile_args: bool = False,
link_args: bool = False, links: bool = False,
includes: bool = False, sources: bool = False) -> 'ExternalLibrary':
includes: bool = False, sources: bool = False,
only_exts: bool = False) -> 'ExternalLibrary':
# External library only has link_args, so ignore the rest of the
# interface.
new = copy.copy(self)
if not link_args:
if not link_args or only_exts:
new.link_args = []
return new

Expand Down
1 change: 1 addition & 0 deletions mesonbuild/interpreter/interpreterobjects.py
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,7 @@ def merge_from_method(self, args: T.Tuple[build.ConfigurationData], kwargs: TYPE
KwargInfo('links', bool, default=False),
KwargInfo('includes', bool, default=False),
KwargInfo('sources', bool, default=False),
KwargInfo('only_exts', bool, default=False, since='1.6.0'),
]

class DependencyHolder(ObjectHolder[Dependency]):
Expand Down

0 comments on commit 99c3210

Please sign in to comment.