Blame SOURCES/0002-Revert-decorators-Make-unknown-kwarg-fatal.patch

5515ae
From cb683b38e0252d545650d55424ba4f7077c5b813 Mon Sep 17 00:00:00 2001
5515ae
From: Paolo Bonzini <pbonzini@redhat.com>
5515ae
Date: Wed, 2 Nov 2022 10:07:17 +0100
5515ae
Subject: [PATCH 2/9] Revert "decorators: Make unknown kwarg fatal"
5515ae
Content-Type: text/plain
5515ae
5515ae
This reverts commit 88a1bed81b7d9ad262d3b511eb20444c609db235.
5515ae
---
5515ae
 mesonbuild/interpreterbase/decorators.py         | 16 ++++++++++------
5515ae
 .../common/129 build by default/meson.build      |  1 +
5515ae
 test cases/frameworks/7 gnome/gir/meson.build    |  4 ++++
5515ae
 test cases/unit/22 warning location/meson.build  |  2 +-
5515ae
 unittests/allplatformstests.py                   |  6 +++---
5515ae
 5 files changed, 19 insertions(+), 10 deletions(-)
5515ae
5515ae
diff --git a/mesonbuild/interpreterbase/decorators.py b/mesonbuild/interpreterbase/decorators.py
5515ae
index 5dd8b8982..41c959a63 100644
5515ae
--- a/mesonbuild/interpreterbase/decorators.py
5515ae
+++ b/mesonbuild/interpreterbase/decorators.py
5515ae
@@ -119,11 +119,11 @@ class permittedKwargs:
5515ae
     def __call__(self, f: TV_func) -> TV_func:
5515ae
         @wraps(f)
5515ae
         def wrapped(*wrapped_args: T.Any, **wrapped_kwargs: T.Any) -> T.Any:
5515ae
-            kwargs = get_callee_args(wrapped_args)[2]
5515ae
-            unknowns = set(kwargs).difference(self.permitted)
5515ae
-            if unknowns:
5515ae
-                ustr = ', '.join([f'"{u}"' for u in sorted(unknowns)])
5515ae
-                raise InvalidArguments(f'Got unknown keyword arguments {ustr}')
5515ae
+            node, args, kwargs, _ = get_callee_args(wrapped_args)
5515ae
+            for k in kwargs:
5515ae
+                if k not in self.permitted:
5515ae
+                    mlog.warning(f'''Passed invalid keyword argument "{k}".''', location=node)
5515ae
+                    mlog.warning('This will become a hard error in the future.')
5515ae
             return f(*wrapped_args, **wrapped_kwargs)
5515ae
         return T.cast('TV_func', wrapped)
5515ae
 
5515ae
@@ -532,8 +532,12 @@ def typed_kwargs(name: str, *types: KwargInfo) -> T.Callable[..., T.Any]:
5515ae
             all_names = {t.name for t in types}
5515ae
             unknowns = set(kwargs).difference(all_names)
5515ae
             if unknowns:
5515ae
+                # Warn about unknown argumnts, delete them and continue. This
5515ae
+                # keeps current behavior
5515ae
                 ustr = ', '.join([f'"{u}"' for u in sorted(unknowns)])
5515ae
-                raise InvalidArguments(f'{name} got unknown keyword arguments {ustr}')
5515ae
+                mlog.warning(f'{name} got unknown keyword arguments {ustr}')
5515ae
+                for u in unknowns:
5515ae
+                    del kwargs[u]
5515ae
 
5515ae
             for info in types:
5515ae
                 types_tuple = info.types if isinstance(info.types, tuple) else (info.types,)
5515ae
diff --git a/test cases/common/129 build by default/meson.build b/test cases/common/129 build by default/meson.build
5515ae
index b797f76e9..b28b6347c 100644
5515ae
--- a/test cases/common/129 build by default/meson.build	
5515ae
+++ b/test cases/common/129 build by default/meson.build	
5515ae
@@ -9,6 +9,7 @@ executable('fooprog', 'foo.c',
5515ae
 
5515ae
 executable('barprog', 'foo.c',
5515ae
     build_by_default : false,
5515ae
+    build_always : true,
5515ae
 )
5515ae
 
5515ae
 comp = files('mygen.py')
5515ae
diff --git a/test cases/frameworks/7 gnome/gir/meson.build b/test cases/frameworks/7 gnome/gir/meson.build
5515ae
index fbff2060e..64c49f729 100644
5515ae
--- a/test cases/frameworks/7 gnome/gir/meson.build	
5515ae
+++ b/test cases/frameworks/7 gnome/gir/meson.build	
5515ae
@@ -46,6 +46,10 @@ gnome.generate_gir(
5515ae
   dependencies : [[fake_dep, dep1_dep]],
5515ae
   install : true,
5515ae
   build_by_default : true,
5515ae
+  # Test that unknown kwargs do not crash the parser.
5515ae
+  # Unknown kwargs will eventually become a hard error.
5515ae
+  # Once that happens remove this.
5515ae
+  unknown_kwarg : true,
5515ae
 )
5515ae
 
5515ae
 test('gobject introspection/c', girexe)
5515ae
diff --git a/test cases/unit/22 warning location/meson.build b/test cases/unit/22 warning location/meson.build
5515ae
index 132939e04..52a93d18c 100644
5515ae
--- a/test cases/unit/22 warning location/meson.build	
5515ae
+++ b/test cases/unit/22 warning location/meson.build	
5515ae
@@ -1,4 +1,4 @@
5515ae
-project('warning location', 'c')
5515ae
+project('warning location', 'c', invalid: 'cheese')
5515ae
 a = library('liba', 'a.c')
5515ae
 b = library('libb', 'b.c')
5515ae
 executable('main', 'main.c', link_with: a, link_with: b)
5515ae
diff --git a/unittests/allplatformstests.py b/unittests/allplatformstests.py
5515ae
index 0b968e7cf..6ba95b652 100644
5515ae
--- a/unittests/allplatformstests.py
5515ae
+++ b/unittests/allplatformstests.py
5515ae
@@ -1931,6 +1931,7 @@ class AllPlatformTests(BasePlatformTests):
5515ae
             r'sub' + os.path.sep + r'meson.build:4: WARNING: subdir warning',
5515ae
             r'meson.build:7: WARNING: Module unstable-simd has no backwards or forwards compatibility and might not exist in future releases.',
5515ae
             r"meson.build:11: WARNING: The variable(s) 'MISSING' in the input file 'conf.in' are not present in the given configuration data.",
5515ae
+            r'meson.build:1: WARNING: Passed invalid keyword argument "invalid".',
5515ae
         ]:
5515ae
             self.assertRegex(out, re.escape(expected))
5515ae
 
5515ae
@@ -1980,9 +1981,8 @@ class AllPlatformTests(BasePlatformTests):
5515ae
 
5515ae
     def test_permitted_method_kwargs(self):
5515ae
         tdir = os.path.join(self.unit_test_dir, '25 non-permitted kwargs')
5515ae
-        with self.assertRaises(subprocess.CalledProcessError) as cm:
5515ae
-            self.init(tdir)
5515ae
-        self.assertIn('ERROR: compiler.has_header_symbol got unknown keyword arguments "prefixxx"', cm.exception.output)
5515ae
+        out = self.init(tdir, allow_fail=True)
5515ae
+        self.assertIn('Function does not take keyword arguments.', out)
5515ae
 
5515ae
     def test_templates(self):
5515ae
         ninja = mesonbuild.environment.detect_ninja()
5515ae
-- 
5515ae
2.38.1
5515ae