Blob Blame History Raw
From b705e45c48b79348bbb70fddc06b408a19ecedc7 Mon Sep 17 00:00:00 2001
From: Paolo Bonzini <pbonzini@redhat.com>
Date: Wed, 2 Nov 2022 10:08:52 +0100
Subject: [PATCH 3/9] Revert "coredata: throw a MesonException on unknown
 options"
Content-Type: text/plain

This reverts commit dbf2ace6ca1ce39aa01497f815b65856079cc581.
---
 mesonbuild/coredata.py         | 15 ++++++++-------
 unittests/allplatformstests.py |  8 +++-----
 2 files changed, 11 insertions(+), 12 deletions(-)

diff --git a/mesonbuild/coredata.py b/mesonbuild/coredata.py
index f34694281..b274a5777 100644
--- a/mesonbuild/coredata.py
+++ b/mesonbuild/coredata.py
@@ -803,7 +803,7 @@ class CoreData:
                 except KeyError:
                     continue
 
-    def set_options(self, options: T.Dict[OptionKey, T.Any], subproject: str = '') -> None:
+    def set_options(self, options: T.Dict[OptionKey, T.Any], subproject: str = '', warn_unknown: bool = True) -> None:
         if not self.is_cross_build():
             options = {k: v for k, v in options.items() if k.machine is not MachineChoice.BUILD}
         # Set prefix first because it's needed to sanitize other options
@@ -819,15 +819,16 @@ class CoreData:
         for k, v in options.items():
             if k == pfk:
                 continue
-            elif k in self.options:
-                self.set_option(k, v)
-            elif k.machine != MachineChoice.BUILD:
+            elif k not in self.options:
                 unknown_options.append(k)
-        if unknown_options:
+            else:
+                self.set_option(k, v)
+        if unknown_options and warn_unknown:
             unknown_options_str = ', '.join(sorted(str(s) for s in unknown_options))
             sub = f'In subproject {subproject}: ' if subproject else ''
-            raise MesonException(f'{sub}Unknown options: "{unknown_options_str}"')
-
+            mlog.warning(f'{sub}Unknown options: "{unknown_options_str}"')
+            mlog.log('The value of new options can be set with:')
+            mlog.log(mlog.bold('meson setup <builddir> --reconfigure -Dnew_option=new_value ...'))
         if not self.is_cross_build():
             self.copy_build_options_from_regular_ones()
 
diff --git a/unittests/allplatformstests.py b/unittests/allplatformstests.py
index 6ba95b652..f848cc547 100644
--- a/unittests/allplatformstests.py
+++ b/unittests/allplatformstests.py
@@ -2297,11 +2297,9 @@ class AllPlatformTests(BasePlatformTests):
             self.assertEqual(obj.options[OptionKey('default_library')].value, 'shared')
         self.wipe()
 
-        # Should fail on unknown options
-        with self.assertRaises((subprocess.CalledProcessError, RuntimeError)) as cm:
-            self.init(testdir, extra_args=['-Dbad=1', '-Dfoo=2', '-Dwrong_link_args=foo'])
-            self.assertNotEqual(0, cm.exception.returncode)
-            self.assertIn(msg, cm.exception.output)
+        # Should warn on unknown options
+        out = self.init(testdir, extra_args=['-Dbad=1', '-Dfoo=2', '-Dwrong_link_args=foo'])
+        self.assertIn('Unknown options: "bad, foo, wrong_link_args"', out)
         self.wipe()
 
         # Should fail on malformed option
-- 
2.38.1