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