From 1dc13e9951a5ce38edb93718ab5ac7b1bf6616d0 Mon Sep 17 00:00:00 2001 From: Tristan Partin Date: Tue, 10 Aug 2021 18:02:39 -0500 Subject: Add unset_variable() This should be useful for helping to control variable scope within Meson. CMake has something similar for controlling scope. --- mesonbuild/interpreter/interpreter.py | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'mesonbuild/interpreter/interpreter.py') diff --git a/mesonbuild/interpreter/interpreter.py b/mesonbuild/interpreter/interpreter.py index b527115..ab7efa0 100644 --- a/mesonbuild/interpreter/interpreter.py +++ b/mesonbuild/interpreter/interpreter.py @@ -360,6 +360,7 @@ class Interpreter(InterpreterBase, HoldableObject): 'static_library': self.func_static_lib, 'both_libraries': self.func_both_lib, 'test': self.func_test, + 'unset_variable': self.func_unset_variable, 'vcs_tag': self.func_vcs_tag, 'range': self.func_range, }) @@ -2638,6 +2639,16 @@ This will become a hard error in the future.''', location=self.current_node) def func_is_variable(self, node: mparser.BaseNode, args: T.Tuple[str], kwargs: 'TYPE_kwargs') -> bool: return args[0] in self.variables + @FeatureNew('unset_variable', '0.60.0') + @typed_pos_args('unset_variable', str) + @noKwargs + def func_unset_variable(self, node: mparser.BaseNode, args: T.Tuple[str], kwargs: 'TYPE_kwargs') -> None: + varname = args[0] + try: + del self.variables[varname] + except KeyError: + raise InterpreterException(f'Tried to unset unknown variable "{varname}".') + @staticmethod def machine_from_native_kwarg(kwargs: T.Dict[str, T.Any]) -> MachineChoice: native = kwargs.get('native', False) -- cgit v1.1