diff options
author | Nirbheek Chauhan <nirbheek@centricular.com> | 2020-03-12 22:01:14 +0530 |
---|---|---|
committer | Nirbheek Chauhan <nirbheek@centricular.com> | 2020-03-12 22:14:51 +0530 |
commit | 3348a0fd1a09ab0768f487661ad1eabe295a6725 (patch) | |
tree | 2b57147b4ab455f2972d6d0431adffcf07efd6f7 | |
parent | a18658d8e11ed3504aa700df6a9e78a3cd9460f4 (diff) | |
download | meson-nirbheek/more-buildtype-changes.tar.gz |
Warn when detecting debug with get_option('buildtype')nirbheek/more-buildtype-changes
Build files should always use `get_option('debug')` since `buildtype`
is set to `custom` in many cases.
-rw-r--r-- | mesonbuild/interpreter.py | 14 | ||||
-rwxr-xr-x | run_unittests.py | 5 |
2 files changed, 16 insertions, 3 deletions
diff --git a/mesonbuild/interpreter.py b/mesonbuild/interpreter.py index af6eda321..416d26fb7 100644 --- a/mesonbuild/interpreter.py +++ b/mesonbuild/interpreter.py @@ -2833,7 +2833,7 @@ external dependencies (including libraries) must go to "dependencies".''') @stringArgs @noKwargs - def func_get_option(self, nodes, args, kwargs): + def func_get_option(self, node, args, kwargs): if len(args) != 1: raise InterpreterException('Argument required for get_option.') optname = args[0] @@ -2843,9 +2843,17 @@ external dependencies (including libraries) must go to "dependencies".''') 'options of other subprojects.') opt = self.get_option_internal(optname) if isinstance(opt, coredata.UserFeatureOption): - return FeatureOptionHolder(self.environment, optname, opt) + opt = FeatureOptionHolder(self.environment, optname, opt) elif isinstance(opt, coredata.UserOption): - return opt.value + opt = opt.value + if optname == 'buildtype': + class BuildTypeString(str): + def startswith(self, token): + if token == 'debug': + mlog.warning("Use get_option('debug') to check whether debugging is enabled " + "instead of get_option('buildtype').startswith('debug')", location=node) + super().startswith(token) + opt = BuildTypeString(opt) return opt @noKwargs diff --git a/run_unittests.py b/run_unittests.py index f867f1c35..03ada0c36 100755 --- a/run_unittests.py +++ b/run_unittests.py @@ -4832,6 +4832,11 @@ class FailureTests(BasePlatformTests): "meson.override_dependency('zlib', declare_dependency())", """Tried to override dependency 'zlib' which has already been resolved or overridden""") + def test_buildtype_debug_warning(self): + self.assertMesonOutputs("get_option('buildtype').startswith('debug')\n", + r"WARNING:.*get_option\('debug'\)") + + @unittest.skipUnless(is_windows() or is_cygwin(), "requires Windows (or Windows via Cygwin)") class WindowsTests(BasePlatformTests): ''' |