diff options
| author | Dylan Baker <dylan@pnwbakers.com> | 2025-03-12 11:04:53 -0700 |
|---|---|---|
| committer | Dylan Baker <dylan@pnwbakers.com> | 2025-04-08 10:00:16 -0700 |
| commit | 90d6a3e61100e39ab74ff7b2b4bc456af5a8114c (patch) | |
| tree | 808ccd77b21493647ea25c85df1954e9a6e48ef2 | |
| parent | 390ea4624c2fbfecf831f1c7f34ec796ff410de7 (diff) | |
| download | meson-90d6a3e61100e39ab74ff7b2b4bc456af5a8114c.tar.gz | |
coredata: move update_project_options to the optstore
| -rw-r--r-- | mesonbuild/coredata.py | 29 | ||||
| -rw-r--r-- | mesonbuild/interpreterbase/interpreterbase.py | 2 | ||||
| -rw-r--r-- | mesonbuild/mconf.py | 6 | ||||
| -rw-r--r-- | mesonbuild/options.py | 30 |
4 files changed, 34 insertions, 33 deletions
diff --git a/mesonbuild/coredata.py b/mesonbuild/coredata.py index 4791fe128..ba57821cc 100644 --- a/mesonbuild/coredata.py +++ b/mesonbuild/coredata.py @@ -15,7 +15,6 @@ from collections import OrderedDict import textwrap from .mesonlib import ( - MesonBugException, MesonException, MachineChoice, PerMachine, PerMachineDefaultable, default_prefix, @@ -499,34 +498,6 @@ class CoreData: linkkey = OptionKey(f'{lang}_link_args', machine=for_machine) return T.cast('T.List[str]', self.optstore.get_value_for(linkkey)) - def update_project_options(self, project_options: 'MutableKeyedOptionDictType', subproject: SubProject) -> None: - for key, value in project_options.items(): - if key not in self.optstore: - self.optstore.add_project_option(key, value) - continue - if key.subproject != subproject: - raise MesonBugException(f'Tried to set an option for subproject {key.subproject} from {subproject}!') - - oldval = self.optstore.get_value_object(key) - if type(oldval) is not type(value): - self.optstore.set_option(key, value.value) - elif options.choices_are_different(oldval, value): - # 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.optstore.set_value_object(key, value) - try: - value.set_value(oldval.value) - except MesonException: - mlog.warning(f'Old value(s) of {key} are no longer valid, resetting to default ({value.value}).', - fatal=False) - - # Find any extranious keys for this project and remove them - potential_removed_keys = self.optstore.keys() - project_options.keys() - for key in potential_removed_keys: - if self.optstore.is_project_option(key) and key.subproject == subproject: - self.optstore.remove(key) - def is_cross_build(self, when_building_for: MachineChoice = MachineChoice.HOST) -> bool: if when_building_for == MachineChoice.BUILD: return False diff --git a/mesonbuild/interpreterbase/interpreterbase.py b/mesonbuild/interpreterbase/interpreterbase.py index 2bdb5ef2e..b13bbae1a 100644 --- a/mesonbuild/interpreterbase/interpreterbase.py +++ b/mesonbuild/interpreterbase/interpreterbase.py @@ -704,7 +704,7 @@ class InterpreterBase: self.coredata.options_files[self.subproject] = (option_file, hashlib.sha1(f.read()).hexdigest()) oi = optinterpreter.OptionInterpreter(self.environment.coredata.optstore, self.subproject) oi.process(option_file) - self.coredata.update_project_options(oi.options, self.subproject) + self.coredata.optstore.update_project_options(oi.options, self.subproject) self.build_def_files.add(option_file) else: self.coredata.options_files[self.subproject] = None diff --git a/mesonbuild/mconf.py b/mesonbuild/mconf.py index cf2162232..416caf1a0 100644 --- a/mesonbuild/mconf.py +++ b/mesonbuild/mconf.py @@ -96,7 +96,7 @@ class Conf: if ophash != conf_options[1]: oi = OptionInterpreter(self.coredata.optstore, sub) oi.process(opfile) - self.coredata.update_project_options(oi.options, sub) + self.coredata.optstore.update_project_options(oi.options, sub) self.coredata.options_files[sub] = (opfile, ophash) else: opfile = os.path.join(self.source_dir, 'meson.options') @@ -105,12 +105,12 @@ class Conf: if os.path.exists(opfile): oi = OptionInterpreter(self.coredata.optstore, sub) oi.process(opfile) - self.coredata.update_project_options(oi.options, sub) + self.coredata.optstore.update_project_options(oi.options, sub) with open(opfile, 'rb') as f: ophash = hashlib.sha1(f.read()).hexdigest() self.coredata.options_files[sub] = (opfile, ophash) else: - self.coredata.update_project_options({}, sub) + self.coredata.optstore.update_project_options({}, sub) elif os.path.isfile(os.path.join(self.build_dir, environment.build_filename)): # Make sure that log entries in other parts of meson don't interfere with the JSON output with mlog.no_logging(): diff --git a/mesonbuild/options.py b/mesonbuild/options.py index 3ad4f9155..4339f7773 100644 --- a/mesonbuild/options.py +++ b/mesonbuild/options.py @@ -35,6 +35,8 @@ from . import mlog if T.TYPE_CHECKING: from typing_extensions import Literal, Final, TypeAlias, TypedDict + from .interpreterbase import SubProject + DeprecatedType: TypeAlias = T.Union[bool, str, T.Dict[str, str], T.List[str]] AnyOptionType: TypeAlias = T.Union[ 'UserBooleanOption', 'UserComboOption', 'UserFeatureOption', @@ -1402,3 +1404,31 @@ class OptionStore: self.set_option(key, valstr, is_first_invocation) else: self.augments[str(key)] = valstr + + def update_project_options(self, project_options: MutableKeyedOptionDictType, subproject: SubProject) -> None: + for key, value in project_options.items(): + if key not in self.options: + self.add_project_option(key, value) + continue + if key.subproject != subproject: + raise MesonBugException(f'Tried to set an option for subproject {key.subproject} from {subproject}!') + + oldval = self.get_value_object(key) + if type(oldval) is not type(value): + self.set_option(key, value.value) + elif choices_are_different(oldval, value): + # 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.set_value_object(key, value) + try: + value.set_value(oldval.value) + except MesonException: + mlog.warning(f'Old value(s) of {key} are no longer valid, resetting to default ({value.value}).', + fatal=False) + + # Find any extranious keys for this project and remove them + potential_removed_keys = self.options.keys() - project_options.keys() + for key in potential_removed_keys: + if self.is_project_option(key) and key.subproject == subproject: + self.remove(key) |
