diff --git a/mesonbuild/interpreterbase.py b/mesonbuild/interpreterbase.py index 91f4bd3e9..9dc6b0f95 100644 --- a/mesonbuild/interpreterbase.py +++ b/mesonbuild/interpreterbase.py @@ -18,7 +18,7 @@ from . import mparser, mesonlib, mlog from . import environment, dependencies -import os, copy, re +import os, copy, re, types from functools import wraps # Decorators for method calls. @@ -63,17 +63,19 @@ class permittedKwargs: def __call__(self, f): @wraps(f) def wrapped(s, node_or_state, args, kwargs): + loc = types.SimpleNamespace() if hasattr(s, 'subdir'): - subdir = s.subdir - lineno = s.current_lineno + loc.subdir = s.subdir + loc.lineno = s.current_lineno elif hasattr(node_or_state, 'subdir'): - subdir = node_or_state.subdir - lineno = node_or_state.current_lineno + loc.subdir = node_or_state.subdir + loc.lineno = node_or_state.current_lineno + else: + loc = None for k in kwargs: if k not in self.permitted: - fname = os.path.join(subdir, environment.build_filename) - mlog.warning('''Passed invalid keyword argument "%s" in %s line %d. -This will become a hard error in the future.''' % (k, fname, lineno)) + mlog.warning('''Passed invalid keyword argument "{}"'''.format(k), location=loc) + mlog.warning('This will become a hard error in the future.') return f(s, node_or_state, args, kwargs) return wrapped diff --git a/run_unittests.py b/run_unittests.py index 11f16a24d..c634b8b2b 100755 --- a/run_unittests.py +++ b/run_unittests.py @@ -1717,6 +1717,7 @@ int main(int argc, char **argv) { r'WARNING: subdir warning in file sub' + os.path.sep + r'meson.build, line 4', r'WARNING: Module unstable-simd has no backwards or forwards compatibility and might not exist in future releases in file meson.build, line 7', r"WARNING: The variable(s) 'MISSING' in the input file conf.in are not present in the given configuration data in file meson.build, line 10", + r'WARNING: Passed invalid keyword argument "invalid" in file meson.build, line 1' ]: self.assertRegex(out, re.escape(expected)) diff --git a/test cases/unit/20 warning location/meson.build b/test cases/unit/20 warning location/meson.build index 0b14b8be9..15295a95c 100644 --- a/test cases/unit/20 warning location/meson.build +++ b/test cases/unit/20 warning location/meson.build @@ -1,4 +1,4 @@ -project('warning location', 'c') +project('warning location', 'c', invalid: 'cheese') a = library('liba', 'a.c') b = library('libb', 'b.c') executable('main', 'main.c', link_with: a, link_with: b)