intepreter: add kwargs annotations for build_target classes

This doesn't do much yet, but with my advanced knowledge of what's
coming this lays out most of what we're going to need
pull/12020/head
Dylan Baker 1 year ago committed by Xavier Claessens
parent ded2204d2c
commit 686f6aac31
  1. 17
      mesonbuild/interpreter/interpreter.py
  2. 45
      mesonbuild/interpreter/kwargs.py

@ -1808,7 +1808,7 @@ class Interpreter(InterpreterBase, HoldableObject):
@typed_kwargs('executable', OVERRIDE_OPTIONS_KW, allow_unknown=True)
def func_executable(self, node: mparser.BaseNode,
args: T.Tuple[str, T.List[BuildTargetSource]],
kwargs) -> build.Executable:
kwargs: kwtypes.Executable) -> build.Executable:
return self.build_target(node, args, kwargs, build.Executable)
@permittedKwargs(build.known_stlib_kwargs)
@ -1816,7 +1816,7 @@ class Interpreter(InterpreterBase, HoldableObject):
@typed_kwargs('static_library', OVERRIDE_OPTIONS_KW, allow_unknown=True)
def func_static_lib(self, node: mparser.BaseNode,
args: T.Tuple[str, T.List[BuildTargetSource]],
kwargs) -> build.StaticLibrary:
kwargs: kwtypes.StaticLibrary) -> build.StaticLibrary:
return self.build_target(node, args, kwargs, build.StaticLibrary)
@permittedKwargs(build.known_shlib_kwargs)
@ -1824,7 +1824,7 @@ class Interpreter(InterpreterBase, HoldableObject):
@typed_kwargs('shared_library', OVERRIDE_OPTIONS_KW, allow_unknown=True)
def func_shared_lib(self, node: mparser.BaseNode,
args: T.Tuple[str, T.List[BuildTargetSource]],
kwargs) -> build.SharedLibrary:
kwargs: kwtypes.SharedLibrary) -> build.SharedLibrary:
holder = self.build_target(node, args, kwargs, build.SharedLibrary)
holder.shared_library_only = True
return holder
@ -1834,7 +1834,7 @@ class Interpreter(InterpreterBase, HoldableObject):
@typed_kwargs('both_libraries', OVERRIDE_OPTIONS_KW, allow_unknown=True)
def func_both_lib(self, node: mparser.BaseNode,
args: T.Tuple[str, T.List[BuildTargetSource]],
kwargs) -> build.BothLibraries:
kwargs: kwtypes.Library) -> build.BothLibraries:
return self.build_both_libraries(node, args, kwargs)
@FeatureNew('shared_module', '0.37.0')
@ -1843,7 +1843,7 @@ class Interpreter(InterpreterBase, HoldableObject):
@typed_kwargs('shared_module', OVERRIDE_OPTIONS_KW, allow_unknown=True)
def func_shared_module(self, node: mparser.BaseNode,
args: T.Tuple[str, T.List[BuildTargetSource]],
kwargs) -> build.SharedModule:
kwargs: kwtypes.SharedModule) -> build.SharedModule:
return self.build_target(node, args, kwargs, build.SharedModule)
@permittedKwargs(known_library_kwargs)
@ -1851,7 +1851,7 @@ class Interpreter(InterpreterBase, HoldableObject):
@typed_kwargs('library', OVERRIDE_OPTIONS_KW, allow_unknown=True)
def func_library(self, node: mparser.BaseNode,
args: T.Tuple[str, T.List[BuildTargetSource]],
kwargs) -> build.Executable:
kwargs: kwtypes.Library) -> build.Executable:
return self.build_library(node, args, kwargs)
@permittedKwargs(build.known_jar_kwargs)
@ -1859,7 +1859,7 @@ class Interpreter(InterpreterBase, HoldableObject):
@typed_kwargs('jar', OVERRIDE_OPTIONS_KW, allow_unknown=True)
def func_jar(self, node: mparser.BaseNode,
args: T.Tuple[str, T.List[T.Union[str, mesonlib.File, build.GeneratedTypes]]],
kwargs) -> build.Jar:
kwargs: kwtypes.Jar) -> build.Jar:
return self.build_target(node, args, kwargs, build.Jar)
@FeatureNewKwargs('build_target', '0.40.0', ['link_whole', 'override_options'])
@ -1868,7 +1868,8 @@ class Interpreter(InterpreterBase, HoldableObject):
@typed_kwargs('build_target', OVERRIDE_OPTIONS_KW, allow_unknown=True)
def func_build_target(self, node: mparser.BaseNode,
args: T.Tuple[str, T.List[BuildTargetSource]],
kwargs) -> T.Union[build.Executable, build.StaticLibrary, build.SharedLibrary,
kwargs: kwtypes.BuildTarget
) -> T.Union[build.Executable, build.StaticLibrary, build.SharedLibrary,
build.SharedModule, build.BothLibraries, build.Jar]:
if 'target_type' not in kwargs:
raise InterpreterException('Missing target_type keyword argument')

@ -308,3 +308,48 @@ class DoSubproject(ExtractRequired):
version: T.List[str]
cmake_options: T.List[str]
options: T.Optional[CMakeSubprojectOptions]
class _BaseBuildTarget(TypedDict):
"""Arguments used by all BuildTarget like functions.
This really exists because Jar is so different than all of the other
BuildTarget functions.
"""
override_options: T.Dict[OptionKey, T.Union[str, int, bool, T.List[str]]]
class _BuildTarget(_BaseBuildTarget):
"""Arguments shared by non-JAR functions"""
class Executable(_BuildTarget):
pass
class StaticLibrary(_BuildTarget):
pass
class SharedLibrary(_BuildTarget):
pass
class SharedModule(_BuildTarget):
pass
class Library(_BuildTarget):
"""For library, both_library, and as a base for build_target"""
class BuildTarget(Library):
pass
class Jar(_BaseBuildTarget):
pass

Loading…
Cancel
Save