InterpreterBase: Fix extracting the node in all method/function calls

Closes: #4813.
pull/4818/head
Xavier Claessens 6 years ago
parent 0d195cefa6
commit 4b4f642e6a
  1. 35
      mesonbuild/interpreterbase.py

@ -47,14 +47,14 @@ def _get_callee_args(wrapped_args, want_subproject=False):
if want_subproject and n == 2:
if hasattr(s, 'subproject'):
# Interpreter base types have 2 args: self, node
node_or_state = wrapped_args[1]
node = wrapped_args[1]
# args and kwargs are inside the node
args = None
kwargs = None
subproject = s.subproject
elif hasattr(wrapped_args[1], 'subproject'):
# Module objects have 2 args: self, interpreter
node_or_state = wrapped_args[1]
node = wrapped_args[1].current_node
# args and kwargs are inside the node
args = None
kwargs = None
@ -63,7 +63,7 @@ def _get_callee_args(wrapped_args, want_subproject=False):
raise AssertionError('Unknown args: {!r}'.format(wrapped_args))
elif n == 3:
# Methods on objects (*Holder, MesonMain, etc) have 3 args: self, args, kwargs
node_or_state = None # FIXME
node = s.current_node
args = wrapped_args[1]
kwargs = wrapped_args[2]
if want_subproject:
@ -73,30 +73,32 @@ def _get_callee_args(wrapped_args, want_subproject=False):
subproject = s.interpreter.subproject
elif n == 4:
# Meson functions have 4 args: self, node, args, kwargs
# Module functions have 4 args: self, state, args, kwargs; except,
# PythonInstallation methods have self, interpreter, args, kwargs
node_or_state = wrapped_args[1]
# Module functions have 4 args: self, state, args, kwargs
if isinstance(s, InterpreterBase):
node = wrapped_args[1]
else:
node = wrapped_args[1].current_node
args = wrapped_args[2]
kwargs = wrapped_args[3]
if want_subproject:
if isinstance(s, InterpreterBase):
subproject = s.subproject
else:
subproject = node_or_state.subproject
subproject = wrapped_args[1].subproject
elif n == 5:
# Module snippets have 5 args: self, interpreter, state, args, kwargs
node_or_state = wrapped_args[2]
node = wrapped_args[2].current_node
args = wrapped_args[3]
kwargs = wrapped_args[4]
if want_subproject:
subproject = node_or_state.subproject
subproject = wrapped_args[2].subproject
else:
raise AssertionError('Unknown args: {!r}'.format(wrapped_args))
# Sometimes interpreter methods are called internally with None instead of
# empty list/dict
args = args if args is not None else []
kwargs = kwargs if kwargs is not None else {}
return s, node_or_state, args, kwargs, subproject
return s, node, args, kwargs, subproject
def flatten(args):
if isinstance(args, mparser.StringNode):
@ -164,19 +166,10 @@ class permittedKwargs:
def __call__(self, f):
@wraps(f)
def wrapped(*wrapped_args, **wrapped_kwargs):
s, node_or_state, args, kwargs, _ = _get_callee_args(wrapped_args)
loc = types.SimpleNamespace()
if hasattr(s, 'subdir'):
loc.subdir = s.subdir
loc.lineno = s.current_lineno
elif node_or_state and hasattr(node_or_state, 'subdir'):
loc.subdir = node_or_state.subdir
loc.lineno = node_or_state.current_lineno
else:
loc = None
s, node, args, kwargs, _ = _get_callee_args(wrapped_args)
for k in kwargs:
if k not in self.permitted:
mlog.warning('''Passed invalid keyword argument "{}".'''.format(k), location=loc)
mlog.warning('''Passed invalid keyword argument "{}".'''.format(k), location=node)
mlog.warning('This will become a hard error in the future.')
return f(*wrapped_args, **wrapped_kwargs)
return wrapped

Loading…
Cancel
Save