Skip to content

Commit

Permalink
Replace OptionKey.evolve(...) with specialized functions
Browse files Browse the repository at this point in the history
This will allow further optimizations in next commit.
  • Loading branch information
bruchar1 committed Feb 14, 2025
1 parent 185dad9 commit b117c7e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
2 changes: 1 addition & 1 deletion mesonbuild/coredata.py
Original file line number Diff line number Diff line change
Expand Up @@ -606,7 +606,7 @@ def set_options(self, opts_to_set: T.Dict[OptionKey, T.Any], subproject: str = '
# refactor they will get per-subproject values.
really_unknown = []
for uo in unknown_options:
topkey = uo.evolve(subproject='')
topkey = uo.as_root()
if topkey not in self.optstore:
really_unknown.append(uo)
unknown_options = really_unknown
Expand Down
18 changes: 9 additions & 9 deletions mesonbuild/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,17 +253,17 @@ def evolve(self,
machine if machine is not None else self.machine)

def as_root(self) -> 'OptionKey':
"""Convenience method for key.evolve(subproject='')."""
"""Convenience method for key.as_root()."""
if self.subproject is None or self.subproject == '':
return self
return self.evolve(subproject='')

def as_build(self) -> 'OptionKey':
"""Convenience method for key.evolve(machine=MachineChoice.BUILD)."""
"""Convenience method for key.as_build()."""
return self.evolve(machine=MachineChoice.BUILD)

def as_host(self) -> 'OptionKey':
"""Convenience method for key.evolve(machine=MachineChoice.HOST)."""
"""Convenience method for key.as_host()."""
return self.evolve(machine=MachineChoice.HOST)

def has_module_prefix(self) -> bool:
Expand Down Expand Up @@ -806,7 +806,7 @@ def ensure_and_validate_key(self, key: T.Union[OptionKey, str]) -> OptionKey:
# I did not do this yet, because it would make this MR even
# more massive than it already is. Later then.
if not self.is_cross and key.machine == MachineChoice.BUILD:
key = key.evolve(machine=MachineChoice.HOST)
key = key.as_host()
return key

def get_value(self, key: T.Union[OptionKey, str]) -> 'OptionValueType':
Expand All @@ -821,7 +821,7 @@ def get_value_object_for(self, key: 'T.Union[OptionKey, str]') -> AnyOptionType:
if self.is_project_option(key):
assert key.subproject is not None
if potential is not None and potential.yielding:
parent_key = key.evolve(subproject='')
parent_key = key.as_root()
parent_option = self.options[parent_key]
# If parent object has different type, do not yield.
# This should probably be an error.
Expand Down Expand Up @@ -1048,7 +1048,7 @@ def set_option_from_string(self, keystr: T.Union[OptionKey, str], new_value: str
o = OptionKey.from_string(keystr)
if o in self.options:
return self.set_value(o, new_value)
o = o.evolve(subproject='')
o = o.as_root()
return self.set_value(o, new_value)

def set_subproject_options(self, subproject: str,
Expand Down Expand Up @@ -1301,7 +1301,7 @@ def initialize_from_top_level_project_call(self,
elif key in self.options:
self.set_value(key, valstr, first_invocation)
else:
proj_key = key.evolve(subproject='')
proj_key = key.as_root()
if proj_key in self.options:
self.options[proj_key].set_value(valstr)
else:
Expand Down Expand Up @@ -1334,7 +1334,7 @@ def initialize_from_top_level_project_call(self,
# Argubly this should be a hard error, the default
# value of project option should be set in the option
# file, not in the project call.
proj_key = key.evolve(subproject='')
proj_key = key.as_root()
if self.is_project_option(proj_key):
self.set_option(proj_key, valstr)
else:
Expand All @@ -1352,7 +1352,7 @@ def initialize_from_top_level_project_call(self,
if key in self.options:
self.set_value(key, valstr, True)
elif key.subproject is None:
projectkey = key.evolve(subproject='')
projectkey = key.as_root()
if projectkey in self.options:
self.options[projectkey].set_value(valstr)
else:
Expand Down

0 comments on commit b117c7e

Please sign in to comment.