aboutsummaryrefslogtreecommitdiff
path: root/mesonbuild
diff options
context:
space:
mode:
authorDylan Baker <dylan@pnwbakers.com>2020-09-14 11:36:38 -0700
committerJussi Pakkanen <jpakkane@gmail.com>2020-10-05 23:10:35 +0300
commit94ac51fdda0408c6d1f61e7e5e89cebaa9182842 (patch)
tree58fd6d3b44c2cb2b57fb9c8f6dbfb17fe4c36cae /mesonbuild
parentc4fa87692547a25f772b3da336147b4eb9114f64 (diff)
downloadmeson-94ac51fdda0408c6d1f61e7e5e89cebaa9182842.zip
meson-94ac51fdda0408c6d1f61e7e5e89cebaa9182842.tar.gz
meson-94ac51fdda0408c6d1f61e7e5e89cebaa9182842.tar.bz2
options: Handle updates to choices in options
Currently if you change the `choices` field in the meson_options.txt file, no update will be done until `meson setup --wipe` is called. Now if the choices change then the options will be properly merged. If the currently select value is still valid it is guaranteed to be kept, if it is now invalid the new default value will be used and a warning will be printed. Fixes #7386
Diffstat (limited to 'mesonbuild')
-rw-r--r--mesonbuild/coredata.py20
1 files changed, 15 insertions, 5 deletions
diff --git a/mesonbuild/coredata.py b/mesonbuild/coredata.py
index 4be828b..e3b3b01 100644
--- a/mesonbuild/coredata.py
+++ b/mesonbuild/coredata.py
@@ -689,14 +689,24 @@ class CoreData:
def get_external_link_args(self, for_machine: MachineChoice, lang):
return self.compiler_options[for_machine][lang]['link_args'].value
- def merge_user_options(self, options: T.Dict[str, T.Union[str, bool, int]]) -> None:
+ def merge_user_options(self, options: T.Dict[str, UserOption[T.Any]]) -> None:
for (name, value) in options.items():
if name not in self.user_options:
self.user_options[name] = value
- else:
- oldval = self.user_options[name]
- if type(oldval) != type(value):
- self.user_options[name] = value
+ continue
+
+ oldval = self.user_options[name]
+ if type(oldval) != type(value):
+ self.user_options[name] = value
+ elif oldval.choices != value.choices:
+ # If the choices have changed, use the new value, but attempt
+ # to keep the old options. If they are not valid keep the new
+ # defaults but warn.
+ self.user_options[name] = value
+ try:
+ value.set_value(oldval.value)
+ except MesonException as e:
+ mlog.warning('Old value(s) of {} are no longer valid, resetting to default ({}).'.format(name, value.value))
def is_cross_build(self, when_building_for: MachineChoice = MachineChoice.HOST) -> bool:
if when_building_for == MachineChoice.BUILD: