Skip to content

Commit

Permalink
Fix yielding when top project does not define the option.
Browse files Browse the repository at this point in the history
  • Loading branch information
jpakkane committed Feb 22, 2025
1 parent 4386e2a commit 8389be0
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
8 changes: 7 additions & 1 deletion mesonbuild/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -810,7 +810,13 @@ def get_value_object_for(self, key: 'T.Union[OptionKey, str]') -> AnyOptionType:
assert key.subproject is not None
if potential is not None and potential.yielding:
parent_key = key.evolve(subproject='')
parent_option = self.options[parent_key]
try:
parent_option = self.options[parent_key]
except KeyError:
# Subproject is set to yield, but top level
# project does not have an option of the same
# name. Return the subproject option.
return potential
# If parent object has different type, do not yield.
# This should probably be an error.
if type(parent_option) is type(potential):
Expand Down
16 changes: 16 additions & 0 deletions unittests/optiontests.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,22 @@ def test_project_yielding(self):
self.assertEqual(optstore.get_value_for(name, 'sub'), top_value)
self.assertEqual(optstore.num_options(), 2)

def test_project_yielding_not_defined_in_top_project(self):
optstore = OptionStore(False)
top_name = 'a_name'
top_value = 'top'
sub_name = 'different_name'
sub_value = 'sub'
vo = UserStringOption(top_name, 'A top level option', top_value)
optstore.add_project_option(OptionKey(top_name, ''), vo)
self.assertEqual(optstore.get_value_for(top_name, ''), top_value)
self.assertEqual(optstore.num_options(), 1)
vo2 = UserStringOption(sub_name, 'A subproject option', sub_value, True)
optstore.add_project_option(OptionKey(sub_name, 'sub'), vo2)
self.assertEqual(optstore.get_value_for(top_name, ''), top_value)
self.assertEqual(optstore.get_value_for(sub_name, 'sub'), sub_value)
self.assertEqual(optstore.num_options(), 2)

def test_augments(self):
optstore = OptionStore(False)
name = 'cpp_std'
Expand Down

0 comments on commit 8389be0

Please sign in to comment.