From 69e9d32bca23d75a9a5d7df794d34c9aeb949d8a Mon Sep 17 00:00:00 2001 From: Nirbheek Chauhan Date: Sat, 7 Mar 2020 01:49:30 +0530 Subject: coredata: Warn on usage of both -Dbuildtype and -Doptimization/-Ddebug It may not be obvious to users that these two ways to set build-types override each other and specifying both is redundant, and conflicts are resolved based on whichever is specified later. Closes https://github.com/mesonbuild/meson/issues/6742 --- docs/markdown/Builtin-options.md | 1 + mesonbuild/coredata.py | 7 +++++++ run_unittests.py | 7 ++++--- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/docs/markdown/Builtin-options.md b/docs/markdown/Builtin-options.md index c2b10b6..ea5ad70 100644 --- a/docs/markdown/Builtin-options.md +++ b/docs/markdown/Builtin-options.md @@ -87,6 +87,7 @@ Using the option as-is with no prefix affects all machines. For example: | werror | false | Treat warnings as errors | no | | wrap_mode {default, nofallback,
nodownload, forcefallback} | default | Wrap mode to use | no | + For setting optimization levels and toggling debug, you can either set the `buildtype` option, or you can set the `optimization` and `debug` options which give finer control over the same. Whichever you decide to use, the other will diff --git a/mesonbuild/coredata.py b/mesonbuild/coredata.py index 344da4c..6f75534 100644 --- a/mesonbuild/coredata.py +++ b/mesonbuild/coredata.py @@ -718,6 +718,13 @@ class CoreData: self.copy_build_options_from_regular_ones() def set_default_options(self, default_options, subproject, env): + # Warn if the user is using two different ways of setting build-type + # options that override each other + if 'buildtype' in env.cmd_line_options and \ + ('optimization' in env.cmd_line_options or 'debug' in env.cmd_line_options): + mlog.warning('Recommend using either -Dbuildtype or -Doptimization + -Ddebug. ' + 'Using both is redundant since they override each other. ' + 'See: https://mesonbuild.com/Builtin-options.html#build-type-options') 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 diff --git a/run_unittests.py b/run_unittests.py index 41e8ad4..f867f1c 100755 --- a/run_unittests.py +++ b/run_unittests.py @@ -3842,10 +3842,11 @@ 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 + # Setting both buildtype and debug on the command-line should work, and + # should warn not to do that. Also test that --debug is parsed as -Ddebug=true self.new_builddir() - self.init(testdir, extra_args=['-Dbuildtype=debugoptimized', '--debug']) + out = self.init(testdir, extra_args=['-Dbuildtype=debugoptimized', '--debug']) + self.assertRegex(out, 'Recommend using either.*buildtype.*debug.*redundant') opts = self.get_opts_as_dict() self.assertEqual(opts['debug'], True) self.assertEqual(opts['optimization'], '2') -- cgit v1.1