From a62a42b272923f95b7aeb30f0196cfdf3b251264 Mon Sep 17 00:00:00 2001 From: Dylan Baker Date: Wed, 19 Jul 2023 13:12:30 -0700 Subject: [PATCH] interpreter: use kwarginfo for build_target(target_type) Which lets us remove a bunch of validation code --- mesonbuild/interpreter/interpreter.py | 12 ++---------- mesonbuild/interpreter/kwargs.py | 4 +++- mesonbuild/interpreter/type_checking.py | 12 ++++++++++++ 3 files changed, 17 insertions(+), 11 deletions(-) diff --git a/mesonbuild/interpreter/interpreter.py b/mesonbuild/interpreter/interpreter.py index 853d858b9..235f04875 100644 --- a/mesonbuild/interpreter/interpreter.py +++ b/mesonbuild/interpreter/interpreter.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( diff --git a/mesonbuild/interpreter/kwargs.py b/mesonbuild/interpreter/kwargs.py index 4254c3043..31c96e28e 100644 --- a/mesonbuild/interpreter/kwargs.py +++ b/mesonbuild/interpreter/kwargs.py @@ -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): diff --git a/mesonbuild/interpreter/type_checking.py b/mesonbuild/interpreter/type_checking.py index 38e425734..7c615c2c8 100644 --- a/mesonbuild/interpreter/type_checking.py +++ b/mesonbuild/interpreter/type_checking.py @@ -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', + } + ) ]