From 3e651719cc336f6626cf401aabf2c4c67ce05bd5 Mon Sep 17 00:00:00 2001 From: Charles Brunet Date: Wed, 28 Feb 2024 09:23:46 -0500 Subject: [PATCH] Fix unknown base options not detected in commandline arguments --- mesonbuild/coredata.py | 7 ++++++- unittests/platformagnostictests.py | 7 +++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/mesonbuild/coredata.py b/mesonbuild/coredata.py index b81c98b32ac7..72f0054c05aa 100644 --- a/mesonbuild/coredata.py +++ b/mesonbuild/coredata.py @@ -974,6 +974,8 @@ def set_options(self, options: T.Dict[OptionKey, T.Any], subproject: str = '', f return dirty def set_default_options(self, default_options: T.MutableMapping[OptionKey, str], subproject: str, env: 'Environment') -> None: + from .compilers import base_options + # Main project can set default options on subprojects, but subprojects # can only set default options on themselves. # Preserve order: if env.options has 'buildtype' it must come after @@ -1005,7 +1007,10 @@ def set_default_options(self, default_options: T.MutableMapping[OptionKey, str], continue # Skip base, compiler, and backend options, they are handled when # adding languages and setting backend. - if k.type in {OptionType.COMPILER, OptionType.BACKEND, OptionType.BASE}: + if k.type == OptionType.BASE and k in base_options: + # set_options will report unknown base options + continue + if k.type in {OptionType.COMPILER, OptionType.BACKEND}: continue options[k] = v diff --git a/unittests/platformagnostictests.py b/unittests/platformagnostictests.py index 7875a73ebc1d..28a79a0d4b7b 100644 --- a/unittests/platformagnostictests.py +++ b/unittests/platformagnostictests.py @@ -285,3 +285,10 @@ def test_reconfigure_base_options(self): out = self.init(testdir, extra_args=['--reconfigure', '-Db_ndebug=if-release', '-Dc_std=c99'], inprocess=True) self.assertIn('\nMessage: b_ndebug: if-release\n', out) self.assertIn('\nMessage: c_std: c99\n', out) + + def test_setup_with_unknown_option(self): + testdir = os.path.join(self.common_test_dir, '1 trivial') + + for option in ('not_an_option', 'b_not_an_option'): + out = self.init(testdir, extra_args=['--wipe', f'-D{option}=1'], inprocess=True, allow_fail=True) + self.assertIn(f'ERROR: Unknown options: "{option}"', out)