diff options
author | Florian Schmaus <flo@geekplace.eu> | 2021-07-26 00:10:58 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-07-26 01:10:58 +0300 |
commit | dbf2ace6ca1ce39aa01497f815b65856079cc581 (patch) | |
tree | b4b9b7cfacc52b3f16f68963d278225c1026cb75 | |
parent | bf41d56597349a7047f2034e3e3e00d4502220cc (diff) | |
download | meson-dbf2ace6ca1ce39aa01497f815b65856079cc581.zip meson-dbf2ace6ca1ce39aa01497f815b65856079cc581.tar.gz meson-dbf2ace6ca1ce39aa01497f815b65856079cc581.tar.bz2 |
coredata: throw a MesonException on unknown options
Fixes #7288.
-rw-r--r-- | docs/markdown/snippets/unknown-options-always-fatal.md | 5 | ||||
-rw-r--r-- | mesonbuild/coredata.py | 15 | ||||
-rwxr-xr-x | run_unittests.py | 10 |
3 files changed, 17 insertions, 13 deletions
diff --git a/docs/markdown/snippets/unknown-options-always-fatal.md b/docs/markdown/snippets/unknown-options-always-fatal.md new file mode 100644 index 0000000..ce982c3 --- /dev/null +++ b/docs/markdown/snippets/unknown-options-always-fatal.md @@ -0,0 +1,5 @@ +## Unknown options are now always fatal + +Passing unknown options to "meson setup" or "meson configure" is now +always fatal. That is, Meson will exit with an error code if this +happens. Previous Meson versions only showed a warning message. diff --git a/mesonbuild/coredata.py b/mesonbuild/coredata.py index c2604be..37d830d 100644 --- a/mesonbuild/coredata.py +++ b/mesonbuild/coredata.py @@ -758,7 +758,7 @@ class CoreData: except KeyError: continue - def set_options(self, options: T.Dict[OptionKey, T.Any], subproject: str = '', warn_unknown: bool = True) -> None: + def set_options(self, options: T.Dict[OptionKey, T.Any], subproject: str = '') -> 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 @@ -774,16 +774,15 @@ class CoreData: for k, v in options.items(): if k == pfk: continue - elif k not in self.options: - unknown_options.append(k) - else: + elif k in self.options: self.set_option(k, v) - if unknown_options and warn_unknown: + elif k.machine != MachineChoice.BUILD: + unknown_options.append(k) + if unknown_options: unknown_options_str = ', '.join(sorted(str(s) for s in unknown_options)) sub = f'In subproject {subproject}: ' if subproject else '' - 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 ...')) + raise MesonException(f'{sub}Unknown options: "{unknown_options_str}"') + if not self.is_cross_build(): self.copy_build_options_from_regular_ones() diff --git a/run_unittests.py b/run_unittests.py index 324de94..8306782 100755 --- a/run_unittests.py +++ b/run_unittests.py @@ -3306,8 +3306,6 @@ class AllPlatformTests(BasePlatformTests): if cc.get_id() == 'clang': if is_windows(): raise unittest.SkipTest('LTO not (yet) supported by windows clang') - else: - extra_args.append('-D_cargs=-Werror=unused-command-line-argument') self.init(testdir, extra_args=['-Db_lto=true', '-Db_lto_threads=8'] + extra_args) self.build() @@ -4315,9 +4313,11 @@ class AllPlatformTests(BasePlatformTests): self.assertEqual(obj.options[OptionKey('default_library')].value, 'shared') self.wipe() - # 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) + # 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) self.wipe() # Should fail on malformed option |