coredata: Passing an option is supposed to set it, not flip the default

With the current logic passing `--debug` will actually be parsed as
`-Ddebug=false`, which is absolutely not what is expected.

There is no case in which the presence of a boolean option in `--foo`
form will mean 'I want feature foo disabled', regardless of the
*default* value of that option.

Also includes a test.

Closes https://github.com/mesonbuild/meson/issues/4686
pull/6776/head
Nirbheek Chauhan 5 years ago committed by Xavier Claessens
parent c7aa4c8861
commit bd953b6b29
  1. 7
      mesonbuild/coredata.py
  2. 8
      run_unittests.py

@ -1001,9 +1001,10 @@ class BuiltinOption(T.Generic[_T, _U]):
return self.opt_type(self.description, **keywords)
def _argparse_action(self) -> T.Optional[str]:
if self.default is True:
return 'store_false'
elif self.default is False:
# If the type is a boolean, the presence of the argument in --foo form
# is to enable it. Disabling happens by using -Dfoo=false, which is
# parsed under `args.projectoptions` and does not hit this codepath.
if isinstance(self.default, bool):
return 'store_true'
return None

@ -3842,6 +3842,14 @@ recommended as it is not supported on some platforms''')
self.assertEqual(opts['debug'], True)
self.assertEqual(opts['optimization'], '2')
self.assertEqual(opts['buildtype'], 'debugoptimized')
# Setting both buildtype and debug on the command-line should work
# Also test that --debug is parsed as -Ddebug=true
self.new_builddir()
self.init(testdir, extra_args=['-Dbuildtype=debugoptimized', '--debug'])
opts = self.get_opts_as_dict()
self.assertEqual(opts['debug'], True)
self.assertEqual(opts['optimization'], '2')
self.assertEqual(opts['buildtype'], 'debugoptimized')
@skipIfNoPkgconfig
@unittest.skipIf(is_windows(), 'Help needed with fixing this test on windows')

Loading…
Cancel
Save