interpreter: use kwarginfo for build_target(target_type)

Which lets us remove a bunch of validation code
pull/12020/head
Dylan Baker 1 year ago committed by Xavier Claessens
parent 096869ad63
commit a62a42b272
  1. 12
      mesonbuild/interpreter/interpreter.py
  2. 4
      mesonbuild/interpreter/kwargs.py
  3. 12
      mesonbuild/interpreter/type_checking.py

@ -1877,17 +1877,12 @@ class Interpreter(InterpreterBase, HoldableObject):
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')
target_type = kwargs.pop('target_type')
target_type = kwargs['target_type']
if target_type == 'executable':
return self.build_target(node, args, kwargs, build.Executable)
elif target_type == 'shared_library':
return self.build_target(node, args, kwargs, build.SharedLibrary)
elif target_type == 'shared_module':
FeatureNew.single_use(
'build_target(target_type: \'shared_module\')',
'0.51.0', self.subproject, location=node)
return self.build_target(node, args, kwargs, build.SharedModule)
elif target_type == 'static_library':
return self.build_target(node, args, kwargs, build.StaticLibrary)
@ -1895,10 +1890,7 @@ class Interpreter(InterpreterBase, HoldableObject):
return self.build_both_libraries(node, args, kwargs)
elif target_type == 'library':
return self.build_library(node, args, kwargs)
elif target_type == 'jar':
return self.build_target(node, args, kwargs, build.Jar)
else:
raise InterpreterException('Unknown target_type.')
return self.build_target(node, args, kwargs, build.Jar)
@noPosargs
@typed_kwargs(

@ -348,7 +348,9 @@ class Library(_BuildTarget):
class BuildTarget(Library):
pass
target_type: Literal['executable', 'shared_library', 'static_library',
'shared_module', 'both_libraries', 'library', 'jar']
class Jar(_BaseBuildTarget):

@ -556,4 +556,16 @@ BUILD_TARGET_KWS = [
*LIBRARY_KWS,
*_EXCLUSIVE_EXECUTABLE_KWS,
*_EXCLUSIVE_JAR_KWS,
KwargInfo(
'target_type',
str,
required=True,
validator=in_set_validator({
'executable', 'shared_library', 'static_library', 'shared_module',
'both_libraries', 'library', 'jar'
}),
since_values={
'shared_module': '0.51.0',
}
)
]

Loading…
Cancel
Save