coredata: Set default options as cmdline args that override each other

The previous code was assuming that options do not depend on each
other, and that you can set defaults using `dict.setdefault()`. This
is not true for `buildtype` + `optimization`/`debug`, so we add
defaults + overrides in the right order and use the options parsing
code later to compute the values.

Includes a test.

Closes https://github.com/mesonbuild/meson/issues/6752
pull/6776/head
Nirbheek Chauhan 5 years ago committed by Xavier Claessens
parent bc135f6c4d
commit c7aa4c8861
  1. 21
      mesonbuild/coredata.py
  2. 18
      run_unittests.py
  3. 2
      test cases/common/1 trivial/meson.build

@ -718,13 +718,8 @@ class CoreData:
self.copy_build_options_from_regular_ones()
def set_default_options(self, default_options, subproject, env):
# Set defaults first from conf files (cross or native), then
# override them as nec as necessary.
for k, v in env.paths.host:
if v is not None:
env.cmd_line_options.setdefault(k, v)
# Set default options as if they were passed to the command line.
cmd_line_options = OrderedDict()
# Set project default_options as if they were passed to the cmdline.
# Subprojects can only define default for user options and not yielding
# builtin option.
from . import optinterpreter
@ -734,7 +729,17 @@ class CoreData:
and optinterpreter.is_invalid_name(k, log=False):
continue
k = subproject + ':' + k
env.cmd_line_options.setdefault(k, v)
cmd_line_options[k] = v
# Override project default_options using conf files (cross or native)
for k, v in env.paths.host:
if v is not None:
cmd_line_options[k] = v
# Override all the above defaults using the command-line arguments
# actually passed to us
cmd_line_options.update(env.cmd_line_options)
env.cmd_line_options = cmd_line_options
# Create a subset of cmd_line_options, keeping only options for this
# subproject. Also take builtin options if it's the main project.

@ -3825,6 +3825,24 @@ recommended as it is not supported on some platforms''')
self.assertEqual(opts['debug'], True)
self.assertEqual(opts['optimization'], '0')
# Command-line parsing of buildtype settings should be the same as
# setting with `meson configure`.
#
# Setting buildtype should set optimization/debug
self.new_builddir()
self.init(testdir, extra_args=['-Dbuildtype=debugoptimized'])
opts = self.get_opts_as_dict()
self.assertEqual(opts['debug'], True)
self.assertEqual(opts['optimization'], '2')
self.assertEqual(opts['buildtype'], 'debugoptimized')
# Setting optimization/debug should set buildtype
self.new_builddir()
self.init(testdir, extra_args=['-Doptimization=2', '-Ddebug=true'])
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')
def test_native_dep_pkgconfig(self):

@ -1,7 +1,7 @@
# Comment on the first line
project('trivial test',
# Comment inside a function call + array for language list
['c'],
['c'], default_options: ['buildtype=debug'],
meson_version : '>=0.52.0')
#this is a comment
sources = 'trivial.c'

Loading…
Cancel
Save