aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--docs/markdown/snippets/coercing_option_values_deprecated.md9
-rw-r--r--mesonbuild/optinterpreter.py4
-rw-r--r--test cases/common/247 deprecated option/meson_options.txt2
-rw-r--r--test cases/common/40 options/meson.build5
-rw-r--r--test cases/common/40 options/meson_options.txt4
-rw-r--r--test cases/common/40 options/test.json7
6 files changed, 28 insertions, 3 deletions
diff --git a/docs/markdown/snippets/coercing_option_values_deprecated.md b/docs/markdown/snippets/coercing_option_values_deprecated.md
new file mode 100644
index 0000000..3621387
--- /dev/null
+++ b/docs/markdown/snippets/coercing_option_values_deprecated.md
@@ -0,0 +1,9 @@
+## coercing values in the option() function is deprecated
+
+Currently code such as:
+```meson
+option('foo', type : 'boolean', value : 'false')
+```
+works, because Meson coerces `'false'` to `false`.
+
+This should be avoided, and will now result in a deprecation warning.
diff --git a/mesonbuild/optinterpreter.py b/mesonbuild/optinterpreter.py
index de7ba04..9251df8 100644
--- a/mesonbuild/optinterpreter.py
+++ b/mesonbuild/optinterpreter.py
@@ -20,7 +20,7 @@ from . import coredata
from . import mesonlib
from . import mparser
from . import mlog
-from .interpreterbase import FeatureNew, typed_pos_args, typed_kwargs, ContainerTypeInfo, KwargInfo
+from .interpreterbase import FeatureNew, typed_pos_args, typed_kwargs, ContainerTypeInfo, KwargInfo, FeatureDeprecated
from .interpreter.type_checking import NoneType, in_set_validator
if T.TYPE_CHECKING:
from .interpreterbase import TYPE_var, TYPE_kwargs
@@ -221,6 +221,7 @@ class OptionInterpreter:
(bool, str),
default=True,
validator=lambda x: None if isinstance(x, bool) or x in {'true', 'false'} else 'boolean options must have boolean values',
+ deprecated_values={'true': ('1.1.0', 'use a boolean, not a string'), 'false': ('1.1.0', 'use a boolean, not a string')},
),
)
def boolean_parser(self, description: str, yield_: bool, kwargs: BooleanArgs) -> coredata.UserOption:
@@ -244,6 +245,7 @@ class OptionInterpreter:
'value',
(int, str),
default=True,
+ feature_validator=lambda x: [FeatureDeprecated('number values as strings', '1.1.0', 'use a raw number instead')] if isinstance(x, str) else [],
convertor=int,
),
KwargInfo('min', (int, NoneType)),
diff --git a/test cases/common/247 deprecated option/meson_options.txt b/test cases/common/247 deprecated option/meson_options.txt
index 9665501..88cd8aa 100644
--- a/test cases/common/247 deprecated option/meson_options.txt
+++ b/test cases/common/247 deprecated option/meson_options.txt
@@ -16,7 +16,7 @@ option('o5', type: 'boolean', deprecated: {'enabled': 'true', 'disabled': 'false
# A boolean option has been replaced by a feature with another name, old true/false values
# are accepted by the new option for backward compatibility.
-option('o6', type: 'boolean', value: 'true', deprecated: 'o7')
+option('o6', type: 'boolean', value: true, deprecated: 'o7')
option('o7', type: 'feature', value: 'enabled', deprecated: {'true': 'enabled', 'false': 'disabled'})
# A project option is replaced by a module option
diff --git a/test cases/common/40 options/meson.build b/test cases/common/40 options/meson.build
index 2eccef7..a10ff28 100644
--- a/test cases/common/40 options/meson.build
+++ b/test cases/common/40 options/meson.build
@@ -1,4 +1,4 @@
-project('options', 'c')
+project('options', 'c', meson_version : '>= 1.0.0')
if get_option('testoption') != 'optval'
error('Incorrect value to test option')
@@ -43,3 +43,6 @@ if get_option('CASESENSITIVE') != 'ALL CAPS'
endif
assert(get_option('wrap_mode') == 'default', 'Wrap mode option is broken.')
+assert(get_option('boolean_string') == false)
+assert(get_option('boolean_string2') == true)
+assert(get_option('integer_string') == 42)
diff --git a/test cases/common/40 options/meson_options.txt b/test cases/common/40 options/meson_options.txt
index 8067eae..ecb024d 100644
--- a/test cases/common/40 options/meson_options.txt
+++ b/test cases/common/40 options/meson_options.txt
@@ -7,3 +7,7 @@ option('integer_opt', type : 'integer', min : 0, max : -(-5), value : 3)
option('neg' + '_' + 'int' + '_' + 'opt', type : 'integer', min : -5, max : 5, value : -3)
option('CaseSenSiTivE', type : 'string', value: 'Some CAPS', description : 'An option with mixed capitaliziation')
option('CASESENSITIVE', type : 'string', value: 'ALL CAPS', description : 'An option with all caps')
+
+option('boolean_string', type : 'boolean', value : 'false')
+option('boolean_string2', type : 'boolean', value : 'true')
+option('integer_string', type : 'integer', value : '42')
diff --git a/test cases/common/40 options/test.json b/test cases/common/40 options/test.json
new file mode 100644
index 0000000..d1800c6
--- /dev/null
+++ b/test cases/common/40 options/test.json
@@ -0,0 +1,7 @@
+{
+ "stdout": [
+ {
+ "line": " * 1.1.0: {'\"boolean option\" keyword argument \"value\" value \"false\"', '\"boolean option\" keyword argument \"value\" value \"true\"', 'number values as strings'}"
+ }
+ ]
+}