aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNirbheek Chauhan <nirbheek@centricular.com>2020-03-07 00:34:05 +0530
committerXavier Claessens <xclaesse@gmail.com>2020-03-11 07:11:59 -0400
commitc7aa4c8861eb6c1d3534b3b0e94e901b7b2d0206 (patch)
tree3979ef7df1f5addad9da44f143c936a2bc31ba02
parentbc135f6c4dd56c925438d9c84f3bb6794f7ecaa3 (diff)
downloadmeson-c7aa4c8861eb6c1d3534b3b0e94e901b7b2d0206.zip
meson-c7aa4c8861eb6c1d3534b3b0e94e901b7b2d0206.tar.gz
meson-c7aa4c8861eb6c1d3534b3b0e94e901b7b2d0206.tar.bz2
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
-rw-r--r--mesonbuild/coredata.py21
-rwxr-xr-xrun_unittests.py18
-rw-r--r--test cases/common/1 trivial/meson.build2
3 files changed, 32 insertions, 9 deletions
diff --git a/mesonbuild/coredata.py b/mesonbuild/coredata.py
index fdd8cab..a0df24d 100644
--- a/mesonbuild/coredata.py
+++ b/mesonbuild/coredata.py
@@ -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.
diff --git a/run_unittests.py b/run_unittests.py
index baea70e..5b25b6c 100755
--- a/run_unittests.py
+++ b/run_unittests.py
@@ -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):
diff --git a/test cases/common/1 trivial/meson.build b/test cases/common/1 trivial/meson.build
index c476c37..fb1142c 100644
--- a/test cases/common/1 trivial/meson.build
+++ b/test cases/common/1 trivial/meson.build
@@ -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'