aboutsummaryrefslogtreecommitdiff
path: root/mesonbuild/coredata.py
diff options
context:
space:
mode:
authorXavier Claessens <xavier.claessens@collabora.com>2021-08-27 13:47:14 -0400
committerXavier Claessens <xclaesse@gmail.com>2021-10-09 18:13:34 -0400
commit77ef437cc46954fddc23402a50931a700c9dd187 (patch)
tree8468b562e88abc8be504327fa714d05bf4c23904 /mesonbuild/coredata.py
parent953bbf5e1946f14d486ee28cd3cd261cbb79b33f (diff)
downloadmeson-77ef437cc46954fddc23402a50931a700c9dd187.zip
meson-77ef437cc46954fddc23402a50931a700c9dd187.tar.gz
meson-77ef437cc46954fddc23402a50931a700c9dd187.tar.bz2
optinterpreter: Add deprecated kwarg
It can be either: - boolean: the option is completely deprecated. - list: some choices are deprecated. - dict: some choices are deprecated and replaced by another. Fixes: #7444
Diffstat (limited to 'mesonbuild/coredata.py')
-rw-r--r--mesonbuild/coredata.py30
1 files changed, 28 insertions, 2 deletions
diff --git a/mesonbuild/coredata.py b/mesonbuild/coredata.py
index 4c7b24c..7782bd1 100644
--- a/mesonbuild/coredata.py
+++ b/mesonbuild/coredata.py
@@ -72,6 +72,10 @@ class UserOption(T.Generic[_T], HoldableObject):
if not isinstance(yielding, bool):
raise MesonException('Value of "yielding" must be a boolean.')
self.yielding = yielding
+ self.deprecated: T.Union[bool, T.Dict[str, str], T.List[str]] = False
+
+ def listify(self, value: T.Any) -> T.List[T.Any]:
+ return [value]
def printable_value(self) -> T.Union[str, int, bool, T.List[T.Union[str, int, bool]]]:
assert isinstance(self.value, (str, int, bool, list))
@@ -205,7 +209,7 @@ class UserArrayOption(UserOption[T.List[str]]):
self.allow_dups = allow_dups
self.value = self.validate_value(value, user_input=user_input)
- def validate_value(self, value: T.Union[str, T.List[str]], user_input: bool = True) -> T.List[str]:
+ def listify(self, value: T.Union[str, T.List[str]], user_input: bool = True) -> T.List[str]:
# User input is for options defined on the command line (via -D
# options). Users can put their input in as a comma separated
# string, but for defining options in meson_options.txt the format
@@ -230,6 +234,10 @@ class UserArrayOption(UserOption[T.List[str]]):
newvalue = value
else:
raise MesonException(f'"{newvalue}" should be a string array, but it is not')
+ return newvalue
+
+ def validate_value(self, value: T.Union[str, T.List[str]], user_input: bool = True) -> T.List[str]:
+ newvalue = self.listify(value, user_input)
if not self.allow_dups and len(set(newvalue)) != len(newvalue):
msg = 'Duplicated values in array option is deprecated. ' \
@@ -629,10 +637,28 @@ class CoreData:
value = self.sanitize_dir_option_value(prefix, key, value)
try:
- self.options[key].set_value(value)
+ opt = self.options[key]
except KeyError:
raise MesonException(f'Tried to set unknown builtin option {str(key)}')
+ if opt.deprecated is True:
+ mlog.deprecation(f'Option {key.name!r} is deprecated')
+ elif isinstance(opt.deprecated, list):
+ for v in opt.listify(value):
+ if v in opt.deprecated:
+ mlog.deprecation(f'Option {key.name!r} value {v!r} is deprecated')
+ elif isinstance(opt.deprecated, dict):
+ def replace(v):
+ newvalue = opt.deprecated.get(v)
+ if newvalue is not None:
+ mlog.deprecation(f'Option {key.name!r} value {v!r} is replaced by {newvalue!r}')
+ return newvalue
+ return v
+ newvalue = [replace(v) for v in opt.listify(value)]
+ value = ','.join(newvalue)
+
+ opt.set_value(value)
+
if key.name == 'buildtype':
self._set_others_from_buildtype(value)
elif key.name in {'wrap_mode', 'force_fallback_for'}: