From 30a9bb60eec03dbf0746b120201263859490716a Mon Sep 17 00:00:00 2001 From: Dylan Baker Date: Thu, 1 Jul 2021 09:57:53 -0700 Subject: [PATCH 01/18] interpreter: use typed_pos_args for is_disabler --- mesonbuild/interpreter/interpreter.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/mesonbuild/interpreter/interpreter.py b/mesonbuild/interpreter/interpreter.py index daef5fd6f..97502ca22 100644 --- a/mesonbuild/interpreter/interpreter.py +++ b/mesonbuild/interpreter/interpreter.py @@ -11,6 +11,7 @@ # See the License for the specific language governing permissions and # limitations under the License. +from mesonbuild.interpreterbase.baseobjects import TYPE_kwargs from .. import mparser from .. import environment from .. import coredata @@ -2768,12 +2769,10 @@ This will become a hard error in the future.''', location=self.current_node) return MachineChoice.BUILD if native else MachineChoice.HOST @FeatureNew('is_disabler', '0.52.0') + @typed_pos_args('is_disabler', object) @noKwargs - def func_is_disabler(self, node, args, kwargs): - if len(args) != 1: - raise InvalidCode('Is_disabler takes one argument.') - varname = args[0] - return isinstance(varname, Disabler) + def func_is_disabler(self, node: mparser.BaseNode, args: T.Tuple[object], kwargs: 'TYPE_kwargs') -> bool: + return isinstance(args[0], Disabler) @noKwargs @FeatureNew('range', '0.58.0') From 4d05f9d64bb1266a02fdc5ba41a1852176b1eca3 Mon Sep 17 00:00:00 2001 From: Dylan Baker Date: Thu, 1 Jul 2021 09:58:59 -0700 Subject: [PATCH 02/18] interpreter: use typed_pos_args for is_variable --- mesonbuild/interpreter/interpreter.py | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/mesonbuild/interpreter/interpreter.py b/mesonbuild/interpreter/interpreter.py index 97502ca22..2b6a90eaf 100644 --- a/mesonbuild/interpreter/interpreter.py +++ b/mesonbuild/interpreter/interpreter.py @@ -2753,13 +2753,10 @@ This will become a hard error in the future.''', location=self.current_node) return args[1] raise InterpreterException('Tried to get unknown variable "%s".' % varname) - @stringArgs + @typed_pos_args('is_variable', str) @noKwargs - def func_is_variable(self, node, args, kwargs): - if len(args) != 1: - raise InvalidCode('Is_variable takes two arguments.') - varname = args[0] - return varname in self.variables + def func_is_variable(self, node: mparser.BaseNode, args: T.Tuple[str], kwargs: 'TYPE_kwargs') -> bool: + return args[0] in self.variables @staticmethod def machine_from_native_kwarg(kwargs: T.Dict[str, T.Any]) -> MachineChoice: From 20c5dfe869897fe4de76e8f38281239e282387f2 Mon Sep 17 00:00:00 2001 From: Dylan Baker Date: Thu, 1 Jul 2021 10:01:54 -0700 Subject: [PATCH 03/18] interpreter: use typed_pos_args for get_variable --- mesonbuild/interpreter/interpreter.py | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/mesonbuild/interpreter/interpreter.py b/mesonbuild/interpreter/interpreter.py index 2b6a90eaf..0ffa0627f 100644 --- a/mesonbuild/interpreter/interpreter.py +++ b/mesonbuild/interpreter/interpreter.py @@ -11,7 +11,6 @@ # See the License for the specific language governing permissions and # limitations under the License. -from mesonbuild.interpreterbase.baseobjects import TYPE_kwargs from .. import mparser from .. import environment from .. import coredata @@ -32,7 +31,7 @@ from ..interpreterbase import InterpreterException, InvalidArguments, InvalidCod from ..interpreterbase import Disabler, disablerIfNotFound from ..interpreterbase import FeatureNew, FeatureDeprecated, FeatureNewKwargs, FeatureDeprecatedKwargs from ..interpreterbase import ObjectHolder, RangeHolder -from ..interpreterbase import TYPE_nkwargs, TYPE_nvar, TYPE_var +from ..interpreterbase.baseobjects import TYPE_nkwargs, TYPE_nvar, TYPE_var, TYPE_kwargs from ..modules import ExtensionModule, ModuleObject, MutableModuleObject, NewExtensionModule, NotFoundExtensionModule from ..cmake import CMakeInterpreter from ..backend.backends import Backend, ExecutableSerialisation @@ -2734,24 +2733,22 @@ This will become a hard error in the future.''', location=self.current_node) varname, value = args self.set_variable(varname, value, holderify=True) + @typed_pos_args('get_variable', (str, Disabler), optargs=[object]) @noKwargs @noArgsFlattening @permissive_unholder_return - def func_get_variable(self, node, args, kwargs): - if len(args) < 1 or len(args) > 2: - raise InvalidCode('Get_variable takes one or two arguments.') - varname = args[0] + def func_get_variable(self, node: mparser.BaseNode, args: T.Tuple[T.Union[str, Disabler], T.Optional[object]], + kwargs: 'TYPE_kwargs') -> 'TYPE_var': + varname, fallback = args if isinstance(varname, Disabler): return varname - if not isinstance(varname, str): - raise InterpreterException('First argument must be a string.') + try: return self.variables[varname] except KeyError: - pass - if len(args) == 2: - return args[1] - raise InterpreterException('Tried to get unknown variable "%s".' % varname) + if fallback is not None: + return fallback + raise InterpreterException(f'Tried to get unknown variable "{varname}".') @typed_pos_args('is_variable', str) @noKwargs From 9ecd578167790d3d5d857663db520d3cd423e28b Mon Sep 17 00:00:00 2001 From: Dylan Baker Date: Thu, 1 Jul 2021 10:03:42 -0700 Subject: [PATCH 04/18] interpreter: use typed_pos_args for set_variable --- mesonbuild/interpreter/interpreter.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/mesonbuild/interpreter/interpreter.py b/mesonbuild/interpreter/interpreter.py index 0ffa0627f..33115acda 100644 --- a/mesonbuild/interpreter/interpreter.py +++ b/mesonbuild/interpreter/interpreter.py @@ -2724,12 +2724,11 @@ This will become a hard error in the future.''', location=self.current_node) def is_subproject(self): return self.subproject != '' + @typed_pos_args('set_variable', str, object) @noKwargs @noArgsFlattening @noSecondLevelHolderResolving - def func_set_variable(self, node, args, kwargs): - if len(args) != 2: - raise InvalidCode('Set_variable takes two arguments.') + def func_set_variable(self, node: mparser.BaseNode, args: T.Tuple[str, object], kwargs: 'TYPE_kwargs') -> None: varname, value = args self.set_variable(varname, value, holderify=True) From e71a6544c523c35897f3e11c8c06395d75fa4d4d Mon Sep 17 00:00:00 2001 From: Dylan Baker Date: Thu, 1 Jul 2021 10:05:52 -0700 Subject: [PATCH 05/18] interpreter: use typed_pos_args for join_paths --- mesonbuild/interpreter/interpreter.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/mesonbuild/interpreter/interpreter.py b/mesonbuild/interpreter/interpreter.py index 33115acda..35dbaf366 100644 --- a/mesonbuild/interpreter/interpreter.py +++ b/mesonbuild/interpreter/interpreter.py @@ -2470,10 +2470,10 @@ This will become a hard error in the future.''' % kwargs['input'], location=self initial_values = {} return EnvironmentVariablesObject(initial_values, self.subproject) - @stringArgs + @typed_pos_args('join_paths', varargs=str, min_varargs=1) @noKwargs - def func_join_paths(self, node, args, kwargs): - return self.join_path_strings(args) + def func_join_paths(self, node: mparser.BaseNode, args: T.Tuple[T.List[str]], kwargs: 'TYPE_kwargs') -> str: + return self.join_path_strings(args[0]) def run(self) -> None: super().run() From 5aed9dd93963b69a5036bacfe0a701ce04cf7798 Mon Sep 17 00:00:00 2001 From: Dylan Baker Date: Thu, 1 Jul 2021 10:12:28 -0700 Subject: [PATCH 06/18] interpreter: use typed_pos_args for add_test_setup --- mesonbuild/interpreter/interpreter.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/mesonbuild/interpreter/interpreter.py b/mesonbuild/interpreter/interpreter.py index 35dbaf366..ef3058c3c 100644 --- a/mesonbuild/interpreter/interpreter.py +++ b/mesonbuild/interpreter/interpreter.py @@ -2333,10 +2333,8 @@ This will become a hard error in the future.''' % kwargs['input'], location=self @permittedKwargs({'exe_wrapper', 'gdb', 'timeout_multiplier', 'env', 'is_default', 'exclude_suites'}) - @stringArgs - def func_add_test_setup(self, node, args, kwargs): - if len(args) != 1: - raise InterpreterException('Add_test_setup needs one argument for the setup name.') + @typed_pos_args('add_test_setup', str) + def func_add_test_setup(self, node: mparser.BaseNode, args: T.Tuple[str], kwargs: 'TYPE_kwargs') -> None: setup_name = args[0] if re.fullmatch('([_a-zA-Z][_0-9a-zA-Z]*:)?[_a-zA-Z][_0-9a-zA-Z]*', setup_name) is None: raise InterpreterException('Setup name may only contain alphanumeric characters.') From 3135b130b83c9f4058ae45ff0f6e368e22958c99 Mon Sep 17 00:00:00 2001 From: Dylan Baker Date: Thu, 1 Jul 2021 10:14:23 -0700 Subject: [PATCH 07/18] interpreter: use typed_pos_args for include_directories --- mesonbuild/interpreter/interpreter.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/mesonbuild/interpreter/interpreter.py b/mesonbuild/interpreter/interpreter.py index ef3058c3c..66f2dd29f 100644 --- a/mesonbuild/interpreter/interpreter.py +++ b/mesonbuild/interpreter/interpreter.py @@ -2269,9 +2269,10 @@ This will become a hard error in the future.''' % kwargs['input'], location=self return result @permittedKwargs({'is_system'}) - @stringArgs - def func_include_directories(self, node, args, kwargs): - return self.build_incdir_object(args, kwargs.get('is_system', False)) + @typed_pos_args('include_directories', varargs=str) + def func_include_directories(self, node: mparser.BaseNode, args: T.Tuple[T.List[str]], + kwargs: 'TYPE_kwargs') -> build.IncludeDirs: + return self.build_incdir_object(args[0], kwargs.get('is_system', False)) def build_incdir_object(self, incdir_strings: T.List[str], is_system: bool = False) -> build.IncludeDirs: if not isinstance(is_system, bool): From 09d7da19c18d788e48cb46dbf10d791dabdf7eb9 Mon Sep 17 00:00:00 2001 From: Dylan Baker Date: Thu, 1 Jul 2021 10:15:52 -0700 Subject: [PATCH 08/18] interpreter: use typed_kwargs for include_directories --- mesonbuild/interpreter/interpreter.py | 6 +++--- mesonbuild/interpreter/kwargs.py | 5 +++++ 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/mesonbuild/interpreter/interpreter.py b/mesonbuild/interpreter/interpreter.py index 66f2dd29f..baf2e9de6 100644 --- a/mesonbuild/interpreter/interpreter.py +++ b/mesonbuild/interpreter/interpreter.py @@ -2268,11 +2268,11 @@ This will become a hard error in the future.''' % kwargs['input'], location=self raise InterpreterException('Include directory objects can only be created from strings or include directories.') return result - @permittedKwargs({'is_system'}) @typed_pos_args('include_directories', varargs=str) + @typed_kwargs('include_directories', KwargInfo('is_system', bool, default=False)) def func_include_directories(self, node: mparser.BaseNode, args: T.Tuple[T.List[str]], - kwargs: 'TYPE_kwargs') -> build.IncludeDirs: - return self.build_incdir_object(args[0], kwargs.get('is_system', False)) + kwargs: 'kwargs.FuncIncludeDirectories') -> build.IncludeDirs: + return self.build_incdir_object(args[0], kwargs['is_system']) def build_incdir_object(self, incdir_strings: T.List[str], is_system: bool = False) -> build.IncludeDirs: if not isinstance(is_system, bool): diff --git a/mesonbuild/interpreter/kwargs.py b/mesonbuild/interpreter/kwargs.py index b92b66fd7..2851e5af5 100644 --- a/mesonbuild/interpreter/kwargs.py +++ b/mesonbuild/interpreter/kwargs.py @@ -137,3 +137,8 @@ class FuncInstallMan(TypedDict): class FuncImportModule(ExtractRequired): disabler: bool + + +class FuncIncludeDirectories(TypedDict): + + is_system: bool From 982973f303e3d0431d9b79f89cdf2c8f1ee67bc0 Mon Sep 17 00:00:00 2001 From: Dylan Baker Date: Thu, 1 Jul 2021 10:19:10 -0700 Subject: [PATCH 09/18] interpreter: use typed_pos_args for alias_target --- mesonbuild/interpreter/interpreter.py | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/mesonbuild/interpreter/interpreter.py b/mesonbuild/interpreter/interpreter.py index baf2e9de6..41cea4487 100644 --- a/mesonbuild/interpreter/interpreter.py +++ b/mesonbuild/interpreter/interpreter.py @@ -1778,17 +1778,11 @@ This will become a hard error in the future.''' % kwargs['input'], location=self return tg @FeatureNew('alias_target', '0.52.0') + @typed_pos_args('alias_target', str, varargs=build.Target, min_varargs=1) @noKwargs - def func_alias_target(self, node, args, kwargs): - if len(args) < 2: - raise InvalidCode('alias_target takes at least 2 arguments.') - name = args[0] - if not isinstance(name, str): - raise InterpreterException('First argument must be a string.') - deps = listify(args[1:]) - for d in deps: - if not isinstance(d, (build.BuildTarget, build.CustomTarget)): - raise InterpreterException('Depends items must be build targets.') + def func_alias_target(self, node: mparser.BaseNode, args: T.Tuple[str, T.List[build.Target]], + kwargs: 'TYPE_kwargs') -> build.AliasTarget: + name, deps = args tg = build.AliasTarget(name, deps, self.subdir, self.subproject) self.add_target(name, tg) return tg From 6f6db0f2e36c61c309ff8805e0331ec80d807ecd Mon Sep 17 00:00:00 2001 From: Dylan Baker Date: Thu, 1 Jul 2021 10:22:36 -0700 Subject: [PATCH 10/18] interpreter: use typed_pos_args configuration_data --- mesonbuild/interpreter/interpreter.py | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/mesonbuild/interpreter/interpreter.py b/mesonbuild/interpreter/interpreter.py index 41cea4487..6548002dd 100644 --- a/mesonbuild/interpreter/interpreter.py +++ b/mesonbuild/interpreter/interpreter.py @@ -1055,15 +1055,12 @@ external dependencies (including libraries) must go to "dependencies".''') return opt.value return opt + @typed_pos_args('configuration_data', optargs=[dict]) @noKwargs - def func_configuration_data(self, node, args, kwargs): - if len(args) > 1: - raise InterpreterException('configuration_data takes only one optional positional arguments') - elif len(args) == 1: + def func_configuration_data(self, node: mparser.BaseNode, args: T.Optional[dict], kwargs: 'TYPE_kwargs') -> ConfigurationDataObject: + if args is not None: FeatureNew.single_use('configuration_data dictionary', '0.49.0', self.subproject) initial_values = args[0] - if not isinstance(initial_values, dict): - raise InterpreterException('configuration_data first argument must be a dictionary') else: initial_values = {} return ConfigurationDataObject(self.subproject, initial_values) From 9f07a1ad412188c587e108244ceb90e5e5f446f0 Mon Sep 17 00:00:00 2001 From: Dylan Baker Date: Thu, 1 Jul 2021 10:24:41 -0700 Subject: [PATCH 11/18] interpreter: use typed_pos_args for get_option --- mesonbuild/interpreter/interpreter.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/mesonbuild/interpreter/interpreter.py b/mesonbuild/interpreter/interpreter.py index 6548002dd..746b06e52 100644 --- a/mesonbuild/interpreter/interpreter.py +++ b/mesonbuild/interpreter/interpreter.py @@ -1037,11 +1037,10 @@ external dependencies (including libraries) must go to "dependencies".''') raise InterpreterException('Tried to access unknown option "%s".' % optname) - @stringArgs + @typed_pos_args('get_option', str) @noKwargs - def func_get_option(self, nodes, args, kwargs): - if len(args) != 1: - raise InterpreterException('Argument required for get_option.') + def func_get_option(self, nodes: mparser.BaseNode, args: T.Tuple[str], + kwargs: 'TYPE_kwargs') -> T.Union[coredata.UserOption, 'TYPE_var']: optname = args[0] if ':' in optname: raise InterpreterException('Having a colon in option name is forbidden, ' From 2486938011ecff6990f7351cac40228d53c4bc05 Mon Sep 17 00:00:00 2001 From: Dylan Baker Date: Thu, 1 Jul 2021 10:25:51 -0700 Subject: [PATCH 12/18] interpreter: use typed_pos_args for subproject --- mesonbuild/interpreter/interpreter.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/mesonbuild/interpreter/interpreter.py b/mesonbuild/interpreter/interpreter.py index 746b06e52..09c415055 100644 --- a/mesonbuild/interpreter/interpreter.py +++ b/mesonbuild/interpreter/interpreter.py @@ -829,10 +829,8 @@ external dependencies (including libraries) must go to "dependencies".''') @FeatureNewKwargs('subproject', '0.38.0', ['default_options']) @permittedKwargs({'version', 'default_options', 'required'}) - @stringArgs - def func_subproject(self, nodes, args, kwargs): - if len(args) != 1: - raise InterpreterException('Subproject takes exactly one argument') + @typed_pos_args('subproject', str) + def func_subproject(self, nodes: mparser.BaseNode, args: T.Tuple[str], kwargs: 'TYPE_kwargs') -> SubprojectHolder: return self.do_subproject(args[0], 'meson', kwargs) def disabled_subproject(self, subp_name, disabled_feature=None, exception=None): From 3f6afa26930b818b11dedd84a081b6a8778a4fea Mon Sep 17 00:00:00 2001 From: Dylan Baker Date: Thu, 1 Jul 2021 10:30:42 -0700 Subject: [PATCH 13/18] interpreter: use typed_pos_args for assert --- mesonbuild/interpreter/interpreter.py | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/mesonbuild/interpreter/interpreter.py b/mesonbuild/interpreter/interpreter.py index 09c415055..4c31d956c 100644 --- a/mesonbuild/interpreter/interpreter.py +++ b/mesonbuild/interpreter/interpreter.py @@ -714,20 +714,14 @@ external dependencies (including libraries) must go to "dependencies".''') variables) return dep + @typed_pos_args('assert', bool, optargs=[str]) @noKwargs - def func_assert(self, node, args, kwargs): - if len(args) == 1: + def func_assert(self, node: mparser.FunctionNode, args: T.Tuple[bool, T.Optional[str]], + kwargs: 'TYPE_kwargs') -> None: + value, message = args + if message is None: FeatureNew.single_use('assert function without message argument', '0.53.0', self.subproject) - value = args[0] - message = None - elif len(args) == 2: - value, message = args - if not isinstance(message, str): - raise InterpreterException('Assert message not a string.') - else: - raise InterpreterException('Assert takes between one and two arguments') - if not isinstance(value, bool): - raise InterpreterException('Assert value not bool.') + if not value: if message is None: from ..ast import AstPrinter From 015e44014ac6d4303f00a7fde64c1a0663305422 Mon Sep 17 00:00:00 2001 From: Dylan Baker Date: Thu, 1 Jul 2021 10:39:35 -0700 Subject: [PATCH 14/18] interpreter: use typed_pos_args for subdir --- mesonbuild/interpreter/interpreter.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mesonbuild/interpreter/interpreter.py b/mesonbuild/interpreter/interpreter.py index 4c31d956c..0671bc023 100644 --- a/mesonbuild/interpreter/interpreter.py +++ b/mesonbuild/interpreter/interpreter.py @@ -1929,8 +1929,8 @@ This will become a hard error in the future.''' % kwargs['input'], location=self @FeatureNewKwargs('subdir', '0.44.0', ['if_found']) @permittedKwargs({'if_found'}) - def func_subdir(self, node, args, kwargs): - self.validate_arguments(args, 1, [str]) + @typed_pos_args('subdir', str) + def func_subdir(self, node: mparser.BaseNode, args: T.Tuple[str], kwargs: 'TYPE_kwargs') -> None: mesonlib.check_direntry_issues(args) if '..' in args[0]: raise InvalidArguments('Subdir contains ..') From 011b58d75fd2fd7cee740e65d63859f2c3ba87f1 Mon Sep 17 00:00:00 2001 From: Dylan Baker Date: Thu, 1 Jul 2021 10:44:06 -0700 Subject: [PATCH 15/18] interpreter: use typed_pos_args for project --- mesonbuild/interpreter/interpreter.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/mesonbuild/interpreter/interpreter.py b/mesonbuild/interpreter/interpreter.py index 0671bc023..7c737958d 100644 --- a/mesonbuild/interpreter/interpreter.py +++ b/mesonbuild/interpreter/interpreter.py @@ -1079,12 +1079,10 @@ external dependencies (including libraries) must go to "dependencies".''') options = {k: v for k, v in self.environment.options.items() if k.is_backend()} self.coredata.set_options(options) - @stringArgs @permittedKwargs({'version', 'meson_version', 'default_options', 'license', 'subproject_dir'}) - def func_project(self, node, args, kwargs): - if len(args) < 1: - raise InvalidArguments('Not enough arguments to project(). Needs at least the project name.') - proj_name, *proj_langs = args + @typed_pos_args('project', str, varargs=str) + def func_project(self, node: mparser.FunctionNode, args: T.Tuple[str, T.List[str]], kwargs: 'TYPE_kwargs') -> None: + proj_name, proj_langs = args if ':' in proj_name: raise InvalidArguments(f"Project name {proj_name!r} must not contain ':'") From 011f13bcdcf366d43986227e61881e04f1d33c95 Mon Sep 17 00:00:00 2001 From: Dylan Baker Date: Thu, 1 Jul 2021 10:45:52 -0700 Subject: [PATCH 16/18] interpreter: use typed_pos_args for add_langauges --- mesonbuild/interpreter/interpreter.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/mesonbuild/interpreter/interpreter.py b/mesonbuild/interpreter/interpreter.py index 7c737958d..3684a86dc 100644 --- a/mesonbuild/interpreter/interpreter.py +++ b/mesonbuild/interpreter/interpreter.py @@ -1194,15 +1194,16 @@ external dependencies (including libraries) must go to "dependencies".''') @FeatureNewKwargs('add_languages', '0.54.0', ['native']) @permittedKwargs({'required', 'native'}) - @stringArgs - def func_add_languages(self, node, args, kwargs): + @typed_pos_args('add_languages', varargs=str) + def func_add_languages(self, node: mparser.FunctionNode, args: T.Tuple[T.List[str]], kwargs: 'TYPE_kwargs') -> bool: + langs = args[0] disabled, required, feature = extract_required_kwarg(kwargs, self.subproject) if disabled: - for lang in sorted(args, key=compilers.sort_clink): + for lang in sorted(langs, key=compilers.sort_clink): mlog.log('Compiler for language', mlog.bold(lang), 'skipped: feature', mlog.bold(feature), 'disabled') return False if 'native' in kwargs: - return self.add_languages(args, required, self.machine_from_native_kwarg(kwargs)) + return self.add_languages(langs, required, self.machine_from_native_kwarg(kwargs)) else: # absent 'native' means 'both' for backwards compatibility tv = FeatureNew.get_target_version(self.subproject) @@ -1210,8 +1211,8 @@ external dependencies (including libraries) must go to "dependencies".''') mlog.warning('add_languages is missing native:, assuming languages are wanted for both host and build.', location=self.current_node) - success = self.add_languages(args, False, MachineChoice.BUILD) - success &= self.add_languages(args, required, MachineChoice.HOST) + success = self.add_languages(langs, False, MachineChoice.BUILD) + success &= self.add_languages(langs, required, MachineChoice.HOST) return success @noArgsFlattening From 52c68ca6feecaf652375a3340db9d4160087e392 Mon Sep 17 00:00:00 2001 From: Dylan Baker Date: Thu, 1 Jul 2021 10:49:34 -0700 Subject: [PATCH 17/18] interpreter: use typed_pos_args for files --- mesonbuild/interpreter/interpreter.py | 28 +++++++++++---------------- 1 file changed, 11 insertions(+), 17 deletions(-) diff --git a/mesonbuild/interpreter/interpreter.py b/mesonbuild/interpreter/interpreter.py index 3684a86dc..5e058cef8 100644 --- a/mesonbuild/interpreter/interpreter.py +++ b/mesonbuild/interpreter/interpreter.py @@ -650,10 +650,10 @@ class Interpreter(InterpreterBase, HoldableObject): modname = 'unstable_' + plainname return self._import_module(modname, required) - @stringArgs + @typed_pos_args('files', varargs=str) @noKwargs - def func_files(self, node, args, kwargs): - return [mesonlib.File.from_source_file(self.environment.source_dir, self.subdir, fname) for fname in args] + def func_files(self, node: mparser.FunctionNode, args: T.Tuple[T.List[str]], kwargs: 'TYPE_kwargs') -> T.List[mesonlib.File]: + return [mesonlib.File.from_source_file(self.environment.source_dir, self.subdir, fname) for fname in args[0]] # Used by declare_dependency() and pkgconfig.generate() def extract_variables(self, kwargs, argname='variables', list_new=False, dict_new=False): @@ -1690,7 +1690,6 @@ external dependencies (including libraries) must go to "dependencies".''') def func_subdir_done(self, node, args, kwargs): raise SubdirDoneRequest() - @stringArgs @FeatureNewKwargs('custom_target', '0.57.0', ['env']) @FeatureNewKwargs('custom_target', '0.48.0', ['console']) @FeatureNewKwargs('custom_target', '0.47.0', ['install_mode', 'build_always_stale']) @@ -1700,9 +1699,8 @@ external dependencies (including libraries) must go to "dependencies".''') 'build_always', 'capture', 'depends', 'depend_files', 'depfile', 'build_by_default', 'build_always_stale', 'console', 'env', 'feed'}) - def func_custom_target(self, node, args, kwargs): - if len(args) != 1: - raise InterpreterException('custom_target: Only one positional argument is allowed, and it must be a string name') + @typed_pos_args('custom_target', str) + def func_custom_target(self, node: mparser.FunctionNode, args: T.Tuple[str], kwargs: 'TYPE_kwargs') -> build.CustomTarget: if 'depfile' in kwargs and ('@BASENAME@' in kwargs['depfile'] or '@PLAINNAME@' in kwargs['depfile']): FeatureNew.single_use('substitutions in custom_target depfile', '0.47.0', self.subproject) return self._func_custom_target_impl(node, args, kwargs) @@ -1727,16 +1725,12 @@ This will become a hard error in the future.''' % kwargs['input'], location=self @FeatureNewKwargs('run_target', '0.57.0', ['env']) @permittedKwargs({'command', 'depends', 'env'}) - def func_run_target(self, node, args, kwargs): - if len(args) > 1: - raise InvalidCode('Run_target takes only one positional argument: the target name.') - elif len(args) == 1: - if 'command' not in kwargs: - raise InterpreterException('Missing "command" keyword argument') - all_args = extract_as_list(kwargs, 'command') - deps = extract_as_list(kwargs, 'depends') - else: - raise InterpreterException('Run_target needs at least one positional argument.') + @typed_pos_args('run_target', str) + def func_run_target(self, node: mparser.FunctionNode, args: T.Tuple[str], kwargs: 'TYPE_kwargs') -> build.RunTarget: + if 'command' not in kwargs: + raise InterpreterException('Missing "command" keyword argument') + all_args = extract_as_list(kwargs, 'command') + deps = extract_as_list(kwargs, 'depends') cleaned_args = [] for i in listify(all_args): From f459c0e918d257af40665cb12a633cf932126731 Mon Sep 17 00:00:00 2001 From: Dylan Baker Date: Thu, 1 Jul 2021 10:49:57 -0700 Subject: [PATCH 18/18] interpreter: remove stringArgs uses It's only used now on a files that always raises an exception anyway, might as well just not do any checking and reduces the uses of that function --- mesonbuild/interpreter/interpreter.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/mesonbuild/interpreter/interpreter.py b/mesonbuild/interpreter/interpreter.py index 5e058cef8..488b034ce 100644 --- a/mesonbuild/interpreter/interpreter.py +++ b/mesonbuild/interpreter/interpreter.py @@ -26,7 +26,7 @@ from ..programs import ExternalProgram, NonExistingExternalProgram from ..dependencies import Dependency from ..depfile import DepFile from ..interpreterbase import ContainerTypeInfo, InterpreterBase, KwargInfo, typed_kwargs, typed_pos_args -from ..interpreterbase import noPosargs, noKwargs, stringArgs, permittedKwargs, noArgsFlattening, noSecondLevelHolderResolving, permissive_unholder_return +from ..interpreterbase import noPosargs, noKwargs, permittedKwargs, noArgsFlattening, noSecondLevelHolderResolving, permissive_unholder_return from ..interpreterbase import InterpreterException, InvalidArguments, InvalidCode, SubdirDoneRequest from ..interpreterbase import Disabler, disablerIfNotFound from ..interpreterbase import FeatureNew, FeatureDeprecated, FeatureNewKwargs, FeatureDeprecatedKwargs @@ -814,7 +814,6 @@ external dependencies (including libraries) must go to "dependencies".''') self.environment.get_build_command() + ['introspect'], in_builddir=in_builddir, check=check, capture=capture) - @stringArgs def func_gettext(self, nodes, args, kwargs): raise InterpreterException('Gettext() function has been moved to module i18n. Import it and use i18n.gettext() instead')