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

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